@Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException x) { log.error("execution of {} resulted in exception", exchange.getRequestPath(), x); callback.onException(exchange, sender, x); }
/** * Process a mod_cluster mgmt command. * * @param exchange the http server exchange * @param requestData the request data * @param action the mgmt action * @throws IOException */ void processCommand(final HttpServerExchange exchange, final RequestData requestData, final MCMPAction action) throws IOException { if (exchange.getRequestPath().equals("*") || exchange.getRequestPath().endsWith("/*")) { processNodeCommand(exchange, requestData, action); } else { processAppCommand(exchange, requestData, action); } }
public UndertowRequest(final HttpServerExchange exchange, final Config conf) throws IOException { this.exchange = exchange; this.blocking = Suppliers.memoize(() -> this.exchange.startBlocking()); this.conf = conf; this.path = Router.decode(exchange.getRequestPath()); }
@Override public AuthenticationMechanismOutcome authenticate(final HttpServerExchange exchange, final SecurityContext securityContext) { if (exchange.getRequestPath().endsWith(postLocation) && exchange.getRequestMethod().equals(Methods.POST)) { return runFormAuth(exchange, securityContext); } else { return AuthenticationMechanismOutcome.NOT_ATTEMPTED; } }
@Override public boolean authenticate() { UndertowLogger.SECURITY_LOGGER.debugf("Attempting to authenticate %s, authentication required: %s", exchange.getRequestPath(), isAuthenticationRequired()); if(authenticationState == AuthenticationState.ATTEMPTED || (authenticationState == AuthenticationState.CHALLENGE_SENT && !exchange.isResponseStarted())) { //we are re-attempted, so we just reset the state //see UNDERTOW-263 authenticationState = AuthenticationState.NOT_ATTEMPTED; } return !authTransition(); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { boolean handlingRequired = File.separatorChar != '/'; if (handlingRequired) { exchange.setRequestPath(canonicalize(exchange.getRequestPath().replace(File.separatorChar, '/'))); exchange.setRelativePath(canonicalize(exchange.getRelativePath().replace(File.separatorChar, '/'))); exchange.setResolvedPath(canonicalize(exchange.getResolvedPath().replace(File.separatorChar, '/'))); } next.handleRequest(exchange); }
private boolean authTransition() { if (authTransitionRequired()) { switch (authenticationState) { case NOT_ATTEMPTED: authenticationState = attemptAuthentication(); break; case ATTEMPTED: authenticationState = sendChallenges(); break; default: throw new IllegalStateException("It should not be possible to reach this."); } return authTransition(); } else { UndertowLogger.SECURITY_LOGGER.debugf("Authentication result was %s for %s", authenticationState, exchange.getRequestPath()); // Keep in mind this switch statement is only called after a call to authTransitionRequired. switch (authenticationState) { case NOT_ATTEMPTED: // No constraint was set that mandated authentication so not reason to hold up the request. case ATTEMPTED: // Attempted based on incoming request but no a failure so allow the request to proceed. case AUTHENTICATED: // Authentication was a success - no responses sent. return false; default: // Remaining option is CHALLENGE_SENT to request processing must end. return true; } } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if (Handler.start(exchange)) { Handler.next(exchange); } else { // There is no matching path/method combination. Check if there are defaultHandlers defined. if(Handler.startDefaultHandlers(exchange)) { Handler.next(exchange); } else { String methodPath = String.format("Method: %s, RequestPath: %s", exchange.getRequestMethod(), exchange.getRequestPath()); setExchangeStatus(exchange, MISSING_HANDlER, methodPath); } } } }
buf.append("<h1>" + MOD_CLUSTER_EXPOSED_VERSION + "</h1>"); final String uri = exchange.getRequestPath(); final String nonce = getNonce(); if (refreshTime <= 0) {
final StringBuilder sb = new StringBuilder(); final boolean decodeSlash = exchange.getConnection().getUndertowOptions().get(UndertowOptions.ALLOW_ENCODED_SLASH, false); exchange.setRequestPath(URLUtils.decode(exchange.getRequestPath(), charset, decodeSlash, false, sb)); exchange.setRelativePath(URLUtils.decode(exchange.getRelativePath(), charset, decodeSlash, false, sb)); exchange.setResolvedPath(URLUtils.decode(exchange.getResolvedPath(), charset, decodeSlash, false, sb));
UndertowLogger.REQUEST_LOGGER.debugf("Refusing request for %s due to lack of Origin: header", exchange.getRequestPath()); UndertowLogger.REQUEST_LOGGER.debugf("Refusing request for %s due to Origin %s not being in the allowed origins list", exchange.getRequestPath(), header); UndertowLogger.REQUEST_LOGGER.debugf("Refusing request for %s as none of the specified origins %s were in the allowed origins list", exchange.getRequestPath(), origin);
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { String fullPath; String requestPath; if(exchange.getQueryString().isEmpty()) { fullPath = exchange.getRequestURL(); requestPath = exchange.getRequestPath(); } else{ fullPath = exchange.getRequestURL() + "?" + exchange.getQueryString(); requestPath = exchange.getRequestPath() + "?" + exchange.getQueryString(); } doPush(exchange, fullPath); String referrer = exchange.getRequestHeaders().getFirst(Headers.REFERER); if (referrer != null) { String accept = exchange.getRequestHeaders().getFirst(Headers.ACCEPT); if (accept == null || !accept.contains("text/html")) { //if accept contains text/html it generally means the user has clicked //a link to move to a new page, and is not a resource load for the current page //we only care about resources for the current page exchange.addExchangeCompleteListener(new PushCompletionListener(fullPath, requestPath, referrer)); } } next.handleRequest(exchange); }
public static void renderDirectoryListing(HttpServerExchange exchange, Resource resource) { String requestPath = exchange.getRequestPath(); if (! requestPath.endsWith("/")) { exchange.setStatusCode(StatusCodes.FOUND); exchange.getResponseHeaders().put(Headers.LOCATION, RedirectBuilder.redirect(exchange, exchange.getRelativePath() + "/", true)); exchange.endExchange(); return; } StringBuilder builder = renderDirectoryListing(requestPath, resource); try { ByteBuffer output = ByteBuffer.wrap(builder.toString().getBytes(StandardCharsets.UTF_8)); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html; charset=UTF-8"); exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, String.valueOf(output.limit())); exchange.getResponseHeaders().put(Headers.LAST_MODIFIED, DateUtils.toDateString(new Date())); exchange.getResponseHeaders().put(Headers.CACHE_CONTROL, "must-revalidate"); Channels.writeBlocking(exchange.getResponseChannel(), output); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } catch (IOException e) { UndertowLogger.REQUEST_IO_LOGGER.ioException(e); exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR); } exchange.endExchange(); }
String[] parts = exchange.getRequestPath().split(":"); if(parts.length != 2) {
public ChallengeResult sendChallenge(final HttpServerExchange exchange, final SecurityContext securityContext) { if (exchange.getRequestPath().endsWith(postLocation) && exchange.getRequestMethod().equals(Methods.POST)) { UndertowLogger.SECURITY_LOGGER.debugf("Serving form auth error page %s for %s", loginPage, exchange); // This method would no longer be called if authentication had already occurred. Integer code = servePage(exchange, errorPage); return new ChallengeResult(true, code); } else { UndertowLogger.SECURITY_LOGGER.debugf("Serving login form %s for %s", loginPage, exchange); // we need to store the URL storeInitialLocation(exchange); // TODO - Rather than redirecting, in order to make this mechanism compatible with the other mechanisms we need to // return the actual error page not a redirect. Integer code = servePage(exchange, loginPage); return new ChallengeResult(true, code); } }
.match(httpServerExchange.getRequestPath()); if (result != null) {
public CachedHttpRequest(final HttpServerExchange exchange) { this.path = exchange.getRequestPath(); this.etag = ETagUtils.getETag(exchange); this.contentLocation = exchange.getResponseHeaders().getFirst(Headers.CONTENT_LOCATION); this.language = exchange.getResponseHeaders().getFirst(Headers.CONTENT_LANGUAGE); this.contentType = exchange.getResponseHeaders().getFirst(Headers.CONTENT_TYPE); String lmString = exchange.getResponseHeaders().getFirst(Headers.LAST_MODIFIED); if (lmString == null) { this.lastModified = null; } else { this.lastModified = DateUtils.parseDate(lmString); } //the content encoding can be decided dynamically, based on the current state of the request //as the decision to compress generally depends on size and mime type final AllowedContentEncodings encoding = exchange.getAttachment(AllowedContentEncodings.ATTACHMENT_KEY); if(encoding != null) { this.contentEncoding = encoding.getCurrentContentEncoding(); } else { this.contentEncoding = exchange.getResponseHeaders().getFirst(Headers.CONTENT_ENCODING); } this.responseCode = exchange.getStatusCode(); }
newExchange.setRequestMethod(exchange.getRequestMethod()); exchange.setRequestURI(exchange.getRequestURI(), exchange.isHostIncludedInRequestURI()); exchange.setRequestPath(exchange.getRequestPath()); exchange.setRelativePath(exchange.getRelativePath()); newExchange.setPersistent(true);
newExchange.setRequestMethod(exchange.getRequestMethod()); exchange.setRequestURI(exchange.getRequestURI(), exchange.isHostIncludedInRequestURI()); exchange.setRequestPath(exchange.getRequestPath()); exchange.setRelativePath(exchange.getRelativePath()); newExchange.getRequestHeaders().put(Headers.CONNECTION, Headers.KEEP_ALIVE.toString());
return; } else if (!exchange.getRequestPath().endsWith("/")) { exchange.setStatusCode(StatusCodes.FOUND); exchange.getResponseHeaders().put(Headers.LOCATION, RedirectBuilder.redirect(exchange, exchange.getRelativePath() + "/", true));