Search in sources :

Example 11 with ResourceInvoker

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

the class SynchronousDispatcher method invoke.

public void invoke(HttpRequest request, HttpResponse response) {
    RESTEasyTracingLogger.initTracingSupport(providerFactory, request);
    RESTEasyTracingLogger.logStart(request);
    try {
        pushContextObjects(request, response);
        preprocess(request, response, () -> {
            ResourceInvoker invoker = null;
            try {
                try {
                    invoker = getInvoker(request);
                } catch (Exception exception) {
                    // logger.error("getInvoker() failed mapping exception", exception);
                    writeException(request, response, exception, t -> {
                    });
                    return;
                }
                invoke(request, response, invoker);
            } finally {
                // we're probably clearing it twice but still required
                clearContextData();
            }
        });
    } finally {
        clearContextData();
    }
}
Also used : Registry(org.jboss.resteasy.spi.Registry) HashMap(java.util.HashMap) ResteasyConfiguration(org.jboss.resteasy.spi.ResteasyConfiguration) ArrayList(java.util.ArrayList) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger) HashSet(java.util.HashSet) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Messages(org.jboss.resteasy.resteasy_jaxrs.i18n.Messages) Response(jakarta.ws.rs.core.Response) RequestImpl(org.jboss.resteasy.specimpl.RequestImpl) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) LogMessages(org.jboss.resteasy.resteasy_jaxrs.i18n.LogMessages) ContainerRequestFilter(jakarta.ws.rs.container.ContainerRequestFilter) Dispatcher(org.jboss.resteasy.spi.Dispatcher) Map(java.util.Map) Cleanable(org.jboss.resteasy.plugins.server.Cleanable) Request(jakarta.ws.rs.core.Request) Cleanables(org.jboss.resteasy.plugins.server.Cleanables) NotFoundException(jakarta.ws.rs.NotFoundException) Iterator(java.util.Iterator) UnhandledException(org.jboss.resteasy.spi.UnhandledException) Set(java.util.Set) HttpRequest(org.jboss.resteasy.spi.HttpRequest) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) UriInfo(jakarta.ws.rs.core.UriInfo) HttpRequestPreprocessor(org.jboss.resteasy.spi.HttpRequestPreprocessor) HttpResponse(org.jboss.resteasy.spi.HttpResponse) Consumer(java.util.function.Consumer) ResteasyAsynchronousContext(org.jboss.resteasy.spi.ResteasyAsynchronousContext) List(java.util.List) BuiltResponse(org.jboss.resteasy.specimpl.BuiltResponse) HttpHeaders(jakarta.ws.rs.core.HttpHeaders) ResourceContext(jakarta.ws.rs.container.ResourceContext) Failure(org.jboss.resteasy.spi.Failure) InternalServerErrorException(org.jboss.resteasy.spi.InternalServerErrorException) Providers(jakarta.ws.rs.ext.Providers) PreMatchContainerRequestContext(org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) NotFoundException(jakarta.ws.rs.NotFoundException) UnhandledException(org.jboss.resteasy.spi.UnhandledException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) InternalServerErrorException(org.jboss.resteasy.spi.InternalServerErrorException)

Example 12 with ResourceInvoker

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

the class SynchronousDispatcher method internalInvocation.

public Response internalInvocation(HttpRequest request, HttpResponse response, Object entity) {
    // be extra careful in the clean up process. Only pop if there was an
    // equivalent push.
    ResteasyContext.addContextDataLevel();
    boolean pushedBody = false;
    try {
        MessageBodyParameterInjector.pushBody(entity);
        pushedBody = true;
        ResourceInvoker invoker = getInvoker(request);
        if (invoker != null) {
            pushContextObjects(request, response);
            return execute(request, response, invoker);
        }
        // if invoker is null
        return null;
    } finally {
        ResteasyContext.removeContextDataLevel();
        if (pushedBody) {
            MessageBodyParameterInjector.popBody();
        }
    }
}
Also used : ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker)

Example 13 with ResourceInvoker

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

the class SynchronousDispatcher method invokePropagateNotFound.

/**
 * Propagate NotFoundException.  This is used for Filters.
 *
 * @param request http request
 * @param response http response
 */
public void invokePropagateNotFound(HttpRequest request, HttpResponse response) throws NotFoundException {
    try {
        pushContextObjects(request, response);
        preprocess(request, response, () -> {
            ResourceInvoker invoker = null;
            try {
                try {
                    invoker = getInvoker(request);
                } catch (Exception failure) {
                    if (failure instanceof NotFoundException) {
                        throw ((NotFoundException) failure);
                    } else {
                        // logger.error("getInvoker() failed mapping exception", failure);
                        writeException(request, response, failure, t -> {
                        });
                        return;
                    }
                }
                invoke(request, response, invoker);
            } finally {
                // we're probably clearing it twice but still required
                clearContextData();
            }
        });
    } finally {
        clearContextData();
    }
}
Also used : Registry(org.jboss.resteasy.spi.Registry) HashMap(java.util.HashMap) ResteasyConfiguration(org.jboss.resteasy.spi.ResteasyConfiguration) ArrayList(java.util.ArrayList) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger) HashSet(java.util.HashSet) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Messages(org.jboss.resteasy.resteasy_jaxrs.i18n.Messages) Response(jakarta.ws.rs.core.Response) RequestImpl(org.jboss.resteasy.specimpl.RequestImpl) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) LogMessages(org.jboss.resteasy.resteasy_jaxrs.i18n.LogMessages) ContainerRequestFilter(jakarta.ws.rs.container.ContainerRequestFilter) Dispatcher(org.jboss.resteasy.spi.Dispatcher) Map(java.util.Map) Cleanable(org.jboss.resteasy.plugins.server.Cleanable) Request(jakarta.ws.rs.core.Request) Cleanables(org.jboss.resteasy.plugins.server.Cleanables) NotFoundException(jakarta.ws.rs.NotFoundException) Iterator(java.util.Iterator) UnhandledException(org.jboss.resteasy.spi.UnhandledException) Set(java.util.Set) HttpRequest(org.jboss.resteasy.spi.HttpRequest) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) UriInfo(jakarta.ws.rs.core.UriInfo) HttpRequestPreprocessor(org.jboss.resteasy.spi.HttpRequestPreprocessor) HttpResponse(org.jboss.resteasy.spi.HttpResponse) Consumer(java.util.function.Consumer) ResteasyAsynchronousContext(org.jboss.resteasy.spi.ResteasyAsynchronousContext) List(java.util.List) BuiltResponse(org.jboss.resteasy.specimpl.BuiltResponse) HttpHeaders(jakarta.ws.rs.core.HttpHeaders) ResourceContext(jakarta.ws.rs.container.ResourceContext) Failure(org.jboss.resteasy.spi.Failure) InternalServerErrorException(org.jboss.resteasy.spi.InternalServerErrorException) Providers(jakarta.ws.rs.ext.Providers) PreMatchContainerRequestContext(org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext) NotFoundException(jakarta.ws.rs.NotFoundException) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) NotFoundException(jakarta.ws.rs.NotFoundException) UnhandledException(org.jboss.resteasy.spi.UnhandledException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) InternalServerErrorException(org.jboss.resteasy.spi.InternalServerErrorException)

Example 14 with ResourceInvoker

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

the class ResourceLocatorInvoker method invokeOnTargetObject.

protected BuiltResponse invokeOnTargetObject(HttpRequest request, HttpResponse response, Object target) {
    if (target == null) {
        NotFoundException notFound = new NotFoundException(Messages.MESSAGES.nullSubresource(request.getUri().getAbsolutePath()));
        throw notFound;
    }
    Class<? extends Object> clazz = target.getClass();
    LocatorRegistry registry = cachedSubresources.get(clazz);
    if (registry == null) {
        if (!GetRestful.isSubResourceClass(clazz)) {
            String msg = Messages.MESSAGES.subresourceHasNoJaxRsAnnotations(clazz.getName());
            throw new InternalServerErrorException(msg);
        }
        registry = new LocatorRegistry(clazz, providerFactory);
        cachedSubresources.putIfAbsent(clazz, registry);
    }
    ResourceInvoker invoker = registry.getResourceInvoker(request);
    if (invoker instanceof ResourceLocatorInvoker) {
        ResourceLocatorInvoker locator = (ResourceLocatorInvoker) invoker;
        final long timeStamp = methodStatisticsLogger.timestamp();
        try {
            return locator.invoke(request, response, target);
        } finally {
            methodStatisticsLogger.duration(timeStamp);
        }
    } else {
        ResourceMethodInvoker method = (ResourceMethodInvoker) invoker;
        return method.invoke(request, response, target);
    }
}
Also used : NotFoundException(jakarta.ws.rs.NotFoundException) InternalServerErrorException(org.jboss.resteasy.spi.InternalServerErrorException) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker)

Example 15 with ResourceInvoker

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

the class RegistryStatsResource method get.

@GET
@Produces({ "application/xml", "application/json" })
public RegistryData get() throws JAXBException {
    ResourceMethodRegistry registry = (ResourceMethodRegistry) ResteasyContext.getContextData(Registry.class);
    RegistryData data = new RegistryData();
    for (String key : registry.getBounded().keySet()) {
        List<ResourceInvoker> invokers = registry.getBounded().get(key);
        RegistryEntry entry = new RegistryEntry();
        data.getEntries().add(entry);
        entry.setUriTemplate(key);
        for (ResourceInvoker invoker : invokers) {
            if (invoker instanceof ResourceMethodInvoker) {
                ResourceMethodInvoker rm = (ResourceMethodInvoker) invoker;
                for (String httpMethod : rm.getHttpMethods()) {
                    ResourceMethodEntry method = null;
                    if (httpMethod.equals("GET"))
                        method = new GetResourceMethod();
                    else if (httpMethod.equals("PUT"))
                        method = new PutResourceMethod();
                    else if (httpMethod.equals("DELETE"))
                        method = new DeleteResourceMethod();
                    else if (httpMethod.equals("POST"))
                        method = new PostResourceMethod();
                    else if (httpMethod.equals("OPTIONS"))
                        method = new OptionsResourceMethod();
                    else if (httpMethod.equals("TRACE"))
                        method = new TraceResourceMethod();
                    else if (httpMethod.equals("HEAD"))
                        method = new HeadResourceMethod();
                    method.setClazz(rm.getResourceClass().getName());
                    method.setMethod(rm.getMethod().getName());
                    AtomicLong stat = rm.getStats().get(httpMethod);
                    if (stat != null)
                        method.setInvocations(stat.longValue());
                    else
                        method.setInvocations(0);
                    if (rm.getProduces() != null) {
                        for (MediaType mediaType : rm.getProduces()) {
                            method.getProduces().add(mediaType.toString());
                        }
                    }
                    if (rm.getConsumes() != null) {
                        for (MediaType mediaType : rm.getConsumes()) {
                            method.getConsumes().add(mediaType.toString());
                        }
                    }
                    entry.getMethods().add(method);
                }
            } else {
                ResourceLocatorInvoker rl = (ResourceLocatorInvoker) invoker;
                SubresourceLocator locator = new SubresourceLocator();
                locator.setClazz(rl.getMethod().getDeclaringClass().getName());
                locator.setMethod(rl.getMethod().getName());
                entry.setLocator(locator);
            }
        }
    }
    return data;
}
Also used : ResourceLocatorInvoker(org.jboss.resteasy.core.ResourceLocatorInvoker) ResourceMethodRegistry(org.jboss.resteasy.core.ResourceMethodRegistry) Registry(org.jboss.resteasy.spi.Registry) ResourceMethodRegistry(org.jboss.resteasy.core.ResourceMethodRegistry) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) ResourceMethodInvoker(org.jboss.resteasy.core.ResourceMethodInvoker) AtomicLong(java.util.concurrent.atomic.AtomicLong) MediaType(jakarta.ws.rs.core.MediaType) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

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