title: Get HttpServletRequest in Jax Rs / Appfuse application?
body: <p>I created a basic application shell with AppFuse, and followed the <a href="http://appfuse.org/display/APF/Web+Services#WebServices-rest" rel="noreferrer">AppFuse tutorial</a> to create a a simple RESTful service with Jax-RS.  That works just fine.  A call to <code>http://localhost:8080/services/api/persons</code> returns a collection of Person objects as a Json formatted string with the right data. </p>
  
  <p>I now would like to access the <code>ServletRequest</code> and <code>ServletResponse</code> objects from within a RESTful service exposed by Appfuse (to use another library that requires these objects).    </p>
  
  <p>I <em>think</em> that should be doable by adding an @Context annotation, e.g. following this <a href="https://stackoverflow.com/questions/1814517/get-servletcontext-on-tomcat-from-jax-rs-jersey">StackOverflow post</a> and this <a href="http://www.java.net/node/701269" rel="noreferrer">forum post</a>.</p>
  
  <p>But if I add the @Context tag (see below), it compiles fine but throws an Exception when the server is restarted (attached at bottom). </p>
  
  <p>Here's the declaration of the <code>@WebService</code>:</p>
  
  <pre><code>@WebService
  @Path("/persons")
  public interface PersonManager extends GenericManager&lt;Person, Long&gt; {
      @Path("/")
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      List&lt;Person&gt; read();
      ...
  }
  </code></pre>
  
  <p>And here's the implementation class where I think I would call the <code>@Context</code> annotation:</p>
  
  <pre><code>@Service("personManager") 
  public class PersonManagerImpl extends GenericManagerImpl&lt;Person, Long&gt; implements PersonManager { 
      PersonDao personDao; 
      @Context ServletRequest request; // Exception thrown on launch if this is present 
      @Context ServletContext context;  // Exception thrown on launch of this is present 
      ... 
      } 
  </code></pre>
  
  <p>Hopefully I'm missing something simple, either something to include to make it work, or to realize that getting the ServletRequest isn't supposed to be possible because....  Any clues would be welcome.</p>
  
  <p>Am running this on Tomcat in IntelliJ.</p>
  
  <p>===  EXCEPTION STACK TRACE (Truncated) === </p>
  
  <pre><code>Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: 
  PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'serviceBeans' threw exception; nested exception is java.lang.RuntimeException: java.lang.NullPointerException 
          at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102) 
          at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58) 
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358) 
          ... 37 more 
  </code></pre>