<< Back to previous view

[JERSEY-1798] JerseyServletContainerInitializer behavior violates JAX-RS 1.1 Spec Created: 17/Mar/13  Updated: 06/Nov/13  Resolved: 06/Nov/13

Status: Resolved
Project: jersey
Component/s: core
Affects Version/s: 1.17
Fix Version/s: 1.18

Type: Bug Priority: Critical
Reporter: chasetec Assignee: Libor Kramolis
Resolution: Fixed Votes: 0
Remaining Estimate: 0 minutes
Time Spent: 6 hours, 5 minutes
Original Estimate: 18 hours
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   

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.



 Comments   
Comment by Libor Kramolis [ 04/Nov/13 10:44 AM ]

Have you tried WebLogic 12.1.2 or newer? I guess it is already fixed there.

Comment by Libor Kramolis [ 06/Nov/13 06:12 PM ]

This is already fixed in WebLogic 12.1.2 or newer.

Generated at Wed Apr 23 20:21:59 UTC 2014 using JIRA 4.0.2#472.