Search in sources :

Example 1 with PostMatchContainerRequestContext

use of org.jboss.resteasy.core.interception.jaxrs.PostMatchContainerRequestContext in project resteasy by resteasy.

the class SseEventSinkInterceptor method filter.

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    ResourceMethodInvoker rmi = ((PostMatchContainerRequestContext) requestContext).getResourceMethod();
    if (rmi.isAsyncStreamProvider() || rmi.isSse()) {
        Dispatcher dispatcher = ResteasyContext.getContextData(Dispatcher.class);
        ResteasyProviderFactory providerFactory = dispatcher != null ? dispatcher.getProviderFactory() : ResteasyProviderFactory.getInstance();
        SseEventOutputImpl sink = new SseEventOutputImpl(new SseEventProvider(providerFactory), providerFactory);
        ResteasyContext.getContextDataMap().put(SseEventSink.class, sink);
        ResteasyContext.getContextData(PostResourceMethodInvokers.class).addInvokers(new PostResourceMethodInvoker() {

            @Override
            public void invoke() {
                sink.flushResponseToClient();
            }
        });
    }
}
Also used : PostResourceMethodInvoker(org.jboss.resteasy.core.PostResourceMethodInvoker) ResourceMethodInvoker(org.jboss.resteasy.core.ResourceMethodInvoker) PostMatchContainerRequestContext(org.jboss.resteasy.core.interception.jaxrs.PostMatchContainerRequestContext) PostResourceMethodInvoker(org.jboss.resteasy.core.PostResourceMethodInvoker) Dispatcher(org.jboss.resteasy.spi.Dispatcher) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) PostResourceMethodInvokers(org.jboss.resteasy.core.PostResourceMethodInvokers)

Example 2 with PostMatchContainerRequestContext

use of org.jboss.resteasy.core.interception.jaxrs.PostMatchContainerRequestContext in project resteasy by resteasy.

the class ResourceMethodInvoker method invokeOnTarget.

protected BuiltResponse invokeOnTarget(HttpRequest request, HttpResponse response, Object target) {
    final RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(request);
    final long timestamp = tracingLogger.timestamp("METHOD_INVOKE");
    final long msTimeStamp = methodStatisticsLogger.timestamp();
    try {
        // we don't pop so writer interceptors can get at this
        ResteasyContext.pushContext(ResourceInfo.class, resourceInfo);
        ResteasyContext.pushContext(Configuration.class, resourceMethodProviderFactory);
        if (requestFilters != null && requestFilters.length > 0) {
            PostMatchContainerRequestContext requestContext = new PostMatchContainerRequestContext(request, this, requestFilters, () -> invokeOnTargetAfterFilter(request, response, target));
            // let it handle the continuation
            return requestContext.filter();
        } else {
            return invokeOnTargetAfterFilter(request, response, target);
        }
    } finally {
        methodStatisticsLogger.duration(msTimeStamp);
        if (resource instanceof SingletonResource) {
            tracingLogger.logDuration("METHOD_INVOKE", timestamp, ((SingletonResource) resource).traceInfo(), method.getMethod());
        } else {
            tracingLogger.logDuration("METHOD_INVOKE", timestamp, resource, method.getMethod());
        }
    }
}
Also used : PostMatchContainerRequestContext(org.jboss.resteasy.core.interception.jaxrs.PostMatchContainerRequestContext) SingletonResource(org.jboss.resteasy.plugins.server.resourcefactory.SingletonResource) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger)

Aggregations

PostMatchContainerRequestContext (org.jboss.resteasy.core.interception.jaxrs.PostMatchContainerRequestContext)2 PostResourceMethodInvoker (org.jboss.resteasy.core.PostResourceMethodInvoker)1 PostResourceMethodInvokers (org.jboss.resteasy.core.PostResourceMethodInvokers)1 ResourceMethodInvoker (org.jboss.resteasy.core.ResourceMethodInvoker)1 SingletonResource (org.jboss.resteasy.plugins.server.resourcefactory.SingletonResource)1 Dispatcher (org.jboss.resteasy.spi.Dispatcher)1 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)1 RESTEasyTracingLogger (org.jboss.resteasy.tracing.RESTEasyTracingLogger)1