You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Kou, Zhi Qiang (JIRA)" <ji...@apache.org> on 2014/04/18 05:55:19 UTC

[jira] [Updated] (CXF-5702) CXF 3.0 implementation issue with JAX-RS

     [ https://issues.apache.org/jira/browse/CXF-5702?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kou, Zhi Qiang updated CXF-5702:
--------------------------------

    Description: 
It seems CXF JAX-RS implementation has something wrong with the relationship between defined servlet-mapping and the value of ApplicationPath annotation.

>From JSR-339 spec, section 2.3.2: If the Application subclass is annotated with @ApplicationPath, implementations are REQUIRED to use the value of this annotation appended with ”/*” to define a mapping for the added server. Otherwise, the application MUST be packaged with a web.xml that specifies a servlet mapping.

Also from ApplicationPath javadoc:
Identifies the application path that serves as the base URI for all resource URIs provided by Path. May only be applied to a subclass of Application. *When published in a Servlet container, the value of the application path may be overridden using a servlet-mapping element in the web.xml.*
https://jsr311.java.net/nonav/javadoc/javax/ws/rs/ApplicationPath.html

>From above information, if both servlet-mapping in web.xml and ApplicationPath has value, only one of them should be used as the base URI, and it should be the value of servlet-mapping in web.xml.

In my application, my web.xml looks like below. There are two servlet defined, each for one jaxrs application. And the servlet-mapping values are defined as "/first/*" and "/second/*".
	<servlet>
		<servlet-name>rest1</servlet-name>
		<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
		<init-param>
			<param-name>javax.ws.rs.Application</param-name>
			<param-value>com.ibm.sample.jaxrs.UserDemoApplication</param-value>
		</init-param>
	</servlet>
	<servlet>
		<servlet-name>rest2</servlet-name>
		<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
		<init-param>
			<param-name>javax.ws.rs.Application</param-name>
			<param-value>com.ibm.sample.jaxrs.GroupDemoApplication</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>rest1</servlet-name>
		<url-pattern>/first/*</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>rest2</servlet-name>
		<url-pattern>/second/*</url-pattern>
	</servlet-mapping>

And in my application classes:

@ApplicationPath("userdemo")
public class UserDemoApplication extends javax.ws.rs.core.Application {

@ApplicationPath("groupdemo")
public class GroupDemoApplication extends javax.ws.rs.core.Application {

So in this case according to spec and javadoc, "/first/*" and "/second/*" should be used as the base URI, but not the "userdemo" and "groupdemo".

But in the real case I can only access the resources via URLs:
http://localhost:9080/SingleParameterCxf/first/userdemo/users/eric
http://localhost:9080/SingleParameterCxf/second/groupdemo/groups/root

======

However if I implement the same application using Jersey RI libs, I can access my resources via URLs:
http://localhost:9080/SingleParameterJersey/first/users/eric
http://localhost:9080/SingleParameterJersey/second/groups/root

My feeling is Jersey RI implementation is correct behavior according to SPEC and JavaDoc. Please let me know if my understanding is correct or not.

Any help is highly appreciated! Thank you!


  was:
It seems CXF JAX-RS implementation has something wrong with the relationship between defined servlet-mapping and the value of ApplicationPath annotation.

>From JSR-339 spec, section 2.3.2: If the Application subclass is annotated with @ApplicationPath, implementations are REQUIRED to use the value of this annotation appended with ”/*” to define a mapping for the added server. Otherwise, the application MUST be packaged with a web.xml that specifies a servlet mapping.

Also from ApplicationPath javadoc:
Identifies the application path that serves as the base URI for all resource URIs provided by Path. May only be applied to a subclass of Application. When published in a Servlet container, the value of the application path may be overridden using a servlet-mapping element in the web.xml.

>From above information, if both servlet-mapping in web.xml and ApplicationPath has value, only one of them should be used as the base URI, and it should be the value of servlet-mapping in web.xml.

In my application, my web.xml looks like below. There are two servlet defined, each for one jaxrs application. And the servlet-mapping values are defined as "/first/*" and "/second/*".
	<servlet>
		<servlet-name>rest1</servlet-name>
		<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
		<init-param>
			<param-name>javax.ws.rs.Application</param-name>
			<param-value>com.ibm.sample.jaxrs.UserDemoApplication</param-value>
		</init-param>
	</servlet>
	<servlet>
		<servlet-name>rest2</servlet-name>
		<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
		<init-param>
			<param-name>javax.ws.rs.Application</param-name>
			<param-value>com.ibm.sample.jaxrs.GroupDemoApplication</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>rest1</servlet-name>
		<url-pattern>/first/*</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>rest2</servlet-name>
		<url-pattern>/second/*</url-pattern>
	</servlet-mapping>

And in my application classes:

@ApplicationPath("userdemo")
public class UserDemoApplication extends javax.ws.rs.core.Application {

@ApplicationPath("groupdemo")
public class GroupDemoApplication extends javax.ws.rs.core.Application {

So in this case according to spec and javadoc, "/first/*" and "/second/*" should be used as the base URI, but not the "userdemo" and "groupdemo".

But in the real case I can only access the resources via URLs:
http://localhost:9080/SingleParameterCxf/first/userdemo/users/eric
http://localhost:9080/SingleParameterCxf/second/groupdemo/groups/root

======

However if I implement the same application using Jersey RI libs, I can access my resources via URLs:
http://localhost:9080/SingleParameterJersey/first/users/eric
http://localhost:9080/SingleParameterJersey/second/groups/root

My feeling is Jersey RI implementation is correct behavior according to SPEC and JavaDoc. Please let me know if my understanding is correct or not.

Any help is highly appreciated! Thank you!



> CXF 3.0 implementation issue with JAX-RS
> ----------------------------------------
>
>                 Key: CXF-5702
>                 URL: https://issues.apache.org/jira/browse/CXF-5702
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.0.0-milestone2
>         Environment: Windows
>            Reporter: Kou, Zhi Qiang
>            Priority: Blocker
>
> It seems CXF JAX-RS implementation has something wrong with the relationship between defined servlet-mapping and the value of ApplicationPath annotation.
> From JSR-339 spec, section 2.3.2: If the Application subclass is annotated with @ApplicationPath, implementations are REQUIRED to use the value of this annotation appended with ”/*” to define a mapping for the added server. Otherwise, the application MUST be packaged with a web.xml that specifies a servlet mapping.
> Also from ApplicationPath javadoc:
> Identifies the application path that serves as the base URI for all resource URIs provided by Path. May only be applied to a subclass of Application. *When published in a Servlet container, the value of the application path may be overridden using a servlet-mapping element in the web.xml.*
> https://jsr311.java.net/nonav/javadoc/javax/ws/rs/ApplicationPath.html
> From above information, if both servlet-mapping in web.xml and ApplicationPath has value, only one of them should be used as the base URI, and it should be the value of servlet-mapping in web.xml.
> In my application, my web.xml looks like below. There are two servlet defined, each for one jaxrs application. And the servlet-mapping values are defined as "/first/*" and "/second/*".
> 	<servlet>
> 		<servlet-name>rest1</servlet-name>
> 		<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
> 		<init-param>
> 			<param-name>javax.ws.rs.Application</param-name>
> 			<param-value>com.ibm.sample.jaxrs.UserDemoApplication</param-value>
> 		</init-param>
> 	</servlet>
> 	<servlet>
> 		<servlet-name>rest2</servlet-name>
> 		<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
> 		<init-param>
> 			<param-name>javax.ws.rs.Application</param-name>
> 			<param-value>com.ibm.sample.jaxrs.GroupDemoApplication</param-value>
> 		</init-param>
> 	</servlet>
> 	<servlet-mapping>
> 		<servlet-name>rest1</servlet-name>
> 		<url-pattern>/first/*</url-pattern>
> 	</servlet-mapping>
> 	<servlet-mapping>
> 		<servlet-name>rest2</servlet-name>
> 		<url-pattern>/second/*</url-pattern>
> 	</servlet-mapping>
> And in my application classes:
> @ApplicationPath("userdemo")
> public class UserDemoApplication extends javax.ws.rs.core.Application {
> @ApplicationPath("groupdemo")
> public class GroupDemoApplication extends javax.ws.rs.core.Application {
> So in this case according to spec and javadoc, "/first/*" and "/second/*" should be used as the base URI, but not the "userdemo" and "groupdemo".
> But in the real case I can only access the resources via URLs:
> http://localhost:9080/SingleParameterCxf/first/userdemo/users/eric
> http://localhost:9080/SingleParameterCxf/second/groupdemo/groups/root
> ======
> However if I implement the same application using Jersey RI libs, I can access my resources via URLs:
> http://localhost:9080/SingleParameterJersey/first/users/eric
> http://localhost:9080/SingleParameterJersey/second/groups/root
> My feeling is Jersey RI implementation is correct behavior according to SPEC and JavaDoc. Please let me know if my understanding is correct or not.
> Any help is highly appreciated! Thank you!



--
This message was sent by Atlassian JIRA
(v6.2#6252)