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);
}
}
}
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());
}
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);
}
}
}
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);
}
}
}
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);
}
}
Aggregations