Search in sources :

Example 1 with ContainerResponseFilter

use of jakarta.ws.rs.container.ContainerResponseFilter in project resteasy by resteasy.

the class ServerResponseWriter method executeFilters.

private static void executeFilters(BuiltResponse jaxrsResponse, HttpRequest request, HttpResponse response, ResteasyProviderFactory providerFactory, ResourceMethodInvoker method, Consumer<Throwable> onComplete, RunnableWithIOException continuation) throws IOException {
    ContainerResponseFilter[] responseFilters = null;
    if (method != null) {
        responseFilters = method.getResponseFilters();
    } else {
        responseFilters = providerFactory.getContainerResponseFilterRegistry().postMatch(null, null);
    }
    if (responseFilters != null) {
        ResponseContainerRequestContext requestContext = new ResponseContainerRequestContext(request);
        ContainerResponseContextImpl responseContext = new ContainerResponseContextImpl(request, response, jaxrsResponse, requestContext, responseFilters, onComplete, continuation);
        RESTEasyTracingLogger logger = RESTEasyTracingLogger.getInstance(request);
        final long timestamp = logger.timestamp("RESPONSE_FILTER_SUMMARY");
        // filter calls the continuation
        responseContext.filter();
        logger.logDuration("RESPONSE_FILTER_SUMMARY", timestamp, responseFilters.length);
    } else {
        try {
            continuation.run(onComplete);
        } catch (Throwable t) {
            onComplete.accept(t);
            SynchronousDispatcher.rethrow(t);
        }
    }
}
Also used : ContainerResponseFilter(jakarta.ws.rs.container.ContainerResponseFilter) ResponseContainerRequestContext(org.jboss.resteasy.core.interception.jaxrs.ResponseContainerRequestContext) ContainerResponseContextImpl(org.jboss.resteasy.core.interception.jaxrs.ContainerResponseContextImpl) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger)

Example 2 with ContainerResponseFilter

use of jakarta.ws.rs.container.ContainerResponseFilter in project resteasy by resteasy.

the class ProviderFactoryTest method testRegisterProviderInstancePriorityContainerResponseFilter.

/**
 * @tpTestDetails Regression test for JBEAP-4706
 *                Test whether the priority is supplied to the container response filter registry.
 * @tpSince RESTEasy 3.0.17
 */
@Test
public void testRegisterProviderInstancePriorityContainerResponseFilter() throws Exception {
    ContainerResponseFilter responseFilter = new ContainerResponseFilter() {

        public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
        }
    };
    this.testRegisterProviderInstancePriority(responseFilter, factory.getContainerResponseFilterRegistry());
}
Also used : ContainerResponseFilter(jakarta.ws.rs.container.ContainerResponseFilter) ContainerRequestContext(jakarta.ws.rs.container.ContainerRequestContext) ContainerResponseContext(jakarta.ws.rs.container.ContainerResponseContext) Test(org.junit.Test)

Example 3 with ContainerResponseFilter

use of jakarta.ws.rs.container.ContainerResponseFilter in project resteasy by resteasy.

the class ServerHelper method processProviderInstanceContracts.

protected void processProviderInstanceContracts(Object provider, Map<Class<?>, Integer> contracts, Integer priorityOverride, boolean builtIn, Map<Class<?>, Integer> newContracts) {
    ConstrainedTo constrainedTo = (ConstrainedTo) provider.getClass().getAnnotation(ConstrainedTo.class);
    if (constrainedTo != null && constrainedTo.value() != RuntimeType.SERVER)
        return;
    super.processProviderInstanceContracts(provider, contracts, priorityOverride, builtIn, newContracts);
    if (Utils.isA(provider, ContainerRequestFilter.class, contracts)) {
        int priority = Utils.getPriority(priorityOverride, contracts, ContainerRequestFilter.class, provider.getClass());
        JaxrsInterceptorRegistry<ContainerRequestFilter> registry = getRequestFiltersForWrite();
        registry.registerSingleton((ContainerRequestFilter) provider, priority);
        attachedRequestFilters = false;
        requestFilters = registry;
        newContracts.put(ContainerRequestFilter.class, priority);
    }
    if (Utils.isA(provider, ContainerResponseFilter.class, contracts)) {
        int priority = Utils.getPriority(priorityOverride, contracts, ContainerResponseFilter.class, provider.getClass());
        JaxrsInterceptorRegistry<ContainerResponseFilter> registry = getResponseFiltersForWrite();
        registry.registerSingleton((ContainerResponseFilter) provider, priority);
        attachedResponseFilters = false;
        responseFilters = registry;
        newContracts.put(ContainerResponseFilter.class, priority);
    }
    if (Utils.isA(provider, AsyncResponseProvider.class, contracts)) {
        try {
            addAsyncResponseProvider((AsyncResponseProvider) provider, provider.getClass());
            int priority = Utils.getPriority(priorityOverride, contracts, AsyncResponseProvider.class, provider.getClass());
            newContracts.put(AsyncResponseProvider.class, priority);
        } catch (Exception e) {
            throw new RuntimeException(Messages.MESSAGES.unableToInstantiateAsyncResponseProvider(), e);
        }
    }
    if (Utils.isA(provider, AsyncStreamProvider.class, contracts)) {
        try {
            addAsyncStreamProvider((AsyncStreamProvider) provider, provider.getClass());
            int priority = Utils.getPriority(priorityOverride, contracts, AsyncStreamProvider.class, provider.getClass());
            newContracts.put(AsyncStreamProvider.class, priority);
        } catch (Exception e) {
            throw new RuntimeException(Messages.MESSAGES.unableToInstantiateAsyncStreamProvider(), e);
        }
    }
    if (Utils.isA(provider, ExceptionMapper.class, contracts)) {
        try {
            addExceptionMapper((ExceptionMapper) provider, provider.getClass(), builtIn);
            int priority = Utils.getPriority(priorityOverride, contracts, ExceptionMapper.class, provider.getClass());
            newContracts.put(ExceptionMapper.class, priority);
        } catch (Exception e) {
            throw new RuntimeException(Messages.MESSAGES.unableToInstantiateExceptionMapper(), e);
        }
    }
}
Also used : ContainerResponseFilter(jakarta.ws.rs.container.ContainerResponseFilter) ConstrainedTo(jakarta.ws.rs.ConstrainedTo) ContainerRequestFilter(jakarta.ws.rs.container.ContainerRequestFilter)

Example 4 with ContainerResponseFilter

use of jakarta.ws.rs.container.ContainerResponseFilter in project tomee by apache.

the class JAXRSUtils method runContainerResponseFilters.

public static void runContainerResponseFilters(ServerProviderFactory pf, ResponseImpl r, Message m, OperationResourceInfo ori, Method invoked) throws IOException, Throwable {
    List<ProviderInfo<ContainerResponseFilter>> containerFilters = pf.getContainerResponseFilters(ori == null ? null : ori.getNameBindings());
    if (!containerFilters.isEmpty()) {
        ContainerRequestContext requestContext = new ContainerRequestContextImpl(m.getExchange().getInMessage(), false, true);
        ContainerResponseContext responseContext = new ContainerResponseContextImpl(r, m, ori == null ? null : ori.getClassResourceInfo().getServiceClass(), invoked);
        for (ProviderInfo<ContainerResponseFilter> filter : containerFilters) {
            InjectionUtils.injectContexts(filter.getProvider(), filter, m);
            filter.getProvider().filter(requestContext, responseContext);
        }
    }
}
Also used : ContainerResponseFilter(jakarta.ws.rs.container.ContainerResponseFilter) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) ContainerRequestContext(jakarta.ws.rs.container.ContainerRequestContext) ContainerRequestContextImpl(org.apache.cxf.jaxrs.impl.ContainerRequestContextImpl) ContainerResponseContext(jakarta.ws.rs.container.ContainerResponseContext) ContainerResponseContextImpl(org.apache.cxf.jaxrs.impl.ContainerResponseContextImpl)

Example 5 with ContainerResponseFilter

use of jakarta.ws.rs.container.ContainerResponseFilter in project minijax by minijax.

the class MinijaxApplication method runResponseFilters.

private void runResponseFilters(final MinijaxRequestContext context, final Response response) throws IOException {
    final ContainerResponseContext responseContext = (ContainerResponseContext) response;
    for (final Class<? extends ContainerResponseFilter> filterClass : responseFilters) {
        final ContainerResponseFilter filter = context.getResource(filterClass);
        filter.filter(context, responseContext);
    }
}
Also used : ContainerResponseFilter(jakarta.ws.rs.container.ContainerResponseFilter) ContainerResponseContext(jakarta.ws.rs.container.ContainerResponseContext)

Aggregations

ContainerResponseFilter (jakarta.ws.rs.container.ContainerResponseFilter)6 ContainerResponseContext (jakarta.ws.rs.container.ContainerResponseContext)3 ContainerRequestContext (jakarta.ws.rs.container.ContainerRequestContext)2 RESTEasyTracingLogger (org.jboss.resteasy.tracing.RESTEasyTracingLogger)2 ConstrainedTo (jakarta.ws.rs.ConstrainedTo)1 ContainerRequestFilter (jakarta.ws.rs.container.ContainerRequestFilter)1 IOException (java.io.IOException)1 ContainerRequestContextImpl (org.apache.cxf.jaxrs.impl.ContainerRequestContextImpl)1 ContainerResponseContextImpl (org.apache.cxf.jaxrs.impl.ContainerResponseContextImpl)1 ProviderInfo (org.apache.cxf.jaxrs.model.ProviderInfo)1 RunnableWithIOException (org.jboss.resteasy.core.ServerResponseWriter.RunnableWithIOException)1 ContainerResponseContextImpl (org.jboss.resteasy.core.interception.jaxrs.ContainerResponseContextImpl)1 ResponseContainerRequestContext (org.jboss.resteasy.core.interception.jaxrs.ResponseContainerRequestContext)1 ApplicationException (org.jboss.resteasy.spi.ApplicationException)1 Test (org.junit.Test)1