Search in sources :

Example 1 with ResourceInvoker

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

the class ServiceMethodsRegistry method getMethods.

public List<Method> getMethods() {
    List<Method> results = new LinkedList<>();
    for (Map.Entry<String, List<ResourceInvoker>> entry : registry.getBounded().entrySet()) {
        List<ResourceInvoker> invokers = entry.getValue();
        for (ResourceInvoker invoker : invokers) {
            if (invoker instanceof ResourceMethodInvoker) {
                ResourceMethodInvoker resourceMethod = (ResourceMethodInvoker) invoker;
                Method method = resourceMethod.getMethod();
                results.add(method);
            } else {
            // TODO: fix this?
            }
        }
    }
    return results;
}
Also used : ResourceMethodInvoker(org.jboss.resteasy.core.ResourceMethodInvoker) List(java.util.List) LinkedList(java.util.LinkedList) Method(java.lang.reflect.Method) Map(java.util.Map) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) LinkedList(java.util.LinkedList)

Example 2 with ResourceInvoker

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

the class ServiceRegistry method scanRegistry.

private void scanRegistry() throws Exception {
    methods = new ArrayList<MethodMetaData>();
    locators = new ArrayList<ServiceRegistry>();
    for (Entry<String, List<ResourceInvoker>> entry : registry.getBounded().entrySet()) {
        List<ResourceInvoker> invokers = entry.getValue();
        for (ResourceInvoker invoker : invokers) {
            if (invoker instanceof ResourceMethodInvoker) {
                methods.add(new MethodMetaData(this, (ResourceMethodInvoker) invoker));
            } else if (invoker instanceof ResourceLocatorInvoker) {
                ResourceLocatorInvoker locator = (ResourceLocatorInvoker) invoker;
                Method method = locator.getMethod();
                Class<?> locatorType = method.getReturnType();
                Class<?>[] locatorResourceTypes = GetRestful.getSubResourceClasses(locatorType);
                for (Class<?> locatorResourceType : locatorResourceTypes) {
                    if (locatorResourceType == null) {
                        // just logging this
                        if (LogMessages.LOGGER.isEnabled(Level.WARN))
                            LogMessages.LOGGER.warn(Messages.MESSAGES.impossibleToGenerateJsapi(method.getDeclaringClass().getName(), method.getName()));
                        // skip this
                        continue;
                    }
                    ResourceMethodRegistry locatorRegistry = new ResourceMethodRegistry(providerFactory);
                    locatorRegistry.addResourceFactory(null, null, locatorResourceType);
                    locators.add(new ServiceRegistry(this, locatorRegistry, providerFactory, locator));
                }
            }
        }
    }
}
Also used : ResourceLocatorInvoker(org.jboss.resteasy.core.ResourceLocatorInvoker) ResourceMethodRegistry(org.jboss.resteasy.core.ResourceMethodRegistry) Method(java.lang.reflect.Method) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) ResourceMethodInvoker(org.jboss.resteasy.core.ResourceMethodInvoker) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ResourceInvoker

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

the class SegmentTest method testDefaultOptions.

/**
 * @tpTestDetails Check default option for segment
 * @tpSince RESTEasy 3.0.16
 */
@Test
public void testDefaultOptions() throws URISyntaxException {
    ResourceMethodRegistry registry = new ResourceMethodRegistry(ResteasyProviderFactory.getInstance());
    registry.addPerRequestResource(SegmentResource.class);
    try {
        ResourceInvoker invoker = registry.getResourceInvoker(MockHttpRequest.options("/resource/sub"));
    } catch (DefaultOptionsMethodException e) {
    }
    try {
        ResourceInvoker invoker = registry.getResourceInvoker(MockHttpRequest.put("/resource/sub"));
    } catch (NotAllowedException e) {
    }
}
Also used : NotAllowedException(jakarta.ws.rs.NotAllowedException) ResourceMethodRegistry(org.jboss.resteasy.core.ResourceMethodRegistry) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) DefaultOptionsMethodException(org.jboss.resteasy.spi.DefaultOptionsMethodException) Test(org.junit.Test)

Example 4 with ResourceInvoker

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

the class ResteasyWadlServiceRegistry method scanRegistry.

private void scanRegistry() {
    resources = new HashMap<>();
    locators = new ArrayList<>();
    for (Map.Entry<String, List<ResourceInvoker>> entry : registry.getBounded().entrySet()) {
        List<ResourceInvoker> invokers = entry.getValue();
        for (ResourceInvoker invoker : invokers) {
            if (invoker instanceof ResourceMethodInvoker) {
                ResteasyWadlMethodMetaData methodMetaData = new ResteasyWadlMethodMetaData(this, (ResourceMethodInvoker) invoker);
                ResteasyWadlResourceMetaData resourceMetaData = resources.get(methodMetaData.getKlassUri());
                if (resourceMetaData == null) {
                    resourceMetaData = new ResteasyWadlResourceMetaData(methodMetaData.getKlassUri());
                    resources.put(methodMetaData.getKlassUri(), resourceMetaData);
                }
                resourceMetaData.addMethodMetaData(methodMetaData);
            } else if (invoker instanceof ResourceLocator) {
                ResourceLocator locator = (ResourceLocator) invoker;
                Method method = locator.getMethod();
                Class<?> locatorType = method.getReturnType();
                Class<?>[] locatorResourceTypes = GetRestful.getSubResourceClasses(locatorType);
                for (Class<?> locatorResourceType : locatorResourceTypes) {
                    if (locatorResourceType == null) {
                        // FIXME: we could generate an error for the client, which would be more informative than
                        // just logging this
                        // skip this
                        LogMessages.LOGGER.warn(Messages.MESSAGES.impossibleToGenerateWADL(method.getDeclaringClass().getName(), method.getName()));
                        continue;
                    }
                    ResourceMethodRegistry locatorRegistry = new ResourceMethodRegistry(providerFactory);
                    locatorRegistry.addResourceFactory(null, null, locatorResourceType);
                    locators.add(new ResteasyWadlServiceRegistry(this, locatorRegistry, providerFactory, locator));
                }
            }
        }
    }
}
Also used : ResourceMethodRegistry(org.jboss.resteasy.core.ResourceMethodRegistry) Method(java.lang.reflect.Method) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) ResourceMethodInvoker(org.jboss.resteasy.core.ResourceMethodInvoker) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ResourceLocator(org.jboss.resteasy.spi.metadata.ResourceLocator)

Example 5 with ResourceInvoker

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

the class SynchronousDispatcher method invoke.

/**
 * Invoke and write response.
 *
 * @param request http request
 * @param response http response
 * @param invoker resource invoker
 */
public void invoke(HttpRequest request, HttpResponse response, ResourceInvoker invoker) {
    RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(request);
    Response jaxrsResponse = null;
    try {
        request.getAsyncContext().initialRequestStarted();
        jaxrsResponse = invoker.invoke(request, response);
        request.getAsyncContext().initialRequestEnded();
        tracingLogger.log("DISPATCH_RESPONSE", jaxrsResponse);
        if (request.getAsyncContext().isSuspended()) {
            /**
             * Callback by the initial calling thread.  This callback will probably do nothing in an asynchronous environment
             * but will be used to simulate AsynchronousResponse in vanilla Servlet containers that do not support
             * asychronous HTTP.
             */
            request.getAsyncContext().getAsyncResponse().initialRequestThreadFinished();
            // we're handing response asynchronously
            jaxrsResponse = null;
        }
    } catch (CompletionException e) {
        // logger.error("invoke() failed mapping exception", e);
        writeException(request, response, e.getCause(), t -> {
        });
        return;
    } catch (Exception e) {
        // logger.error("invoke() failed mapping exception", e);
        invoker.getMethodStatisticsLogger().incFailureCnt();
        writeException(request, response, e, t -> {
        });
        return;
    }
    if (jaxrsResponse != null) {
        writeResponse(request, response, jaxrsResponse);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) HttpResponse(org.jboss.resteasy.spi.HttpResponse) BuiltResponse(org.jboss.resteasy.specimpl.BuiltResponse) 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) CompletionException(java.util.concurrent.CompletionException) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger) 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)

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