2 Replies Latest reply on Oct 30, 2011 8:55 PM by Diego Coronel

    Cant find BeanManager from JNDI

    Diego Coronel Apprentice

      Hi,


      Im trying to get BeanManager from JSF PhaseListener and i cant find it.


      i tried something like:



      ServletContext context = (ServletContext) FacesContext  
                      .getCurrentInstance().getExternalContext().getContext();
      
                BeanManager manager = (BeanManager) context.getAttribute(BeanManager.class.getName());
      
                if (manager != null)
                     return manager;
                manager = (BeanManager) context
                          .getAttribute(
                                    "org.jboss.weld.environment.servlet.javax.enterprise.inject.spi.BeanManager");
                if (manager != null)
                     return manager;
      
                InitialContext ic = null;
                try {
                     ic = new InitialContext();
                     // Standard JNDI binding
                     return (BeanManager) ic.lookup("java:comp/BeanManager");
                } catch (NameNotFoundException e) {
                     if (ic == null)
                          throw new RuntimeException("No InitialContext");
      
                     // Weld/Tomcat
                     try {
                          return (BeanManager) ic.lookup("java:comp/env/BeanManager");
                     } catch (Exception e1) {
                          // JBoss 5/6 (maybe obsolete in Weld 1.0+)
                          try {
                               return (BeanManager) ic.lookup("java:app/BeanManager");
                          } catch (Exception e2) {
                               throw new RuntimeException("Could not find Bean Manager",
                                         e2);
                          }
                     }
                } catch (Exception e) {
                     throw new RuntimeException("Could not find Bean Manager", e);
                }



      And its always failing for all those ways.


      So, i tried to use SEAM 3.1-beta3




      public void beforePhase(@Observes @Before @RestoreView PhaseEvent event, BeanManager bm) {



      and im getting this message



      14:20:23,183 INFO  [org.jboss.seam.faces.exception.CatchExceptionHandlerFactory] (http--127.0.0.1-8080-1) Catch not available, Catch integration disabled
      14:20:29,113 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/DfpcWeb].[Faces Servlet]] (http--127.0.0.1-8080-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.IllegalStateException: Could not wrap ExternalContext
           at org.jboss.seam.faces.environment.SeamExternalContextFactory.getExternalContext(SeamExternalContextFactory.java:47) [seam-faces.jar:]
           at com.sun.faces.context.FacesContextFactoryImpl.getFacesContext(FacesContextFactoryImpl.java:93) [jsf-impl-2.0.4-b09-jbossorg-4.jar:2.0.4-b09-jbossorg-4]
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:302) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:1.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:734) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:543) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:479) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:407) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:528) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:454) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at java.lang.Thread.run(Thread.java:619) [:1.6.0_16]
      Caused by: org.jboss.solder.beanManager.BeanManagerUnavailableException: Failed to locate BeanManager using any of these providers: org.jboss.solder.servlet.beanManager.ServletContextAttributeProvider(20), org.jboss.solder.beanManager.DefaultJndiBeanManagerProvider(11), org.jboss.solder.beanManager.ServletContainerJndiBeanManagerProvider(10)
           at org.jboss.solder.beanManager.BeanManagerLocator.getBeanManager(BeanManagerLocator.java:88) [solder-api.jar:]
           at org.jboss.seam.faces.environment.SeamExternalContextFactory.getExternalContext(SeamExternalContextFactory.java:39) [seam-faces.jar:]
           ... 18 more
      
      14:20:29,114 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host]] (http--127.0.0.1-8080-1) Exception Processing ErrorPage[errorCode=403, location=/home.jsf]: java.lang.IllegalStateException: Could not wrap ExternalContext
           at org.jboss.seam.faces.environment.SeamExternalContextFactory.getExternalContext(SeamExternalContextFactory.java:47) [seam-faces.jar:]
           at com.sun.faces.context.FacesContextFactoryImpl.getFacesContext(FacesContextFactoryImpl.java:93) [jsf-impl-2.0.4-b09-jbossorg-4.jar:2.0.4-b09-jbossorg-4]
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:302) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:1.0.0.Final]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:734) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:543) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:479) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:407) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:528) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:454) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
           at java.lang.Thread.run(Thread.java:619) [:1.6.0_16]
      Caused by: org.jboss.solder.beanManager.BeanManagerUnavailableException: Failed to locate BeanManager using any of these providers: org.jboss.solder.servlet.beanManager.ServletContextAttributeProvider(20), org.jboss.solder.beanManager.DefaultJndiBeanManagerProvider(11), org.jboss.solder.beanManager.ServletContainerJndiBeanManagerProvider(10)
           at org.jboss.solder.beanManager.BeanManagerLocator.getBeanManager(BeanManagerLocator.java:88) [solder-api.jar:]
           at org.jboss.seam.faces.environment.SeamExternalContextFactory.getExternalContext(SeamExternalContextFactory.java:39) [seam-faces.jar:]
           ... 18 more
      
      



      Im using JBoss 7.0.2 and i need this after Sucessfull JAAS authentication, anyone to help me?