title: Injecting contextual data in Resteasy tests with Netty
body: <p>I'm trying to test a resource with Resteasy using an embedded Netty instance as described in the <a href="http://docs.jboss.org/resteasy/docs/3.0.4.Final/userguide/html/RESTEasy_Embedded_Container.html#d4e1403" rel="nofollow noreferrer">Resteasy Docs</a>. </p>
  
  <p>Injecting path parameters and query parameters works like a charm but then I tried to test a resource that injects <code>HttpServletRequest</code> and <code>HttpServletResponse</code> from the context like this:</p>
  
  <pre><code>@GET
  @Path("/")
  public void example(@Context HttpServletResponse response, 
                      @Context HttpServletRequest request) { ... }
  </code></pre>
  
  <p>Resteasy cannot find <code>HttpServletRequest</code>in the context and throws the following exception:</p>
  
  <pre><code>5105 [r #1] DEB o.j.resteasy.core.SynchronousDispatcher  - PathInfo: /auth
  5201 [r #1] ERR c.s.f.v.s.r.e.ApplicationExceptionMapper - Unhandled application exception: Unable to find contextual data of type: javax.servlet.http.HttpServletRequest
  org.jboss.resteasy.spi.LoggableFailure: Unable to find contextual data of type: javax.servlet.http.HttpServletRequest
  </code></pre>
  
  <p>I tried putting mock versions of request and response in the context as suggested in <a href="https://stackoverflow.com/questions/12136780/resteasy-mock-vs-exception-mapper-vs-context">RESTEasy Mock vs. Exception Mapper vs. Context</a> but it does not work either as the contextual data is a ThreadLocal and Netty spawns a new thread for each request.</p>
  
  <p>Any ideas on how to solve this?</p>