I\'ve tried deploying my app to both Tomcat 6 with Metro/Jersey and Glassfish 3.1.2, but accessing the WebServiceContext resource always causes a null pointer exception,
The difference is that the default GlassFish implementation is a JAX-WS SOAP-based web service. For a JAX-RS web service, you should use the following annotation to inject the context.
@Context
private ServletContext sc;
There are other types that you can use @Context annotation to inject, such as UriInfo
, HttpHeaders
. Please see Jersey documentation for details. WebServiceContext
and MessageContext
are JAX-WS objects that have no meaning in the JAX-RS context.