Java Code Examples for io.undertow.util.PathTemplateMatcher#get()

The following examples show how to use io.undertow.util.PathTemplateMatcher#get() . 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: Handler.java    From light-4j with Apache License 2.0 6 votes vote down vote up
/**
 * Add a PathChain (having a non-null path) to the handler data structures.
 */
private static void addPathChain(PathChain pathChain) {
	HttpString method = new HttpString(pathChain.getMethod());

	// Use a random integer as the id for a given path.
	Integer randInt = new Random().nextInt();
	while (handlerListById.containsKey(randInt.toString())) {
		randInt = new Random().nextInt();
	}

	// Flatten out the execution list from a mix of middleware chains and handlers.
	List<HttpHandler> handlers = getHandlersFromExecList(pathChain.getExec());
	if(handlers.size() > 0) {
		// If a matcher already exists for the given type, at to that instead of
		// creating a new one.
		PathTemplateMatcher<String> pathTemplateMatcher = methodToMatcherMap.containsKey(method)
			? methodToMatcherMap.get(method)
			: new PathTemplateMatcher<>();

		if(pathTemplateMatcher.get(pathChain.getPath()) == null) { pathTemplateMatcher.add(pathChain.getPath(), randInt.toString()); }
		methodToMatcherMap.put(method, pathTemplateMatcher);
		handlerListById.put(randInt.toString(), handlers);
	}
}
 
Example 2
Source File: RoutingHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public synchronized RoutingHandler add(String method, String template, HttpHandler handler) {
    PathTemplateMatcher<RoutingMatch> matcher = matches.get(method);
    if (matcher == null) {
        matches.put(method, matcher = new PathTemplateMatcher<>());
    }
    RoutingMatch res = matcher.get(template);
    if (res == null) {
        matcher.add(template, res = new RoutingMatch());
    }
    if (allMethodsMatcher.get(template) == null) {
        allMethodsMatcher.add(template, res);
    }
    res.defaultHandler = handler;
    return this;
}
 
Example 3
Source File: RoutingHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public synchronized RoutingHandler add(String method, String template, Predicate predicate, HttpHandler handler) {
    PathTemplateMatcher<RoutingMatch> matcher = matches.get(method);
    if (matcher == null) {
        matches.put(method, matcher = new PathTemplateMatcher<>());
    }
    RoutingMatch res = matcher.get(template);
    if (res == null) {
        matcher.add(template, res = new RoutingMatch());
    }
    if (allMethodsMatcher.get(template) == null) {
        allMethodsMatcher.add(template, res);
    }
    res.predicatedHandlers.add(new HandlerHolder(predicate, handler));
    return this;
}
 
Example 4
Source File: RoutingHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public synchronized RoutingHandler add(HttpString method, String template, HttpHandler handler) {
    PathTemplateMatcher<RoutingMatch> matcher = matches.get(method);
    if (matcher == null) {
        matches.put(method, matcher = new PathTemplateMatcher<>());
    }
    RoutingMatch res = matcher.get(template);
    if (res == null) {
        matcher.add(template, res = new RoutingMatch());
    }
    if (allMethodsMatcher.get(template) == null) {
        allMethodsMatcher.add(template, res);
    }
    res.defaultHandler = handler;
    return this;
}
 
Example 5
Source File: RoutingHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public synchronized RoutingHandler add(HttpString method, String template, Predicate predicate, HttpHandler handler) {
    PathTemplateMatcher<RoutingMatch> matcher = matches.get(method);
    if (matcher == null) {
        matches.put(method, matcher = new PathTemplateMatcher<>());
    }
    RoutingMatch res = matcher.get(template);
    if (res == null) {
        matcher.add(template, res = new RoutingMatch());
    }
    if (allMethodsMatcher.get(template) == null) {
        allMethodsMatcher.add(template, res);
    }
    res.predicatedHandlers.add(new HandlerHolder(predicate, handler));
    return this;
}