Search in sources :

Example 1 with Path

use of io.gravitee.gateway.handlers.api.path.Path in project gravitee-gateway by gravitee-io.

the class ApiPolicyChainResolver method calculate.

@Override
protected List<Policy> calculate(StreamType streamType, Request request, Response response, ExecutionContext executionContext) {
    // Resolve the "configured" path according to the inbound request
    Path path = pathResolver.resolve(request.path());
    executionContext.setAttribute(ExecutionContext.ATTR_RESOLVED_PATH, path.getResolvedPath());
    return path.getRules().stream().filter(rule -> rule.isEnabled() && rule.getMethods().contains(request.method())).map(rule -> create(streamType, rule.getPolicy().getName(), rule.getPolicy().getConfiguration())).filter(Objects::nonNull).collect(Collectors.toList());
}
Also used : Path(io.gravitee.gateway.handlers.api.path.Path) Objects(java.util.Objects) Policy(io.gravitee.gateway.policy.Policy) List(java.util.List) Response(io.gravitee.gateway.api.Response) Path(io.gravitee.gateway.handlers.api.path.Path) StreamType(io.gravitee.gateway.policy.StreamType) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) Request(io.gravitee.gateway.api.Request) AbstractPolicyChainResolver(io.gravitee.gateway.policy.AbstractPolicyChainResolver) PathResolver(io.gravitee.gateway.handlers.api.path.PathResolver) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors)

Example 2 with Path

use of io.gravitee.gateway.handlers.api.path.Path in project gravitee-gateway by gravitee-io.

the class AbstractPathResolver method resolve.

@Override
public Path resolve(final String path) {
    String decodedPath;
    try {
        decodedPath = URLDecoder.decode(path, DEFAULT_CHARSET);
    } catch (UnsupportedEncodingException uee) {
        decodedPath = path;
    }
    decodedPath += '/';
    int pieces = -1;
    Path bestPath = null;
    for (Path registerPath : registeredPaths) {
        if (registerPath.getPattern().matcher(decodedPath).lookingAt()) {
            int split = registerPath.getPath().split(URL_PATH_SEPARATOR).length;
            if (split > pieces) {
                pieces = split;
                bestPath = registerPath;
            }
        }
    }
    return bestPath;
}
Also used : Path(io.gravitee.gateway.handlers.api.path.Path) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Path (io.gravitee.gateway.handlers.api.path.Path)2 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)1 Request (io.gravitee.gateway.api.Request)1 Response (io.gravitee.gateway.api.Response)1 PathResolver (io.gravitee.gateway.handlers.api.path.PathResolver)1 AbstractPolicyChainResolver (io.gravitee.gateway.policy.AbstractPolicyChainResolver)1 Policy (io.gravitee.gateway.policy.Policy)1 StreamType (io.gravitee.gateway.policy.StreamType)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1