title: Jersey constructor injection with @Context not working
body: <p>Following up on <a href="https://stackoverflow.com/questions/35514658/catch-exception-from-object-afterunmarshal-in-glassfish-4-1">this SO thread</a>, my question is whether I'm doing something fundamentally wrong here:</p>
  
  <p>Using GlassFish 4.1, I'm trying to write a <code>MessageBodyReader</code> that has a constructor like this:</p>
  
  <pre><code>package com.acme;
  
  import javax.ws.rs.core.Context;
  import javax.ws.rs.ext.Provider;
  import javax.ws.rs.ext.Providers;
  import javax.ws.rs.Consumes;
  
  @Provider
  @Consumes( "application/xml" )
  public class MyMessageBodyReader implements MessageBodyReader&lt;Object&gt; {
     public MyMessageBodyReader(@Context Providers ps) {
        // try to do something with ps here
        // e.g. pass to a superclass constructor,
        // as required by the solution in the other thread
     }
  
     [...] // implemented interface methods
  }
  </code></pre>
  
  <p>But whatever I do wrt surrounding configuration, I always get a sequence of these exceptions:</p>
  
  <pre><code>2016-06-07T17:19:28.484+0200|WARN: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
  MultiException stack 1 of 1
  org.jboss.weld.exceptions.CreationException: WELD-001530: Cannot produce an instance of class com.acme.MyMessageBodyReader.
      at org.jboss.weld.injection.producer.NonProducibleInjectionTarget.produce(NonProducibleInjectionTarget.java:55)
      at org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider$CdiFactory$2.getInstance(CdiComponentProvider.java:242)
      at org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider$CdiFactory.provide(CdiComponentProvider.java:189)
      [...]
  </code></pre>
  
  <p>followed by</p>
  
  <pre><code>WARNING: Unknown HK2 failure detected:
  MultiException stack 1 of 2
  org.jboss.weld.exceptions.CreationException: WELD-001530: Cannot produce an instance of class com.acme.MyMessageBodyReader.
      at org.jboss.weld.injection.producer.NonProducibleInjectionTarget.produce(NonProducibleInjectionTarget.java:55)
      at org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider$CdiFactory$2.getInstance(CdiComponentProvider.java:242)
      at org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider$CdiFactory.provide(CdiComponentProvider.java:189)
      [...]
  MultiException stack 2 of 2
  java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
      at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:389)
      at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:461)
      at org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:114)
      [...]
  </code></pre>
  
  <p>I've found several examples of injecting <code>Providers</code> into a constructor, not the least in the subclasses of <code>XmlRootElementJaxbProvider</code> that ship with GlassFish 4.1 - after all, I want to reuse their class hierarchy anyway, as it's done in the linked thread.</p>
  
  <p>Thanks in advance for any advice.</p>