0 Replies Latest reply on Jun 15, 2012 11:38 AM by sebastián scarano

    CDI cannot retrieve servlet responde using @Context annotation

    sebastián scarano Newbie

      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;

      public class GrupoEndpoint

      private HttpServletResponse response;

      public List<Grupo> listAll()
      final List<Grupo> results = em.createQuery("SELECT x FROM Grupo x").getResultList();
      // here response is null!!!
      .addHeader("Access-Control-Allow-Origin", "*");
      .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 ;-)