@Override protected void service(final HttpServletRequest req, final HttpServletResponse rsp) throws ServletException, IOException { try { dispatcher.handle( new ServletServletRequest(req, tmpdir), new ServletServletResponse(req, rsp)); } catch (IOException | ServletException | RuntimeException ex) { log.error("execution of: " + req.getRequestURI() + " resulted in error", ex); throw ex; } catch (Throwable ex) { log.error("execution of: " + req.getRequestURI() + " resulted in error", ex); throw new IllegalStateException(ex); } }
@Override public void channelRead0(final ChannelHandlerContext ctx, final Object msg) { if (msg instanceof HttpRequest) { ctx.channel().attr(NettyRequest.NEED_FLUSH).set(true); HttpRequest req = (HttpRequest) msg; ctx.channel().attr(PATH).set(req.method().name() + " " + req.uri()); if (HttpUtil.is100ContinueExpected(req)) { ctx.write(new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.CONTINUE)); } boolean keepAlive = HttpUtil.isKeepAlive(req); try { String streamId = req.headers().get(STREAM_ID); HttpHeaders headers = new DefaultHttpHeaders(); handler.handle( new NettyRequest(ctx, req, headers, tmpdir, wsMaxMessageSize), new NettyResponse(ctx, headers, bufferSize, keepAlive, streamId)); } catch (Throwable ex) { exceptionCaught(ctx, ex); } } else if (msg instanceof WebSocketFrame) { Attribute<NettyWebSocket> ws = ctx.channel().attr(NettyWebSocket.KEY); ws.get().handle(msg); } }
@Override public void handle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { try { baseRequest.setHandled(true); String type = baseRequest.getContentType(); boolean multipart = false; if (type != null && type.toLowerCase().startsWith(MediaType.multipart.name())) { baseRequest.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, multiPartConfig); multipart = true; } ServletServletRequest nreq = new ServletServletRequest(request, tmpdir, multipart) .with(upgrade(baseRequest, request, response, webSocketServerFactory)); dispatcher.handle(nreq, new JettyResponse(nreq, response)); } catch (IOException | ServletException | RuntimeException ex) { baseRequest.setHandled(false); log.error("execution of: " + target + " resulted in error", ex); throw ex; } catch (Throwable ex) { baseRequest.setHandled(false); log.error("execution of: " + target + " resulted in error", ex); throw new IllegalStateException(ex); } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (exchange.isInIoThread()) { HeaderValues upgrade = exchange.getRequestHeaders().get(Headers.UPGRADE); if (upgrade != null && upgrade.contains("h2c")) { // reset protocol exchange.setProtocol(Protocols.HTTP_1_1); } exchange.dispatch(this); return; } handler.handle(new UndertowRequest(exchange, config), new UndertowResponse(exchange)); }
@Override protected void service(final HttpServletRequest req, final HttpServletResponse rsp) throws ServletException, IOException { try { dispatcher.handle( new ServletServletRequest(req, tmpdir), new ServletServletResponse(req, rsp)); } catch (IOException | ServletException | RuntimeException ex) { log.error("execution of: " + req.getRequestURI() + " resulted in error", ex); throw ex; } catch (Throwable ex) { log.error("execution of: " + req.getRequestURI() + " resulted in error", ex); throw new IllegalStateException(ex); } }
@Override protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { try { dispatcher.handle(new ServletServletRequest(req, tmpdir), new ServletServletResponse(req, resp)); } catch (final Exception e) { throw new ServletException(e); } }
@Override public void channelRead0(final ChannelHandlerContext ctx, final Object msg) { if (msg instanceof HttpRequest) { ctx.channel().attr(NettyRequest.NEED_FLUSH).set(true); HttpRequest req = (HttpRequest) msg; ctx.channel().attr(PATH).set(req.method().name() + " " + req.uri()); if (HttpUtil.is100ContinueExpected(req)) { ctx.write(new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.CONTINUE)); } boolean keepAlive = HttpUtil.isKeepAlive(req); try { String streamId = req.headers().get(STREAM_ID); HttpHeaders headers = new DefaultHttpHeaders(); handler.handle( new NettyRequest(ctx, req, headers, tmpdir, wsMaxMessageSize), new NettyResponse(ctx, headers, bufferSize, keepAlive, streamId)); } catch (Throwable ex) { exceptionCaught(ctx, ex); } } else if (msg instanceof WebSocketFrame) { Attribute<NettyWebSocket> ws = ctx.channel().attr(NettyWebSocket.KEY); ws.get().handle(msg); } }
... HttpServer server = HttpServer.create(myInetSocketAddress, 5); HttpContext context = server.createContext(mySoapPath); Endpoint endpoint = Endpoint.create(mySoapImpl); endpoint.publish(context); MyHandler handler = new MyHandler(context.getHandler()); server.removeContext(mySoapPath); server.createContext(mySoapPath, handler); server.start(); ... private class MyHandler implements HttpHandler { private HttpHandler h; public MyHandler(HttpHandler in) { h = in; } public void handle(HttpExchange t) throws IOException { h.handle(t); t.getResponseHeaders().set("Connection", "close"); t.sendResponseHeaders(200, 0); t.close(); } }
@Override public void handle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { try { baseRequest.setHandled(true); String type = baseRequest.getContentType(); boolean multipart = false; if (type != null && type.toLowerCase().startsWith(MediaType.multipart.name())) { baseRequest.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, multiPartConfig); multipart = true; } ServletServletRequest nreq = new ServletServletRequest(request, tmpdir, multipart) .with(upgrade(baseRequest, request, response, webSocketServerFactory)); dispatcher.handle(nreq, new JettyResponse(nreq, response)); } catch (IOException | ServletException | RuntimeException ex) { baseRequest.setHandled(false); log.error("execution of: " + target + " resulted in error", ex); throw ex; } catch (Throwable ex) { baseRequest.setHandled(false); log.error("execution of: " + target + " resulted in error", ex); throw new IllegalStateException(ex); } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (exchange.isInIoThread()) { HeaderValues upgrade = exchange.getRequestHeaders().get(Headers.UPGRADE); if (upgrade != null && upgrade.contains("h2c")) { // reset protocol exchange.setProtocol(Protocols.HTTP_1_1); } exchange.dispatch(this); return; } handler.handle(new UndertowRequest(exchange, config), new UndertowResponse(exchange)); }