Jersey and Websphere 6.1
August 12, 2009 . Posted in tutorial.
If you landed on this page it probably means that you’ve attempted to deploy a Jersey RESTful web service in IBM’s Websphere app server.
First of all: what were you thinking?!?
Secondly: it probably wasn’t your decision and you just need to make it work and move on. That was our case anyway…
So rather than bore you to death with how we ended up debugging the JVM and discovering that a java.lang.TypeNotPresentException is thrown when calling class.isAnnotationPresent from within the cores (com.ibm.oti.reflect.AnnotationHelper.getAnnotation) of the IBM J9 JVM rather than a plain true / false, I will just give you a bullet list of the things that need to happen to keep Websphere happy.
- Get your versions right! Jersey 1.0.3 and Websphere AS 6.1.0.25 (including 6.1.0.25 Fix Pack for Web Services) (Getting here is a blog post in itself and I will not do it here)
- Make sure that the enterprise app that contains your Jersey resources uses “Classes loaded with parent class loader first” and “Single class loader for application” (That is in your application’s “Class loading and update detection” section.)
- In your web xml configure the Jersey servlet to search for resources using ClassNames rather than packages. Basically make sure your web.xml looks similar to what I have below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <servlet> <servlet-name>Jersey Web Application</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name> <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value> </init-param> <init-param> <param-name>com.sun.jersey.config.property.classnames</param-name> <param-value> net.tmro.MyRESTfulResource </param-value> </init-param> <load-on-startup>10</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey Web Application</servlet-name> <url-pattern>/json/*</url-pattern> </servlet-mapping> |
- Okay, some clarification: the reason ClassNamesResourceConfig is used rather than PackagesResourceConfig is that when the packages are browsed for the actual @Path annotated classes an actual jar browsing is done which throws and swallows a nasty SecurityException… I invite you (more like dare you) to try using ClasspathResourceConfig and let me know if it works.
Now go ahead and give this a try… don’t forget to let me know if it worked or failed for you… Good luck!
Cheers….

James Lorenzen on July 22, 2010 - 11:54 am
Thanks for sharing. We have ran into similar problems. We have to go even further and deploy our jersey services on jboss 4.2.1 and websphere 6.1. Fun!
Anyways, I worked around the issue a little differently. See the bug details here for more information. https://jersey.dev.java.net/issues/show_bug.cgi?id=558
Seems like they have fixed this issue inewer versions of jersey.