Search in sources :

Example 6 with ResourceInvoker

use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.

the class SynchronousDispatcher method getInvoker.

public ResourceInvoker getInvoker(HttpRequest request) throws Failure {
    LogMessages.LOGGER.pathInfo(request.getUri().getPath());
    if (!request.isInitial()) {
        throw new InternalServerErrorException(Messages.MESSAGES.isNotInitialRequest(request.getUri().getPath()));
    }
    ResourceInvoker invoker = registry.getResourceInvoker(request);
    if (invoker == null) {
        throw new NotFoundException(Messages.MESSAGES.unableToFindJaxRsResource(request.getUri().getPath()));
    }
    RESTEasyTracingLogger logger = RESTEasyTracingLogger.getInstance(request);
    logger.log("MATCH_RESOURCE", invoker);
    logger.log("MATCH_RESOURCE_METHOD", invoker.getMethod());
    return invoker;
}
Also used : InternalServerErrorException(org.jboss.resteasy.spi.InternalServerErrorException) NotFoundException(jakarta.ws.rs.NotFoundException) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker)

Example 7 with ResourceInvoker

use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.

the class AbstractPatchMethodFilter method getMethodInvoker.

protected ResourceMethodInvoker getMethodInvoker(ContainerRequestContext requestContext) {
    HttpRequest request = ResteasyContext.getContextData(HttpRequest.class);
    Registry methodRegistry = ResteasyContext.getContextData(Registry.class);
    ResourceInvoker resourceInovker = null;
    try {
        resourceInovker = methodRegistry.getResourceInvoker(request);
    } catch (Exception e) {
        LogMessages.LOGGER.patchTargetMethodNotFound(requestContext.getUriInfo().getRequestUri().toString());
        throw new ProcessingException("GET method returns the patch/merge json object target not found");
    }
    return (ResourceMethodInvoker) resourceInovker;
}
Also used : HttpRequest(org.jboss.resteasy.spi.HttpRequest) ResourceMethodInvoker(org.jboss.resteasy.core.ResourceMethodInvoker) Registry(org.jboss.resteasy.spi.Registry) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) WebApplicationException(jakarta.ws.rs.WebApplicationException) ProcessingException(jakarta.ws.rs.ProcessingException) NotFoundException(jakarta.ws.rs.NotFoundException) BadRequestException(jakarta.ws.rs.BadRequestException) IOException(java.io.IOException) ApplicationException(org.jboss.resteasy.spi.ApplicationException) ProcessingException(jakarta.ws.rs.ProcessingException)

Example 8 with ResourceInvoker

use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.

the class RootNode method removeBinding.

public void removeBinding(String path, Method method) {
    List<MethodExpression> expressions = bounded.get(path);
    if (expressions == null)
        return;
    for (MethodExpression expression : expressions) {
        ResourceInvoker invoker = expression.getInvoker();
        if (invoker.getMethod().equals(method)) {
            expression.parent.targets.remove(expression);
            expressions.remove(expression);
            if (expressions.size() == 0)
                bounded.remove(path);
            size--;
            if (invoker instanceof ResourceMethodInvoker) {
                ((ResourceMethodInvoker) invoker).cleanup();
            }
            return;
        }
    }
}
Also used : ResourceMethodInvoker(org.jboss.resteasy.core.ResourceMethodInvoker) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker)

Example 9 with ResourceInvoker

use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.

the class SegmentNode method match.

public MatchCache match(HttpRequest request, int start) {
    String path = ((ResteasyUriInfo) request.getUri()).getMatchingPath();
    RESTEasyTracingLogger logger = RESTEasyTracingLogger.getInstance(request);
    logger.log("MATCH_PATH_FIND", ((ResteasyUriInfo) request.getUri()).getMatchingPath());
    if (start < path.length() && path.charAt(start) == '/')
        start++;
    List<MethodExpression> potentials = new ArrayList<MethodExpression>();
    potentials(path, start, potentials);
    Collections.sort(potentials);
    boolean expressionMatched = false;
    List<Match> matches = new ArrayList<Match>();
    for (MethodExpression expression : potentials) {
        // We ignore locators if the first match was a resource method as per the spec Section 3, Step 2(h)
        if (expressionMatched && expression.isLocator()) {
            logger.log("MATCH_PATH_SKIPPED", expression.getRegex());
            continue;
        }
        Pattern pattern = expression.getPattern();
        Matcher matcher = pattern.matcher(path);
        matcher.region(start, path.length());
        if (matcher.matches()) {
            expressionMatched = true;
            ResourceInvoker invoker = expression.getInvoker();
            if (invoker instanceof ResourceLocatorInvoker) {
                MatchCache ctx = new MatchCache();
                ctx.invoker = invoker;
                ResteasyUriInfo uriInfo = (ResteasyUriInfo) request.getUri();
                int length = matcher.start(expression.getNumGroups() + 1);
                if (length == -1) {
                    uriInfo.pushMatchedPath(path);
                    uriInfo.pushMatchedURI(path);
                } else {
                    // must find the end of the matched pattern
                    // and get the substring from 1st char thru end
                    // of matched chars
                    Pattern p = expression.getPattern();
                    Matcher m = p.matcher(path);
                    m.region(start, path.length());
                    String substring = path;
                    while (m.find()) {
                        String endText = m.group(m.groupCount());
                        if (endText != null && !endText.isEmpty()) {
                            int indx = path.indexOf(endText, length);
                            if (indx > -1) {
                                substring = path.substring(0, indx);
                            }
                        }
                    }
                    uriInfo.pushMatchedPath(substring);
                    uriInfo.pushMatchedURI(substring);
                }
                expression.populatePathParams(request, matcher, path);
                logger.log("MATCH_LOCATOR", invoker.getMethod());
                return ctx;
            } else {
                matches.add(new Match(expression, matcher));
            }
        } else {
            logger.log("MATCH_PATH_NOT_MATCHED", expression.getRegex());
        }
    }
    if (matches.size() == 0) {
        throw new NotFoundException(Messages.MESSAGES.couldNotFindResourceForFullPath(request.getUri().getRequestUri()));
    }
    MatchCache match = match(matches, request.getHttpMethod(), request);
    match.match.expression.populatePathParams(request, match.match.matcher, path);
    logger.log("MATCH_PATH_SELECTED", match.match.expression.getRegex());
    return match;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ResourceLocatorInvoker(org.jboss.resteasy.core.ResourceLocatorInvoker) ResteasyUriInfo(org.jboss.resteasy.specimpl.ResteasyUriInfo) ArrayList(java.util.ArrayList) NotFoundException(jakarta.ws.rs.NotFoundException) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger)

Example 10 with ResourceInvoker

use of org.jboss.resteasy.spi.ResourceInvoker in project resteasy by resteasy.

the class ResourceMethodRegistry method checkAmbiguousUri.

/**
 * Resteasy 2.x does not properly handle sub-resource and sub-resource locator
 * endpoints with the same uri.  Resteasy 3.x does handle this properly.  In
 * assisting customers identify this issue during an upgrade from Resteasy 2 to 3
 * provides a waring when the situation is found.
 */
public void checkAmbiguousUri() {
    for (Map.Entry<String, List<ResourceInvoker>> entry : this.root.getBounded().entrySet()) {
        List<ResourceInvoker> values = entry.getValue();
        if (values.size() > 1) {
            int locatorCnt = 0;
            int methodCnt = 0;
            for (ResourceInvoker rInvoker : values) {
                if (rInvoker instanceof ResourceLocatorInvoker) {
                    locatorCnt++;
                } else if (rInvoker instanceof ResourceMethodInvoker) {
                    methodCnt++;
                }
            }
            if (methodCnt > 0 && locatorCnt > 0) {
                StringBuilder sb = new StringBuilder();
                int cnt = values.size();
                for (int i = 0; i < cnt; i++) {
                    ResourceInvoker exp = values.get(i);
                    sb.append(exp.getMethod().getDeclaringClass().getName()).append(".").append(exp.getMethod().getName());
                    if (i < cnt - 1) {
                        sb.append(", ");
                    }
                }
                LogMessages.LOGGER.uriAmbiguity(entry.getKey(), sb.toString());
            }
        }
    }
}
Also used : List(java.util.List) Map(java.util.Map) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker)

Aggregations

ResourceInvoker (org.jboss.resteasy.spi.ResourceInvoker)15 NotFoundException (jakarta.ws.rs.NotFoundException)7 List (java.util.List)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ResourceMethodInvoker (org.jboss.resteasy.core.ResourceMethodInvoker)5 InternalServerErrorException (org.jboss.resteasy.spi.InternalServerErrorException)5 Registry (org.jboss.resteasy.spi.Registry)5 RESTEasyTracingLogger (org.jboss.resteasy.tracing.RESTEasyTracingLogger)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 HttpRequest (org.jboss.resteasy.spi.HttpRequest)4 ContainerRequestFilter (jakarta.ws.rs.container.ContainerRequestFilter)3 ResourceContext (jakarta.ws.rs.container.ResourceContext)3 HttpHeaders (jakarta.ws.rs.core.HttpHeaders)3 Request (jakarta.ws.rs.core.Request)3 Response (jakarta.ws.rs.core.Response)3 UriInfo (jakarta.ws.rs.core.UriInfo)3 Providers (jakarta.ws.rs.ext.Providers)3 Method (java.lang.reflect.Method)3