I've created a ContainerRequestFilter
implementation. I'm facing up with some misunderstanding I don't quite solve.
This is my implementation:
@Provider
@PreMatching
@Secured
public class BearerFilter implements ContainerRequestFilter
{
@Context private HttpServletRequest request;
@Override
public void filter(ContainerRequestContext requestContext) throws IOException
{
//this.request is null here
}
}
In order to register it on my jaxrs application:
@ApplicationPath(value = "cmng")
public class RestApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new HashSet<Class<?>>();
resources.add(AccountEndpoint.class);
//...
return resources;
}
@Override
public Set<Object> getSingletons() {
Set<Object> singletons = new HashSet<Object>();
singletons.add(new BearerFilter()); <<<<< manually created object.
return singletons;
}
}
So, BearerFilter
object is created manually, by code. The problem appears here since dependency injection only works on instances created and managed by the container itself.
So I'm not able to inject objects inside a ContainerRequestFilter
since it's not a created or managed object by container itself.
How could I solve that?
I'm using jaxrs.