Sunday, March 1, 2015

Rest Web Services, Jersey 2.x, and differences from 1.x

While trying to help one of my nephews develop REST services using Jersey 2.x, running on Tomcat 7.0.59, have come across issues with the changes in the package names.  These package change names, coupled with a bug in MOXyJsonProvider as detailed at: http://stackoverflow.com/questions/19114043/jax-ws-rs-using-jersey-returning-collection-map-etc made me waste few hours searching for the solution, and caused me scare supporting and maintaining an existing application which uses REST services implemented using Jersey 1.x implementation.  While many solutions were suggested in the web the two required changes which worked were:

1.  Replacing package names in the deployment descriptor from:
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
      <param-name>com.sun.jersey.config.property.packages

</param-name>
      <param-value>...</param-value>

</init-param>  

with: 
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer

</servlet-class>
 

<init-param>
      <param-name>jersey.config.server.provider.packages</param-name>
      <param-value>...</param-value>

</init-param>

2. Disabling MOXyJson provider with JascksonJson provider:
<init-param>
<param-name>jersey.config.disableMoxyJson.server</param-name>
<param-value>true</param-value>
</init-param>

<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>org.codehaus.jackson.jaxrs;...</param-value>
</init-param>


After making the above changes, deploying the REST services in Tomcat 7.0.59 worked as expected.


No comments:

Post a Comment