3 Replies Latest reply on Oct 12, 2006 4:23 PM by Gavin King

    invoke a Seam component outside the context of a web applica

    Nicolas Bielza Newbie

      Hello,

      I' trying to build a standalone Java SE application that would use Seam with the embedded EJB3 container and also embed Jetty as a servlet container.

      I also need to be able to retrieve some configuration information from the SQL database before I can start the servlet container (actually, I want to retrieve a Certificate to start the servlet container with SSL).

      Since managing authentication certificates is at the core of my application, they are defined as EJB / Seam components. So I thought it would be nice if I could retrieve the SSL certificate through the container-managed EntityManager (actually, through an EJB that receives the EntityManager through dependency injection).

      I managed to boot the EJB3 container, and lookup the bean, but when I try to access it I get this exception:

      java.lang.IllegalStateException: Attempted to invoke a Seam component outside the context of a web application

      Obviously, the SeamInterceptor won't let me access the bean before I deploy my web application.

      If I remove ejb-jar.xml from the jar that contains my EJBs, I can access the bean, but once the web application is started, Seam doesn't "see it".

      So my question is: is there a way to get around the SeamInterceptor ? Can I change its policy ? Is there a way to deploy my beans in the EJB3 container, access them and install the SeamInterceptor afterwards ? Am I just doing something plain stupid ?

      Thanks for your advice,
      Nicolas.

        • 1. Re: invoke a Seam component outside the context of a web app
          Gavin King Master

          Unfortunately, the Seam metamodel (the Component objects) are all created by the servlet context listener.

          The EJB3 container has no startup hooks, so I can;t really do that stuff at EJB container startup time.

          But perhaps if you have some funny startup hooks, you could call new initialization().init() from there....

          Might require some changes to Seam code.

          • 2. Re: invoke a Seam component outside the context of a web app
            Nicolas Bielza Newbie

            Thanks for the quick response,

            Actually I'm starting the EJB container using EJB3StandaloneBootstrap.boot(); Then I have a EJB3StandaloneDeployer deploy the EJBs. Seam doesn't start the EJB container, but because my EJB package contains the ejb-jar.xml file, the SeamInterceptor gets installed before Seam is initialized.

            What I'd like to do is to deploy the EJBs in the container without installing the SeamInterceptor, access the EJBs and install the SeamInterceptor just before deploying my webapp (which will initialize Seam). In other words, I'd like to "upgrade" my EJBs to Seam components right before starting Seam.

            What I don't know is: Is there a way to install the SeamInterceptor in the EJB container (or in the JBoss Micro Container) after it has been started and before Seam gets initialized (or maybe it doesn't matter if the SeamInterceptor is installed after Seam initialization) ?

            Thanks,
            Nicolas.

            • 3. Re: invoke a Seam component outside the context of a web app
              Gavin King Master

              I don't see how its really going to work, sorry. I would just do this component that can work w/o an interceptor as a non-seam component if I were you. You can always wrap a Seam component around it if you need.