3 Replies Latest reply on Aug 15, 2012 3:45 PM by wgaulke

    Problem with Seam 3 application and RestEasy - FacesContext is not active

    wgaulke

      Hello,

       

      i am facing a problem which is stressing me, maybe someone can help me out.

       

      I want to add a REST interface to a running Seam 3 Web application. Implementing GET methods was easy until I wanted to use @Inject in the REST Interface, for example:

       

      {code}

      @ApplicationPath("/api")

      public class RestApi extends Application{

      }

       

       

      Path("user")

      public class UserApi {

       

          @Inject

          private PojoBean beant;

       

          @GET

          @Path("/test")

          public String test(){

       

              bean.doSomething();

       

              return "test";

          }

      }

      {code}

       

       

      Without the bean.doSomething() the service works fine, but as soon as I try to use the bean I get the exception:

       

      javax.enterprise.context.ContextNotActiveException: FacesContext is not active

          at org.jboss.seam.faces.environment.FacesContextProducer.getFacesContext(FacesContextProducer.java:53) [seam-faces-3.1.0.Final.jar:3.1.0.Final]

       

       

       

      What I tried:

      • RequestScope to API
      • Adding Faces Servlet to the API path :<url-pattern>/api/*</url-pattern>
      • Adding seam-rest module

       

       

      My configuration

       

      • JBoss AS 7.1.1
      • Seam 3.1 (Faces Module, Solder, Persistence and Security)

       

       

       

      Am I missing something? Any clues are appreciated!

        • 1. Re: Problem with Seam 3 application and RestEasy - FacesContext is not active
          lightguard

          Could you paste your code for PojoBean please, also the full stack trace.

          1 of 1 people found this helpful
          • 2. Re: Problem with Seam 3 application and RestEasy - FacesContext is not active
            wgaulke

            Hello Jason,

             

            your comment opened my eyes, my Pojo code was:

             

            {code}

            @Named

            @ViewScoped

            public class TagList implements Serializable {

               

                @Inject

                private Logger log;

             

                @PersistenceContext

                private EntityManager em;

             

                ... methods ...

             

            }

            {code}

             

            I shared it with a view, now the working code is:

             

            {code}

            @Named

            @RequestScoped

            public class TagList implements Serializable {

               

                @Inject

                private Logger log;

             

                @PersistenceContext

                private EntityManager em;

             

                ... methods ...

             

            }

            {code}

             

             

            I must have been blind or something - obviously Pojos with view Scope cannot be injected in RESTeasy as the scope cannot be assembled during a REST request. I guess I have to refactor some parts

            • 3. Re: Problem with Seam 3 application and RestEasy - FacesContext is not active
              wgaulke

              Actually I am not quite done with the topic.

               

              During further implementation I noticed, that I got the "FacesContext is not active".

               

              I debugged a bit and found out, that the seam-solder exception handling swallows all exceptions but is not able to invoce exception handlers as the faces context is not active -> this again rises the "FacesContext is not active" exception.

               

               

              Has someone any hints for that? How can a spit out the whole stack trace?