I have not tested it, but maybe this will help you.
Filter availability
public class MyFilter implements ContainerRequestFilter { @Context HttpServletRequest webRequest; @Override public void filter(ContainerRequestContext requestContext) throws IOException { final HttpSession session = webRequest.getSession(); ...... } }
You can define your resource configuration class and then register your filter
import org.glassfish.jersey.server.ResourceConfig; import javax.ws.rs.ApplicationPath; @ApplicationPath("/rest") public class MyResourceConfig extends ResourceConfig {
then in the jersey test class
@Override protected Application configure() { return new MyResourceConfig (); }
or in a simpler way
@Override protected Application configure() { return new ResourceConfig(YourResource.class).register(MyFilter.class); }
if you need to set a property for your filter, you can do
@Override protected Application configure() { return new MyResourceConfig ().property("property", "value"); }
or
@Override protected Application configure() { return new ResourceConfig(YourResource.class).register(MyFilter.class).property("property", "value"); }
source share