Hi,

it might be that a JAX-RS runtime does not introspect the parent classes yet, 
as far as the injection of contexts is concerned.
The workaround is to add a method to the very top (concrete) subclass :

@Context
public void setServletContext(ServletContext jaxrsThreadLocalContext) {
   super.setJaxrsServletContext(jaxrsThreadLocalContext);
}

In meantime, I will work on ensuring contexts can be injected into super class 
fields directly...
Cheers, Sergey



----- Original Message ----- From: "Tom" <[email protected]>
To: <[email protected]>
Sent: Tuesday, May 12, 2009 9:33 AM
Subject: ServletContext in an inherited class


I have copied the code from the CXF manual to get access to the ServletContext of either the SOAP or REST call and it works ok. However, I naturally have more that one Service to implement, so I wanted to move this code to an abstract parent class. When the code is there, only the SOAP resource is injected, the REST variable is NULL.

Is there any reason why REST does not work in an inherited class?


   // Get the ServletContext for SOAP and REST
@javax.annotation.Resource private javax.xml.ws.WebServiceContext iSoapWebServiceContext; @javax.ws.rs.core.Context private javax.servlet.ServletContext iServletContext; private ServletContext getServletContext()
   throws javax.ws.rs.WebApplicationException
   {
       if (iSoapWebServiceContext != null)
       {
           // soap invocation
return (ServletContext)iSoapWebServiceContext.getMessageContext().get(javax.xml.ws.handler.MessageContext.SERVLET_CONTEXT);
       }
       else
       {
           // http-only jaxrs one
return iServletContext;//(ServletContext)iRestMessageContext.get(MessageContext.SERVLET_CONTEXT); } }


Reply via email to