Java Code Examples for io.undertow.server.HttpServerExchange#setResolvedPath()

The following examples show how to use io.undertow.server.HttpServerExchange#setResolvedPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestPathAttribute.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
    int pos = newValue.indexOf('?');
    exchange.setResolvedPath("");
    if (pos == -1) {
        exchange.setRelativePath(newValue);
        exchange.setRequestURI(newValue);
        exchange.setRequestPath(newValue);
    } else {
        final String path = newValue.substring(0, pos);
        exchange.setRequestPath(path);
        exchange.setRelativePath(path);
        exchange.setRequestURI(newValue);

        final String newQueryString = newValue.substring(pos);
        exchange.setQueryString(newQueryString);
        exchange.getQueryParameters().putAll(QueryParameterUtils.parseQueryString(newQueryString.substring(1), QueryParameterUtils.getQueryParamEncoding(exchange)));
    }
}
 
Example 2
Source File: RequestURLAttribute.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
    int pos = newValue.indexOf('?');
    if (pos == -1) {
        exchange.setRelativePath(newValue);
        exchange.setRequestURI(newValue);
        exchange.setRequestPath(newValue);
        exchange.setResolvedPath("");
    } else {
        final String path = newValue.substring(0, pos);
        exchange.setRelativePath(path);
        exchange.setRequestURI(path);
        exchange.setRequestPath(path);
        exchange.setResolvedPath("");
        final String newQueryString = newValue.substring(pos);
        exchange.setQueryString(newQueryString);
        exchange.getQueryParameters().putAll(QueryParameterUtils.parseQueryString(newQueryString.substring(1), QueryParameterUtils.getQueryParamEncoding(exchange)));
    }

}
 
Example 3
Source File: URLDecodingHandler.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    boolean decodeDone = exchange.getUndertowOptions().get(UndertowOptions.DECODE_URL, true);
    if (!decodeDone) {
        final StringBuilder sb = new StringBuilder();
        final boolean decodeSlash = exchange.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));
        if (!exchange.getQueryString().isEmpty()) {
            final TreeMap<String, Deque<String>> newParams = new TreeMap<>();
            for (Map.Entry<String, Deque<String>> param : exchange.getQueryParameters().entrySet()) {
                final Deque<String> newVales = new ArrayDeque<>(param.getValue().size());
                for (String val : param.getValue()) {
                    newVales.add(URLUtils.decode(val, charset, true, true, sb));
                }
                newParams.put(URLUtils.decode(param.getKey(), charset, true, true, sb), newVales);
            }
            exchange.getQueryParameters().clear();
            exchange.getQueryParameters().putAll(newParams);
        }
    }
    next.handleRequest(exchange);
}
 
Example 4
Source File: RequestPathAttribute.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
    int pos = newValue.indexOf('?');
    exchange.setResolvedPath("");
    if (pos == -1) {
        exchange.setRelativePath(newValue);
        exchange.setRequestURI(newValue);
        exchange.setRequestPath(newValue);
    } else {
        final String path = newValue.substring(0, pos);
        exchange.setRequestPath(path);
        exchange.setRelativePath(path);
        exchange.setRequestURI(newValue);

        final String newQueryString = newValue.substring(pos);
        exchange.setQueryString(newQueryString);
        exchange.getQueryParameters().putAll(QueryParameterUtils.parseQueryString(newQueryString.substring(1), QueryParameterUtils.getQueryParamEncoding(exchange)));
    }
}
 
Example 5
Source File: RequestURLAttribute.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
    int pos = newValue.indexOf('?');
    if (pos == -1) {
        exchange.setRelativePath(newValue);
        exchange.setRequestURI(newValue);
        exchange.setRequestPath(newValue);
        exchange.setResolvedPath("");
    } else {
        final String path = newValue.substring(0, pos);
        exchange.setRelativePath(path);
        exchange.setRequestURI(path);
        exchange.setRequestPath(path);
        exchange.setResolvedPath("");
        final String newQueryString = newValue.substring(pos);
        exchange.setQueryString(newQueryString);
        exchange.getQueryParameters().putAll(QueryParameterUtils.parseQueryString(newQueryString.substring(1), QueryParameterUtils.getQueryParamEncoding(exchange)));
    }

}
 
Example 6
Source File: URLDecodingHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    boolean decodeDone = exchange.getConnection().getUndertowOptions().get(UndertowOptions.DECODE_URL, true);
    if (!decodeDone) {
        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));
        if (!exchange.getQueryString().isEmpty()) {
            final TreeMap<String, Deque<String>> newParams = new TreeMap<>();
            for (Map.Entry<String, Deque<String>> param : exchange.getQueryParameters().entrySet()) {
                final Deque<String> newVales = new ArrayDeque<>(param.getValue().size());
                for (String val : param.getValue()) {
                    newVales.add(URLUtils.decode(val, charset, true, true, sb));
                }
                newParams.put(URLUtils.decode(param.getKey(), charset, true, true, sb), newVales);
            }
            exchange.getQueryParameters().clear();
            exchange.getQueryParameters().putAll(newParams);
        }
    }
    next.handleRequest(exchange);
}
 
Example 7
Source File: PathSeparatorHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 8
Source File: PathHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    PathMatcher.PathMatch<HttpHandler> match = null;
    boolean hit = false;
    if(cache != null) {
        match = cache.get(exchange.getRelativePath());
        hit = true;
    }
    if(match == null) {
        match = pathMatcher.match(exchange.getRelativePath());
    }
    if (match.getValue() == null) {
        ResponseCodeHandler.HANDLE_404.handleRequest(exchange);
        return;
    }
    if(hit) {
        cache.add(exchange.getRelativePath(), match);
    }
    exchange.setRelativePath(match.getRemaining());
    if(exchange.getResolvedPath().isEmpty()) {
        //first path handler, we can just use the matched part
        exchange.setResolvedPath(match.getMatched());
    } else {
        //already something in the resolved path
        exchange.setResolvedPath(exchange.getResolvedPath() + match.getMatched());
    }
    match.getValue().handleRequest(exchange);
}
 
Example 9
Source File: ProteusHandler.java    From proteus with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception
{
    PathMatcher.PathMatch<HttpHandler> match = null;
    boolean hit = false;

    if (cache != null) {
        match = cache.get(exchange.getRelativePath());
        hit = true;
    }

    if (match == null) {
        match = pathMatcher.match(exchange.getRelativePath());
    }

    if (match.getValue() == null) {
        handleRouterRequest(exchange);

        return;
    }

    if (hit) {
        cache.add(exchange.getRelativePath(), match);
    }

    exchange.setRelativePath(match.getRemaining());

    if (exchange.getResolvedPath().isEmpty()) {
        // first path handler, we can just use the matched part
        exchange.setResolvedPath(match.getMatched());
    } else {
        // already something in the resolved path

        String sb = exchange.getResolvedPath() +
                match.getMatched();
        exchange.setResolvedPath(sb);
    }

    match.getValue().handleRequest(exchange);
}
 
Example 10
Source File: PathSeparatorHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 11
Source File: PathHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    PathMatcher.PathMatch<HttpHandler> match = null;
    boolean hit = false;
    if(cache != null) {
        match = cache.get(exchange.getRelativePath());
        hit = true;
    }
    if(match == null) {
        match = pathMatcher.match(exchange.getRelativePath());
    }
    if (match.getValue() == null) {
        ResponseCodeHandler.HANDLE_404.handleRequest(exchange);
        return;
    }
    if(hit) {
        cache.add(exchange.getRelativePath(), match);
    }
    exchange.setRelativePath(match.getRemaining());
    if(exchange.getResolvedPath().isEmpty()) {
        //first path handler, we can just use the matched part
        exchange.setResolvedPath(match.getMatched());
    } else {
        //already something in the resolved path
        StringBuilder sb = new StringBuilder(exchange.getResolvedPath().length() + match.getMatched().length());
        sb.append(exchange.getResolvedPath());
        sb.append(match.getMatched());
        exchange.setResolvedPath(sb.toString());
    }
    match.getValue().handleRequest(exchange);
}
 
Example 12
Source File: ResolvedPathAttribute.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
    exchange.setResolvedPath(newValue);
}
 
Example 13
Source File: ResolvedPathAttribute.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
    exchange.setResolvedPath(newValue);
}
 
Example 14
Source File: ServletInitialHandler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void dispatchMockRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException {

    final DefaultByteBufferPool bufferPool = new DefaultByteBufferPool(false, 1024, 0, 0);
    MockServerConnection connection = new MockServerConnection(bufferPool);
    HttpServerExchange exchange = new HttpServerExchange(connection);
    exchange.setRequestScheme(request.getScheme());
    exchange.setRequestMethod(new HttpString(request.getMethod()));
    exchange.setProtocol(Protocols.HTTP_1_0);
    exchange.setResolvedPath(request.getContextPath());
    String relative;
    if (request.getPathInfo() == null) {
        relative = request.getServletPath();
    } else {
        relative = request.getServletPath() + request.getPathInfo();
    }
    exchange.setRelativePath(relative);
    final ServletPathMatch info = paths.getServletHandlerByPath(request.getServletPath());
    final HttpServletResponseImpl oResponse = new HttpServletResponseImpl(exchange, servletContext);
    final HttpServletRequestImpl oRequest = new HttpServletRequestImpl(exchange, servletContext);
    final ServletRequestContext servletRequestContext = new ServletRequestContext(servletContext.getDeployment(), oRequest, oResponse, info);
    servletRequestContext.setServletRequest(request);
    servletRequestContext.setServletResponse(response);
    //set the max request size if applicable
    if (info.getServletChain().getManagedServlet().getMaxRequestSize() > 0) {
        exchange.setMaxEntitySize(info.getServletChain().getManagedServlet().getMaxRequestSize());
    }
    exchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext);

    exchange.startBlocking(new ServletBlockingHttpExchange(exchange));
    servletRequestContext.setServletPathMatch(info);

    try {
        dispatchRequest(exchange, servletRequestContext, info.getServletChain(), DispatcherType.REQUEST);
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new ServletException(e);
    }
}