[jboss-dev-forums] [JBoss Web Development] - CDI cannot retrieve servlet responde using @Context annotation

sebastián scarano do-not-reply at jboss.com
Fri Jun 15 11:38:20 EDT 2012


sebastián scarano [https://community.jboss.org/people/opensas] created the discussion

"CDI cannot retrieve servlet responde using @Context annotation"

To view the discussion, visit: https://community.jboss.org/message/742035#742035

--------------------------------------------------------------
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 ;-)
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/742035#742035]

Start a new discussion in JBoss Web Development at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2112]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-dev-forums/attachments/20120615/2149204e/attachment.html 


More information about the jboss-dev-forums mailing list