use of jakarta.ws.rs.container.ContainerRequestFilter in project resteasy by resteasy.
the class ContextParameterInjectionTest method createProxy.
private Object createProxy() {
ServletContext mockServletContext = mock(ServletContext.class);
when(mockServletContext.getAttribute(ResteasyDeployment.class.getName())).thenReturn(null);
ConfigurationBootstrap configBootstrap = new ListenerBootstrap(mockServletContext);
ResteasyContext.pushContext(ResteasyDeployment.class, configBootstrap.createDeployment());
try {
final Class<ContainerRequestFilter> filterClass = ContainerRequestFilter.class;
final ContainerRequestFilter coolInstance = new CoolFilter();
ResteasyProviderFactory mockFactory = mock(ResteasyProviderFactory.class);
when(mockFactory.getContextData(filterClass, filterClass, null, false)).thenReturn(coolInstance);
ResteasyProviderFactory.setInstance(mockFactory);
ContextParameterInjector cpi = new ContextParameterInjector(null, filterClass, filterClass, null, mockFactory);
return cpi.createProxy();
} finally {
ResteasyContext.removeContextDataLevel();
}
}
use of jakarta.ws.rs.container.ContainerRequestFilter 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.ContainerRequestFilter in project minijax by minijax.
the class MinijaxApplication method runRequestFilters.
private void runRequestFilters(final MinijaxRequestContext context) throws IOException {
for (final Class<? extends ContainerRequestFilter> filterClass : requestFilters) {
final ContainerRequestFilter filter = context.getResource(filterClass);
filter.filter(context);
}
}
use of jakarta.ws.rs.container.ContainerRequestFilter in project tomee by apache.
the class JAXRSUtils method runContainerRequestFilters.
public static boolean runContainerRequestFilters(ServerProviderFactory pf, Message m, boolean preMatch, Set<String> names) throws IOException {
List<ProviderInfo<ContainerRequestFilter>> containerFilters = preMatch ? pf.getPreMatchContainerRequestFilters() : pf.getPostMatchContainerRequestFilters(names);
if (!containerFilters.isEmpty()) {
ContainerRequestContext context = new ContainerRequestContextImpl(m, preMatch, false);
for (ProviderInfo<ContainerRequestFilter> filter : containerFilters) {
InjectionUtils.injectContexts(filter.getProvider(), filter, m);
filter.getProvider().filter(context);
Response response = m.getExchange().get(Response.class);
if (response != null) {
setMessageContentType(m, response);
return true;
}
}
}
return false;
}
use of jakarta.ws.rs.container.ContainerRequestFilter in project resteasy by resteasy.
the class ProviderFactoryTest method testRegisterProviderInstancePriorityContainerRequestFilter.
/**
* @tpTestDetails Regression test for JBEAP-4706
* Test whether the priority is supplied to the container request filter registry.
* @tpSince RESTEasy 3.0.17
*/
@Test
public void testRegisterProviderInstancePriorityContainerRequestFilter() throws Exception {
ContainerRequestFilter requestFilter = new ContainerRequestFilter() {
public void filter(ContainerRequestContext requestContext) {
}
};
this.testRegisterProviderInstancePriority(requestFilter, factory.getContainerRequestFilterRegistry());
}
Aggregations