Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package io.undertow.server.handlers;
 
 
 import java.util.Map;

A handler that matches URI templates

Author(s):
Stuart Douglas
See also:
io.undertow.util.PathTemplateMatcher
public class PathTemplateHandler implements HttpHandler {
    private final boolean rewriteQueryParameters;
    public static final AttachmentKey<PathTemplateMatchPATH_TEMPLATE_MATCH = AttachmentKey.create(PathTemplateMatch.class);
    public PathTemplateHandler(boolean rewriteQueryParameters) {
        this. = rewriteQueryParameters;
    }
    public PathTemplateHandler() {
        this(true);
    }
    @Override
    public void handleRequest(HttpServerExchange exchangethrows Exception {
        if (match == null) {
            exchange.setResponseCode(404);
            exchange.endExchange();
            return;
        }
        exchange.putAttachment(new PathTemplateMatch(match.getMatchedTemplate(), match.getParameters()));
        if () {
            for (Map.Entry<StringStringentry : match.getParameters().entrySet()) {
                exchange.addQueryParam(entry.getKey(), entry.getValue());
            }
        }
        match.getValue().handleRequest(exchange);
    }
    public PathTemplateHandler add(final String uriTemplatefinal HttpHandler handler) {
        .add(uriTemplatehandler);
        return this;
    }
    public PathTemplateHandler remove(final String uriTemplate) {
        .remove(uriTemplate);
        return this;
    }
    public static final class PathTemplateMatch {
        private final String matchedTemplate;
        private final Map<StringStringparameters;
        public PathTemplateMatch(String matchedTemplateMap<StringStringparameters) {
            this. = matchedTemplate;
            this. = parameters;
        }
        public String getMatchedTemplate() {
            return ;
        }
        public Map<StringStringgetParameters() {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X