title: JAX-WS WebServiceContext remains null (Annotation Injection Fails)
body: <p>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, <em>except</em> when I test the app using the autogenerated Glassfish testing portal.</p>
  
  <p>Here is a simple test method I wrote to verify this:</p>
  
  <pre><code>import javax.annotation.Resource;
  import javax.jws.WebService;
  import javax.xml.ws.WebServiceContext;
  import javax.xml.ws.handler.MessageContext;
  import javax.servlet.ServletContext;
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  
  @WebService
  @Path("/test")
  public class Test {
      @Resource
      WebServiceContext wsContext;
  
      @GET
      @Produces("text/plain")
      @Path("/hello")
      public String hello() {
          MessageContext mc = wsContext.getMessageContext();   // NULL POINT HAPPENS HERE!
          ServletContext servletContext = (ServletContext) 
                  mc.get(
                          MessageContext.SERVLET_CONTEXT);
          String s = servletContext.getRealPath("/WEB-INF");
          return "Real Path: " + s;
      }
  }
  </code></pre>
  
  <p>and here is the corresponding web-xml (largely auto-generated by Eclipse):</p>
  
  <pre><code>&lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;WebApp&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;servlet&gt;
      &lt;description&gt;JAX-RS Tools Generated - Do not modify&lt;/description&gt;
      &lt;servlet-name&gt;JAX-RS Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;JAX-RS Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/jaxrs/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>What's most interesting is that when I test the TestService by going to the Glassfish generated URL:</p>
  
  <pre><code>http://localhost:8080/WebApp/TestService?Tester
  </code></pre>
  
  <p>I can test/invoke the "hello" method by submitting the form and get a valid WebServiceContext object that generates the appropriate filepath.  Unfortunately, actually performing an HTTP GET Request like</p>
  
  <pre><code>$curl -H "Accept: text/plain" http://localhost:8080/WebApp/jaxrs/test/hello
  </code></pre>
  
  <p>results in a null pointer stack trace that points to line 22 (the WebServiceContext) in the Test class.</p>
  
  <p>Why does the web service work in the Glassfish test harness, but not from actual HTTP requests?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I was able to confirm that the Web Service works perfectly (WebServiceContext is properly injected) if you utilize the GlassFish default XML SOAP request to the GlassFish default URL like this:</p>
  
  <pre><code>$curl -X POST -d @req.xml http://localhost:8080/ZlotyGlassfish/TestService --header "Content-Type:text/xml" 
  </code></pre>
  
  <p>where the contents of the file "req.xml" are a request matching the WSDL definition:</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:impl="http://impl.rest.webservice.webapp.com/"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;impl:hello/&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p><em>My primary question remains why does this work perfectly through the default GlassFish implementation, but the Endpoints generated by the @GET and @Path notations fail to get injected with the the appropriate WebServiceContext object?</em></p>