The ContainerRequestFilter is not being applied when receving request.
This is my fist Stackoverflow question so i do not really know what details to add in my question.
Here is my filter
package tjo.tjaa;
@Provider
class Securityfilter implements ContainerRequestFilter {
private static final String AUTHORIZATION_HEADER="authorization";
private static final String AUTHORIZATION_HEADER_PREFIX="Basic";
private static final String SECURITY_URL="security";
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
//this is where i want to execute code
return;
}
}
And here is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>tjo.tjaa</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
I am assuming there are multiple ways to add filter implementations to the JAX-RS. One way to add custom filters is to add them to the Application class implementation. In your case, you would have an implementation of Application class and provide the custom filter under getClasses API:
public class RestApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
return Sets.newHashSet(
SecurityFilter.class);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.