Configuring the web.xml file for JAX-RS servlets
The web.xml file contains information about the structure and external dependencies of web components in the module and describes how the components are used at run time. To enable the web container to run Java™ API for RESTful Web Services (JAX-RS) applications, you can configure the web.xml file to point directly to the IBM® JAX-RS servlet. When using servlets, you can define a servlet path in the web.xml file that is appended to the base URL.
About this task
You can configure the web.xml file for your web application to enable the JAX-RS application code. You can specify an IBM specific JAX-RS servlet to use to run your JAX-RS code. The web.xml file provides configuration and deployment information for the web components that comprise a web application. Read about configuring the web.xml file for JAX-RS to learn more about this deployment descriptor file.
When
using servlets, any servlet path that is defined in the web.xml is
appended to the base URL. For example, if a root resource has a @javax.ws.rs.Path
value of myresource
and a servlet path of myservletpath
,
the final URL of the resource is http://<your_hostname>:<your
Web_container_port>/<context_root_of_Web_application>//myservletpath/myresource
.
Procedure
Results
Example
The following example illustrates a WEB-INF/web.xml file that configures a servlet path for a JAX-RS application. The servlet path that is defined in the web.xml file is appended to the base URL.
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4"
xmlns=http://java.sun.com/xml/ns/j2ee
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>RestApplication1</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.rest.sample.app1.MyApplication</param-value>
</init-param>
<init-param>
<param-name>requestProcessorAttribute</param-name>
<param-value>restApplication1ProcessorID</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>OtherRestApplicationServlet</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.rest.other.sample.OtherApplication </param-value>
</init-param>
<init-param>
<param-name>requestProcessorAttribute</param-name>
<param-value>otherRestApplicationID </param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name> RestApplication1</servlet-name>
<url-pattern>/rest/api/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>OtherRestApplicationServlet /servlet-name>
<url-pattern>/other/*</url-pattern>
</servlet-mapping>
</web-app>
What to do next
Assemble the web application.