本文整理汇总了Java中org.jetbrains.ide.HttpRequestHandler类的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestHandler类的具体用法?Java HttpRequestHandler怎么用?Java HttpRequestHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpRequestHandler类属于org.jetbrains.ide包,在下文中一共展示了HttpRequestHandler类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.jetbrains.ide.HttpRequestHandler; //导入依赖的package包/类
@Override
protected boolean process(ChannelHandlerContext context, HttpRequest request, QueryStringDecoder urlDecoder) throws IOException, ImageWriteException {
HttpRequestHandler connectedHandler = (HttpRequestHandler)context.getAttachment();
if (connectedHandler != null) {
if (connectedHandler.isSupported(request) && connectedHandler.process(urlDecoder, request, context)) {
return true;
}
// prev cached connectedHandler is not suitable for this request, so, let's find it again
context.setAttachment(null);
}
if (urlDecoder.getPath().equals("/favicon.ico")) {
Icon icon = IconLoader.findIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl());
if (icon != null) {
BufferedImage image = UIUtil.createImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(null, image.getGraphics(), 0, 0);
byte[] icoBytes = Sanselan.writeImageToBytes(image, ImageFormat.IMAGE_FORMAT_ICO, null);
Responses.send(icoBytes, FileResponses.createResponse(urlDecoder.getPath()), request, context);
return true;
}
}
for (HttpRequestHandler handler : BuiltInServerManager.EP_NAME.getExtensions()) {
try {
if (handler.isSupported(request) && handler.process(urlDecoder, request, context)) {
if (context.getAttachment() == null) {
context.setAttachment(handler);
}
return true;
}
}
catch (Throwable e) {
BuiltInServer.LOG.error(e);
}
}
return false;
}
示例2: process
import org.jetbrains.ide.HttpRequestHandler; //导入依赖的package包/类
@Override
protected boolean process(@NotNull ChannelHandlerContext context,
@NotNull FullHttpRequest request,
@NotNull QueryStringDecoder urlDecoder) throws IOException, ImageWriteException {
Attribute<HttpRequestHandler> prevHandlerAttribute = context.attr(PREV_HANDLER);
HttpRequestHandler connectedHandler = prevHandlerAttribute.get();
if (connectedHandler != null) {
if (connectedHandler.isSupported(request) && connectedHandler.process(urlDecoder, request, context)) {
return true;
}
// prev cached connectedHandler is not suitable for this request, so, let's find it again
prevHandlerAttribute.set(null);
}
for (HttpRequestHandler handler : HttpRequestHandler.EP_NAME.getExtensions()) {
try {
if (handler.isSupported(request) && handler.process(urlDecoder, request, context)) {
prevHandlerAttribute.set(handler);
return true;
}
}
catch (Throwable e) {
Logger.getInstance(BuiltInServer.class).error(e);
}
}
if (urlDecoder.path().equals("/favicon.ico")) {
Icon icon = IconLoader.findIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl());
if (icon != null) {
BufferedImage image = UIUtil.createImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(null, image.getGraphics(), 0, 0);
byte[] icoBytes = Sanselan.writeImageToBytes(image, ImageFormat.IMAGE_FORMAT_ICO, null);
HttpResponse response = Responses.response(FileResponses.getContentType(urlDecoder.path()), Unpooled.wrappedBuffer(icoBytes));
Responses.addNoCache(response);
Responses.send(response, context.channel(), request);
return true;
}
}
return false;
}
示例3: process
import org.jetbrains.ide.HttpRequestHandler; //导入依赖的package包/类
@Override
protected boolean process(ChannelHandlerContext context, FullHttpRequest request, QueryStringDecoder urlDecoder) throws Exception {
ThrowableNotNullFunction<HttpRequestHandler, Boolean, IOException> checkAndProcess = httpRequestHandler -> {
return httpRequestHandler.isSupported(request) &&
!NettyKt.isWriteFromBrowserWithoutOrigin(request) &&
httpRequestHandler.isAccessible(request) &&
httpRequestHandler.process(urlDecoder, request, context);
};
Attribute<HttpRequestHandler> prevHandlerAttribute = context.channel().attr(PREV_HANDLER);
HttpRequestHandler connectedHandler = prevHandlerAttribute.get();
if (connectedHandler != null) {
if (checkAndProcess.fun(connectedHandler)) {
return true;
}
// prev cached connectedHandler is not suitable for this request, so, let's find it again
prevHandlerAttribute.set(null);
}
for (HttpRequestHandler handler : HttpRequestHandler.EP_NAME.getExtensions()) {
try {
if (checkAndProcess.fun(handler)) {
prevHandlerAttribute.set(handler);
return true;
}
}
catch (Throwable e) {
Logger.getInstance(BuiltInServer.class).error(e);
}
}
if (urlDecoder.path().equals("/favicon.ico")) {
Icon icon = Application.get().getIcon();
BufferedImage image = UIUtil.createImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(null, image.getGraphics(), 0, 0);
byte[] icoBytes = Imaging.writeImageToBytes(image, ImageFormats.ICO, null);
HttpResponse response = Responses.response(FileResponses.getContentType(urlDecoder.path()), Unpooled.wrappedBuffer(icoBytes));
response = Responses.addNoCache(response);
Responses.send(response, context.channel(), request);
return true;
}
return false;
}