title: Issue injecting @Context in resource class
body: <p>I'm having difficulties injecting HttpHeaders into my rest service class.</p>
  
  <pre><code>@Path("/account")
  @Produces({ MediaType.APPLICATION_JSON })
  @Consumes({ MediaType.APPLICATION_JSON })
  @Transactional
  @Service
  public class UserServiceImpl implements UserService {
      @Context
      private HttpHeaders headers;
  
      @Override
      @POST @Path("/{username}/")
      public User get(@PathParam(value = "username") String username)
          throws UnknownUserException {
          String requestId = headers.getHeaderString("requestId");
  
          return new User();
      }
  }
  </code></pre>
  
  <p>When I try running the application I get the following exception during the spring initialisation:</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: Can not set javax.ws.rs.core.HttpHeaders field com.acme.service.UserServiceImpl.headers to com.sun.proxy.$Proxy50
          at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
          at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
          at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
          at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:75)
          at java.lang.reflect.Field.set(Field.java:758)
          at org.apache.cxf.jaxrs.utils.InjectionUtils$1.run(InjectionUtils.java:192)
          at java.security.AccessController.doPrivileged(Native Method)
          at org.apache.cxf.jaxrs.utils.InjectionUtils.injectFieldValue(InjectionUtils.java:188)
          at org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxiesAndApplication(InjectionUtils.java:1058)
          at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:405)
          at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:429)
          at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:162)
  </code></pre>
  
  <p>A bit of experimenting shows that I get the same error when trying to inject anything.  I have an exception mapper that has the http headers injected in do problem what so ever, so I created a custom provider to obtain the headers but get the same problem injecting that in.</p>
  
  <p>I'm pretty sure I must be missing something fundamental here.  </p>
  
  <p>I know that I could add what I need out of the headers as params to the method but I can't change the interface.</p>
  
  <p>Adding the context to the operation</p>
  
  <pre><code>    @Override
      @POST @Path("/{username}/")
      public User get(@Context HttpHeaders httpHeaders, @PathParam(value = "username") String username)
  </code></pre>
  
  <p>Gives me the following error.</p>
  
  <pre><code>java.lang.IllegalArgumentException: object is not an instance of declaring class
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:483)
          at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:181)
          at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:97)
  </code></pre>
  
  <p>I've discovered that if I drop the implements interface then the application actually starts, however nothing is actually injected in.</p>