private static RequestHandler wrapHandlerIfFormPost(RequestHandler requestHandler, HttpServletRequest servletRequest, boolean removeBodyForFormPost) { if (!servletRequest.getMethod().equals("POST")) { return requestHandler; } String contentType = servletRequest.getHeader(HttpHeaders.Names.CONTENT_TYPE); if (contentType == null) { return requestHandler; } if (!contentType.startsWith(APPLICATION_X_WWW_FORM_URLENCODED)) { return requestHandler; } return new FormPostRequestHandler(requestHandler, getCharsetName(contentType), removeBodyForFormPost); }
public void dispatch() throws IOException { ServletRequestReader servletRequestReader; try { servletRequestReader = handleRequest(); } catch (Throwable throwable) { servletResponseController.trySendError(throwable); servletResponseController.finishedFuture().whenComplete((result, exception) -> completeRequestCallback.accept(null, throwable)); return; } try { onError(servletRequestReader.finishedFuture, servletResponseController::trySendError); onError(servletResponseController.finishedFuture(), servletRequestReader::onError); CompletableFuture.allOf(servletRequestReader.finishedFuture, servletResponseController.finishedFuture()) .whenComplete(completeRequestCallback); } catch (Throwable throwable) { log.log(Level.WARNING, "Failed registering finished listeners.", throwable); } }
private ResponseHandler createResponseHandler(AtomicReference<Boolean> responseReturned, HttpServletRequest httpRequest, HttpServletResponse httpResponse) { return jdiscResponse -> { boolean oldValueWasNull = responseReturned.compareAndSet(null, true); if (!oldValueWasNull) throw new RuntimeException("Can't return response from filter asynchronously"); HttpRequestDispatch requestDispatch = createRequestDispatch(httpRequest, httpResponse); return requestDispatch.handleRequestFilterResponse(jdiscResponse); }; }
private void dispatchHttpRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { AccessLogEntry accessLogEntry = new AccessLogEntry(); request.setAttribute(ATTRIBUTE_NAME_ACCESS_LOG_ENTRY, accessLogEntry); try { switch (request.getDispatcherType()) { case REQUEST: new HttpRequestDispatch(context, accessLogEntry, getMetricContext(request), request, response) .dispatch(); break; default: if (log.isLoggable(Level.INFO)) { log.info("Unexpected " + request.getDispatcherType() + "; " + formatAttributes(request)); } break; } } catch (OverloadException e) { // nop } catch (RuntimeException e) { throw new ExceptionWrapper(e); } }
public HttpRequestDispatch(JDiscContext jDiscContext, AccessLogEntry accessLogEntry, Context metricContext, HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException { this.jDiscContext = jDiscContext; requestHandler = newRequestHandler(jDiscContext, accessLogEntry, servletRequest); this.jettyRequest = (Request) servletRequest; this.metricReporter = new MetricReporter(jDiscContext.metric, metricContext, jettyRequest.getTimeStamp()); honourMaxKeepAliveRequests(); this.servletResponseController = new ServletResponseController( servletRequest, servletResponse, jDiscContext.janitor, metricReporter, jDiscContext.developerMode()); this.async = servletRequest.startAsync(); async.setTimeout(0); metricReporter.uriLength(jettyRequest.getOriginalURI().length()); }
private static RequestHandler newRequestHandler(JDiscContext context, AccessLogEntry accessLogEntry, HttpServletRequest servletRequest) { RequestHandler requestHandler = wrapHandlerIfFormPost( new FilteringRequestHandler(context.requestFilters, context.responseFilters), servletRequest, context.serverConfig.removeRawPostBodyForWwwUrlEncodedPost()); return new AccessLoggingRequestHandler(requestHandler, accessLogEntry); }
private HttpRequestDispatch createRequestDispatch(HttpServletRequest request, HttpServletResponse response) { try { final AccessLogEntry accessLogEntry = null; // Not used in this context. return new HttpRequestDispatch(jDiscContext, accessLogEntry, getConnector(request).getRequestMetricContext(request), request, response); } catch (IOException e) { throw throwUnchecked(e); } }