@Override public String readAttribute(final HttpServerExchange exchange) { return exchange.getRelativePath(); }
@Override public String readAttribute(final HttpServerExchange exchange) { return exchange.getRelativePath(); }
/** * Get the canonical request URI from the request mapping data requestPath * * @param request * @return the request URI path */ protected String requestURI(HttpServerExchange request) { String uri = request.getRelativePath(); if (uri == null || uri.equals("/")) { uri = ""; } return uri; }
@Override public boolean resolve(final HttpServerExchange value) { return value.getRelativePath().endsWith(suffix); }
private void handleRestRequest(HttpServerExchange exchange) throws IOException { logger.log(Level.INFO, "HTTP request received:" + exchange.getRelativePath()); exchange.startBlocking(); if (exchange.getRelativePath().startsWith("/file/")) { handleFileRequest(exchange); } else { handleNormalRequest(exchange); } }
@Override public boolean resolve(final HttpServerExchange value) { final String relativePath = value.getRelativePath(); PathMatcher.PathMatch<Boolean> result = pathMatcher.match(relativePath); return Boolean.TRUE.equals(result.getValue()); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.putAttachment(OLD_RELATIVE_PATH, exchange.getRelativePath()); handler.handleRequest(exchange); } };
private void handleFileRequest(HttpServerExchange exchange) throws FileNotFoundException, IOException { String tempFileToken = exchange.getRelativePath().substring("/file/".length()); File tempFile = daemonWebServer.getFileTokenTempFileFromCache(tempFileToken); if (tempFile != null) { logger.log(Level.INFO, "- Temp file: " + tempFileToken); IOUtils.copy(new FileInputStream(tempFile), exchange.getOutputStream()); exchange.endExchange(); } else { logger.log(Level.WARNING, "Invalid request received; Cannot find file token " + tempFileToken); eventBus.post(new BadRequestResponse(-1, "Invalid request.")); } } }
@Override public boolean resolve(final HttpServerExchange value) { final String relativePath = value.getRelativePath(); PathMatcher.PathMatch<Boolean> result = pathMatcher.match(relativePath); boolean matches = Boolean.TRUE.equals(result.getValue()); if(matches) { Map<String, Object> context = value.getAttachment(PREDICATE_CONTEXT); if(context == null) { value.putAttachment(PREDICATE_CONTEXT, context = new TreeMap<>()); } context.put("remaining", result.getRemaining()); } return matches; }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if(exchange.getRequestMethod().equals(Methods.OPTIONS) && exchange.getRelativePath().equals("*")) { //handle the OPTIONS requests //basically just return an empty response exchange.endExchange(); return; } next.handleRequest(exchange); } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if (exchange.getRequestMethod().equals(Methods.GET) && exchange.getRelativePath().matches(ACME_CHALLENGE_REGEX)) { super.handleRequest(exchange); } else { next.handleRequest(exchange); } } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { exchange.setRelativePath(CanonicalPathUtils.canonicalize(exchange.getRelativePath())); next.handleRequest(exchange); }
protected void storeInitialLocation(final HttpServerExchange exchange) { Session session = Sessions.getOrCreateSession(exchange); session.setAttribute(LOCATION_ATTRIBUTE, RedirectBuilder.redirect(exchange, exchange.getRelativePath())); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { InetSocketAddress peer = exchange.getSourceAddress(); String endpoint = exchange.getRelativePath() + "@" + exchange.getRequestMethod().toString().toLowerCase(); if (!isAllowed(peer.getAddress(), endpoint)) { setExchangeStatus(exchange, INVALID_IP_FOR_PATH, peer.toString(), endpoint); return; } Handler.next(exchange, next); }
/** * Handles the case in with a match was not found for the http method but might exist for another http method. * For example: POST not matched for a path but at least one match exists for same path. * * @param exchange The object for which its handled the "no match" case. * @throws Exception */ private void handleNoMatch(final HttpServerExchange exchange) throws Exception { // if invalidMethodHandler is null we fail fast without matching with allMethodsMatcher if (invalidMethodHandler != null && allMethodsMatcher.match(exchange.getRelativePath()) != null) { invalidMethodHandler.handleRequest(exchange); return; } fallbackHandler.handleRequest(exchange); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { String old = exchange.getAttachment(OLD_RELATIVE_PATH); if(!old.equals(exchange.getRelativePath())) { ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); ServletPathMatch info = src.getDeployment().getServletPaths().getServletHandlerByPath(exchange.getRelativePath()); src.setCurrentServlet(info.getServletChain()); src.setServletPathMatch(info); } handler.handleRequest(exchange); } };
@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); }
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(); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { PathTemplateMatcher.PathMatchResult<HttpHandler> match = pathTemplateMatcher.match(exchange.getRelativePath()); if (match == null) { next.handleRequest(exchange); return; } exchange.putAttachment(PATH_TEMPLATE_MATCH, new PathTemplateMatch(match.getMatchedTemplate(), match.getParameters())); exchange.putAttachment(io.undertow.util.PathTemplateMatch.ATTACHMENT_KEY, new io.undertow.util.PathTemplateMatch(match.getMatchedTemplate(), match.getParameters())); if (rewriteQueryParameters) { for (Map.Entry<String, String> entry : match.getParameters().entrySet()) { exchange.addQueryParam(entry.getKey(), entry.getValue()); } } match.getValue().handleRequest(exchange); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if(exchange.getConnection().isPushSupported()) { PathMatcher.PathMatch<String[]> result = pathMatcher.match(exchange.getRelativePath()); if(result != null) { String[] value = result.getValue(); for(int i = 0; i < value.length; ++i) { exchange.getConnection().pushResource(value[i], Methods.GET, requestHeaders); } } } next.handleRequest(exchange); }