0 Replies Latest reply on Jul 23, 2007 11:38 AM by Denis Forveille

    How to programatically create a seam component in a filter?

    Denis Forveille Novice

      With seam 1.2.1, is it possible to create a seam component in a servlet filter?
      If so how to do it?
      In web.xml, I declare a filter after all other filters 9seam, jsf, etc...)
      In components.xml:

       <component name="test.utilisateur" auto-create="true" scope="session" class="com.saq.pp.metier.modele.Utilisateur"/>
      

      In the servlet filter class, I have:
       public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
       chain.doFilter(req, resp);
       Utilisateur cx = (Utilisateur) Component.getInstance("test.utilisateur");
       }
      

      This result in the following exception:
      java.lang.IllegalStateException: No application context active
       at org.jboss.seam.Component.forName(Component.java:1577)
       at org.jboss.seam.Component.getInstance(Component.java:1627)
       at org.jboss.seam.Component.getInstance(Component.java:1610)
       at org.jboss.seam.Component.getInstance(Component.java:1604)
       at com.saq.pp.web.filter.FiltreTest.doFilter(FiltreTest.java:70)
       at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
       at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
       at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
       at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:761)
       at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:673)
       at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:498)
       at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:464)
       at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:90)
       at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:744)
       at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1433)
       at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:112)
       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:454)
       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:383)
       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:263)
       at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
       at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
       at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
       at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
       at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
       at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
       at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
       at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
       at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
       at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
      

      I have the same results with Component.getInstanceFromFactory()