本文整理匯總了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;
}