0 Replies Latest reply on Jun 15, 2012 11:38 AM by opensas

    CDI cannot retrieve servlet responde using @Context annotation

    opensas

      I have a jax-rs web service returning json, and I'd like to add cors headers to it.

      so I Have the following class:

      [...]
      import javax.enterprise.context.RequestScoped;
      import javax.servlet.http.HttpServletResponse;
      import javax.ws.rs.Path;
      [...]

      @Stateful
      @Path("/grupo")
      @RequestScoped
      @TransactionAttribute
      public class GrupoEndpoint
      {

        
      @Context
        
      private HttpServletResponse response;

         
      @GET
         
      public List<Grupo> listAll()
         
      {
             
      @SuppressWarnings("unchecked")
             
      final List<Grupo> results = em.createQuery("SELECT x FROM Grupo x").getResultList();
             
      // here response is null!!!
              response
      .addHeader("Access-Control-Allow-Origin", "*");
              response
      .addHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
             
      return results;
         
      }

      But response is always null, is there something I might be missing?

      Ps: I asked the same question on stackoverflow, in case you'd like to improve your SO reputation ;-)