web services - JAX-RS filter not getting called -


i have filter defined in file checksessionfilter.java, this:

@provider @sessionchecker public class checksessionfilter implements containerrequestfilter {      @override     public void filter(containerrequestcontext requestcontext) throws webapplicationexception {         ....     } 

in file, sessionchecker.java, have:

@target({ elementtype.type, elementtype.method }) @retention(value = retentionpolicy.runtime) @namebinding public @interface sessionchecker {} 

my web service defined in services.java as:

@path("services") public class services {      @post     @sessionchecker     @consumes(mediatype.application_json)     @produces(mediatype.application_json)     @path("login")     public response login(@context httpservletrequest request, parameters requestparameters) {         ....     } } 

i deployed web service on weblogic 12.2.1. web service works fine. filter not getting called @ all. wrong?

do need put in web.xml?

thanks in advance.

edited include web.xml:

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">   <display-name>xxxxxxxx</display-name>    <servlet>        <servlet-name>jax-rs application</servlet-name>        <servlet-class>com.sun.jersey.spi.container.servlet.servletcontainer</servlet-class>        <init-param>            <param-name>javax.ws.rs.application</param-name>            <param-value>rest.application.config.applicationconfig</param-value>        </init-param>   </servlet>   <servlet-mapping>       <servlet-name>jax-rs application</servlet-name>       <url-pattern>/*</url-pattern>   </servlet-mapping>  </web-app> 

updated web.xml:

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">     <display-name>xxxxxxxx</display-name>     <servlet>         <servlet-name>jax-rs application</servlet-name>         <servlet-class>org.glassfish.jersey.servlet.servletcontainer</servlet-class>         <init-param>             <param-name>javax.ws.rs.application</param-name>             <param-value>rest.application.config.applicationconfig</param-value>         </init-param>     </servlet>     <servlet-mapping>         <servlet-name>jax-rs application</servlet-name>         <url-pattern>/*</url-pattern>     </servlet-mapping> </web-app> 

edited add application config:

package rest.application.config;  import java.util.set; import javax.ws.rs.core.application; import javax.ws.rs.applicationpath;  @applicationpath("resources") public class applicationconfig extends application {      public set<class<?>> getclasses() {         return getrestclasses();     }      //auto-generated restful web service wizard     private set<class<?>> getrestclasses() {         set<class<?>> resources = new java.util.hashset<class<?>>();         resources.add(services.class);         return resources;         } } 

thanks peeskillet, have found solution, add filter in applicationconfig class, shown in code below. need use org.glassfish.jersey.servlet.servletcontainer servlet container in web.xml, jersey 2.x.

package rest.application.config;  import java.util.set; import javax.ws.rs.core.application; import javax.ws.rs.applicationpath;  @applicationpath("resources") public class applicationconfig extends application {      public set<class<?>> getclasses() {         return getrestclasses();     }      //auto-generated restful web service wizard     private set<class<?>> getrestclasses() {         set<class<?>> resources = new java.util.hashset<class<?>>();                 resources.add(services.class);         resources.add(checksessionfilter.class);         return resources;         } } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -