WAS v8.5 > Develop applications > Develop web services - RESTful services > Develop JAX-RS web applications

Disable the JAX-RS runtime environment

There are cases where you must disable the Java API for RESTful Web Services (JAX-RS) runtime environment. When disabling the JAX-RS runtime environment, JAX-RS features are not available, including base JAX-RS runtime capabilities, EJB runtime integration, Java Contexts and Dependency Injection (JCDI) runtime integration, and Servlet 3.0 web container integration. By disabling the JAX-RS runtime environment, any JAX-RS related processing of the application, including processing of classes with scanned JAX-RS annotations, EJB metadata, and JCDI bean enablement, is no longer performed. The JAX-RS runtime environment is not used to process requests and responses to and from the web container.

Best practice: Disabling the JAX-RS runtime environment does not disable Servlet 3.0 based annotation scanning for JAX-RS annotations such as javax.ws.rs.Path. To disable annotation scanning, set the metadata-complete attribute. If annotation scanning is disabled, it is disabled for all other components outside of JAX-RS.

The explicit plug points to the IBM JAX-RS runtime environment are the com.ibm.websphere.jaxrs.server.IBMRestServlet servlet class and the com.ibm.websphere.jaxrs.server.IBMRestFilter filter class. If we specify these classes as your servlet-class or servlet-filter in the web module's web.xml file, the IBM JAX-RS runtime environment is used to process requests to that servlet.

To disable the JAX-RS runtime environment from doing so, replace those classes with any other servlet or filter class that can handle expected requests to the servlet, or remove the servlet entirely from web.xml.

Replacing the IBMRestServlet class with another might modify existing behavior in the application. Removing the servlet entirely results in requests not being processed.

Even if not explicitly using the com.ibm.websphere.jaxrs.server.IBMRestServlet or com.ibm.websphere.jaxrs.server.IBMRestFilter classes, the JAX-RS integration runtime environment may still process the application. For example, if web.xml of a web module is Servlet 3.0 based, and appropriate conditions are met according to the JSR-311 specification, the JAX-RS integration runtime environment processes scanned classes with JAX-RS annotations and may inject a servlet that can handle requests to the JAX-RS resources in the application.

To disable this functionality, and other functionality such as EJB and JCDI integration, set the com.ibm.websphere.jaxrs.server.DisableIBMJAXRSEngine custom JVM property on the application server with a value of true.

  1. Remove references to IBMRestServlet and IBMRestFilter from web.xml. The following example illustrates a sample web.xml file from an application that uses the IBM JAX-RS runtime environment:
    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd"
        version="3.0">     <servlet>         <servlet-name>MyRestApplication1</servlet-name>         <servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>         <init-param>             <param-name>javax.ws.rs.Application</param-name>             <param-value>com.ibm.websphere.jaxrs.example.Application1</param-value>         </init-param>         <init-param>             <param-name>requestProcessorAttribute</param-name>             <param-value>MyRestApplication1RequestProcessorAttribute</param-value>         </init-param>         <load-on-startup>1</load-on-startup>     </servlet>     <servlet>         <servlet-name>MyNonJAXRSApplication</servlet-name>         <servlet-class>com.ibm.websphere.example.NonJAXRSServlet</servlet-class>         <load-on-startup>1</load-on-startup>     </servlet>     <filter>         <filter-name>MyRestApplication2</filter-name>         <filter-class>com.ibm.websphere.jaxrs.server.IBMRestFilter</filter-class>         <init-param>             <param-name>javax.ws.rs.Application</param-name>             <param-value>com.ibm.websphere.jaxrs.example.Application2</param-value>         </init-param>         <init-param>             <param-name>requestProcessorAttribute</param-name>             <param-value>MyRestApplication2RequestProcessorAttribute</param-value>         </init-param>     </filter>     <servlet-mapping>         <servlet-name>MyRestApplication1</servlet-name>         <url-pattern>/jaxrsapp1/*</url-pattern>     </servlet-mapping>     <servlet-mapping>         <servlet-name>MyNonJAXRSApplication</servlet-name>         <url-pattern>/nonjaxrsapp/*</url-pattern>     </servlet-mapping>     <filter-mapping>         <filter-name>MyRestApplication2</servlet-name>         <url-pattern>/jaxrsapp2/*</url-pattern>     </filter-mapping> <web-app>

    The following example illustrates how web.xml looks after removing the references to the IBMRestServlet and IBMRestFilter classes:

    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd"
        version="3.0">     <servlet>         <servlet-name>MyNonJAXRSApplication</servlet-name>         <servlet-class>com.ibm.websphere.example.NonJAXRSServlet</servlet-class>         <load-on-startup>1</load-on-startup>     </servlet>     <servlet-mapping>         <servlet-name>MyNonJAXRSApplication</servlet-name>         <url-pattern>/nonjaxrsapp/*</url-pattern>     </servlet-mapping> </web-app>

  2. Set the com.ibm.websphere.jaxrs.server.DisableIBMJAXRSEngine custom JVM property on the application server with a value of true.

  3. Restart the application server for the custom JVM property to take effect.


Results

You have disabled the JAX-RS runtime environment from processing the application.


Reference:

Metadata for module settings


+

Search Tips   |   Advanced Search