Question

I am trying to create a jersey filter that filters all the server's responses of 500 error.

But I dont know much about filters so I just started some code but I have no idea how to continue...can anybody help me with this issue.

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
}

and my web.xml looks like this

<servlet>
<servlet-name>Authenticator</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
    <param-name>com.sun.jersey.spi.container.ResourceFilters</param-name>
    <param-value>com.query.displayer.Filters</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Authenticator</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
Was it helpful?

Solution

You're mixing 2 versions of Jersey in your application: Implementation of a ContainerRequestFilter from JAX-RS 2.0 (Jersey 2) and descriptor configuration (web.xml) for Jersey 1 (see prefix com.sun.jersey). The following article explains how to register providers in Jersey 2:

It seems that you we're using ResourceFilterFactory in Jersey 1. This concept doesn't exist in Jersey 2 but there is a new concept (directly in JAX-RS 2.0) how to do that:

OTHER TIPS

When you are using Jersey-2 you must use the follow configuration to register your filter into the web.xml

jersey.config.server.provider.classnames

instead of

com.sun.jersey.spi.container.ContainerRequestFilters (jersey-1x)

 <!-- This is the config needed -->
<servlet>    
      //...         
     <init-param>
         <param-name>jersey.config.server.provider.classnames</param-name>
         <param-value>com.your_package_path.yourClassFilter</param-value>
     </init-param>
      //...
</servlet>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top