Reputation: 21902
I am trying to intercept requests in Jersey running inside Glassfish.
I created an implementation of ContainerRequestFilter
package mycustom.api.rest.security;
@Provider
public class SecurityProvider implements ContainerRequestFilter {
@Override
public ContainerRequest filter(ContainerRequest request) {
return request;
}
}
My app is started using a subclass of PackagesResourceConfig
.
When Glassfish starts, Jerseys find my provider:
INFO: Provider classes found:
class mycustom.rest.security.SecurityProvider
But it never hits that filter
method. What am I missing??
Everything else seems to be working fine. I added a couple of ContextResolver
providers to do JSON mapping and they work fine. Requests hit my resources fine, it just never goes through the filter.
Upvotes: 4
Views: 2829
Reputation: 43787
I don't think container filters are loaded in as providers. I think you have to set the response filters property. Strangely PackagesResourceConfig doesn't have a setProperty()
but you could overload getProperty()
and getProperties()
:
public Object getProperty(String propertyName) {
if(propertyName.equals(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS)) {
return new String[] {"mycustom.rest.security.SecurityProvider"};
} else {
return super.getProperty(propertyName);
}
}
public Map<String,Object> getProperties() {
propName = ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS;
Map<String,Object> result = super.getProperties();
result.put(propName,getProperty(propName));
return result;
}
Actually, reading the javadocs more closely, it appears the preferred method is:
myConfig.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
new String [] {"mycustom.rest.security.SecurityProvider"});
Upvotes: 4