Issue Details (XML | Word | Printable)

Key: JERSEY-1798
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Libor Kramolis
Reporter: chasetec
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
jersey

JerseyServletContainerInitializer behavior violates JAX-RS 1.1 Spec

Created: 17/Mar/13 03:35 AM   Updated: 06/Nov/13 06:14 PM   Resolved: 06/Nov/13 06:12 PM
Component/s: core
Affects Version/s: 1.17
Fix Version/s: 1.18

Time Tracking:
Original Estimate: 18 hours
Original Estimate - 18 hours
Remaining Estimate: 0 minutes
Remaining Estimate - 0 minutes
Time Spent: 6 hours, 5 minutes
Time Spent - 6 hours, 5 minutes Time Not Required

Environment:

Windows, Java 1.7.0_07-b11, WebLogic 12.1.1.1, Jersey 1.17 as preferred application library


Tags:
Participants: chasetec and Libor Kramolis


 Description  « Hide

Given this example:

<servlet>
<servlet-name>bob</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>example.MyApplication</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>bob</servlet-name>
<url-pattern>/v1/*</url-pattern>
</servlet-mapping>

My resources should only be available at /v1/. What happens is they are available at two paths /v1/ and /resources/*. With the above example I see the following in the log:

Mar 16, 2013 10:19:22 PM com.sun.jersey.server.impl.container.servlet.JerseyServletContainerInitializer addServletWithApplication
INFO: Registering the Jersey servlet application, named example.MyApplication, at the servlet mapping, /resources/*, with the Application class of the same name

To prevent the auto registration of a servlet with a url-pattern of /resources/* I have to use a servlet-name that matches the fully-qualified class name of the application subclass like so:

<servlet>
<servlet-name>example.MyApplication</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>example.MyApplication</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>example.MyApplication</servlet-name>
<url-pattern>/v1/*</url-pattern>
</servlet-mapping>

On page 6 of the spec it says: If an Application subclass is present and there is already a servlet defined that has a servlet initialization parameter named javax.ws.rs.Application whose value is the fully qualified name of the Application subclass then no new servlet should be added by the JAX-RS implementation's ContainerInitializer since the application is already being handled by an existing servlet.

It says nothing about the servlet-name also having to match the class name to prevent adding a new servlet. The servlet-name is the class name when a servlet is added by a JAX-RS implementation (as stated in the next paragraph of the spec) but that is separate from how to prevent the addition of the servlet.