5 Replies Latest reply on Oct 12, 2011 10:30 AM by spring liao

    after session timeout throw javax.naming.NamingException: Failed to get context with name comp

    spring liao Newbie

      Hi,
      I am learning Seam 3 by writing some code. The code seems to work fine.
      But after the web session time out(30 mins) will see error in jboss 7 log console.
      The error seems about Seam Persistence module and datasource jndi name.
      And It is strange that now the jboss 7 only support java:XXX or java:jboss/XXX jndi name.
      But the log show it want to lookup comp, really confued me.
      I'm not sure this is my fault or else. Could someone help me ?


      used stuff and other info:


      Seam 3, RichFaces 4, JBoss 7, Eclipse Indigo, JBoss Tools 3.3 M3, Windows XP, Mysql 5


      //pom.xml
      <properties>
              <seam.version>3.0.0.Final</seam.version>
              <richfaces.version>4.0.0.Final</richfaces.version>
      </properties>
      <dependencyManagement>
              <dependencies>
                      <dependency>
                              <groupId>org.jboss.seam</groupId>
                              <artifactId>seam-bom</artifactId>
                              <version>${seam.version}</version>
                              <type>pom</type>
                              <scope>import</scope>
                      </dependency>
                      <dependency>
                              <groupId>org.richfaces</groupId>
                              <artifactId>richfaces-bom</artifactId>
                              <version>${richfaces.version}</version>
                              <scope>import</scope>
                              <type>pom</type>
                      </dependency>
              </dependencies>
      </dependencyManagement>
      <dependencies>
              <dependency>
                      <groupId>org.jboss.seam.solder</groupId>
                      <artifactId>seam-solder-api</artifactId>
              </dependency>
              <dependency>
                      <groupId>org.jboss.seam.solder</groupId>
                      <artifactId>seam-solder-impl</artifactId>
                      <scope>runtime</scope>
              </dependency>
              <dependency>
                      <groupId>org.jboss.seam.persistence</groupId>
                      <artifactId>seam-persistence-api</artifactId>
              </dependency>
              <dependency>
                      <groupId>org.jboss.seam.persistence</groupId>
                      <artifactId>seam-persistence-impl</artifactId>
                      <exclusions>
                              <exclusion>
                                      <artifactId>seam-solder</artifactId>
                                      <groupId>org.jboss.seam.solder</groupId>
                              </exclusion>
                      </exclusions>
              </dependency>
              <dependency>
                      <groupId>org.richfaces.ui</groupId>
                      <artifactId>richfaces-components-api</artifactId>
              </dependency>
              <dependency>
                      <groupId>org.richfaces.ui</groupId>
                      <artifactId>richfaces-components-ui</artifactId>
                      <scope>runtime</scope>
              </dependency>
              <dependency>
                      <groupId>org.richfaces.core</groupId>
                      <artifactId>richfaces-core-api</artifactId>
              </dependency>
              <dependency>
                      <groupId>org.richfaces.core</groupId>
                      <artifactId>richfaces-core-impl</artifactId>
                      <scope>runtime</scope>
              </dependency>
      </dependencies>
      
      //standalone.xml:
      <xa-datasource jndi-name="java:jboss/billing2xa" pool-name="billing2xa_Pool" enabled="true" use-java-context="true" use-ccm="true">
          <xa-datasource-property name="DatabaseName">billing2</xa-datasource-property>
          <xa-datasource-property name="User">root</xa-datasource-property>
          <xa-datasource-property name="ServerName">localhost</xa-datasource-property>
          <xa-datasource-property name="PortNumber">6666</xa-datasource-property>
          <xa-datasource-property name="Password">********</xa-datasource-property>
          <driver>mysql</driver>
          <security>
              <user-name>root</user-name>
              <password>********</password>
          </security>
      </xa-datasource>
      
      //persistence.xml
      <jta-data-source>java:jboss/billing2xa</jta-data-source>
      
      //Seam Managed Persistence Context:
      @ExtensionManaged
      @Produces
      @PersistenceUnit(unitName = "billing")
      @ConversationScoped
      EntityManagerFactory emf;
      
      //xhtml:
      <h:form>
        <h:panelGrid columns="2">
          <rich:extendedDataTable value="#{ratePlanBean.ratePlans}" selectionMode="single" var="ratePlan"
            selection="#{ratePlanBean.activeRatePlanIdx}">
            <rich:column>
              <f:facet name="header"><h:outputText value="Id" /></f:facet>
              <h:outputText value="#{ratePlan.id}" />
            </rich:column>
            <rich:column>
              <f:facet name="header"><h:outputText value="Name" /></f:facet>
              <h:outputText value="#{ratePlan.name}" />
            </rich:column>
            <a4j:ajax event="selectionchange" listener="#{ratePlanBean.refreshSvcs}" execute="@form" render="svc" />
          </rich:extendedDataTable>
          <h:selectManyCheckbox id="svc" value="#{ratePlanBean.checkedSvcs}" layout="pageDirection">
            <f:selectItems value="#{ratePlanBean.svcs}" var="svc" itemLabel="#{svc.id} #{svc.name}" itemValue="#{svc.id}" />
          </h:selectManyCheckbox>
        </h:panelGrid>
        <h:commandButton action="#{ratePlanBean.submit}" value="Submit" />
        <h:commandButton action="#{ratePlanBean.startConversation}" value="Start Conversation" />
        <h:commandButton action="#{ratePlanBean.endConversation}" value="End Conversation" />
      </h:form>
      
      //CDI Bean:
      @Named
      @ConversationScoped
      public class RatePlanBean implements Serializable {
          @Inject private Conversation conversation;
          @Inject Logger log;
          @Inject RatePlanRepository ratePlanRepository;
          @Inject SvcRepository svcRepository;
          @Inject private List<RatePlan> ratePlans;
          @Inject private Collection<Svc> svcs;
          private RatePlan activeRatePlan;
          private Collection<Object> activeRatePlanIdx;
          private Collection<Object> checkedSvcs;
          
          public RatePlanBean() {
              System.out.println("invoking RatePlanBean: conversation=" + conversation);
          }
          @PostConstruct
          public void init() {
              log.info("invoking init: " + conversation.getId() + " - " + conversation.getTimeout());
              log.info("------------------------------------------");
          }
          @PreDestroy
          public void destroy() {
              log.info("invoking destory: " + conversation.getId() + " - " + conversation.getTimeout());
              log.info("------------------------------------------");
          }
          @Produces
          @ConversationScoped
          public List<RatePlan> findRatePlans() {
              log.info("invoking findRatePlans: " + conversation.getId() + " - " + conversation.getTimeout());
              log.info("------------------------------------------");
              return ratePlanRepository.findAll();
          }
          @Produces
          @ConversationScoped
          public Collection<Svc> findSvcs() {
              log.info("invoking findSvcs: " + conversation.getId() + " - " + conversation.getTimeout());
              log.info("------------------------------------------");
              return svcRepository.findZonedSvc();
          }
          public List<RatePlan> getRatePlans() {
              log.info("invoking getRatePlans: " + conversation.getId() + " - " + conversation.getTimeout());
              log.info("------------------------------------------");
              return ratePlans;
          }
          public void setRatePlans(List<RatePlan> ratePlans) {
              log.info("invoking setRatePlans: " + conversation.getId() + " - " + conversation.getTimeout());
              this.ratePlans = ratePlans;
              log.info("------------------------------------------");
          }
          public Collection<Svc> getSvcs() {
              log.info("invoking getSvcs: " + conversation.getId() + " - " + conversation.getTimeout());
              log.info("------------------------------------------");
              return svcs;
          }
          public void setSvcs(Collection<Svc> svcs) {
              log.info("invoking setSvcs: " + conversation.getId() + " - " + conversation.getTimeout());
              this.svcs = svcs;
              log.info("------------------------------------------");
          }
          public Collection<Object> getActiveRatePlanIdx() {
              log.info("invoking getActiveRatePlanIdx: " + conversation.getId() + " - " + conversation.getTimeout());
              if (activeRatePlanIdx != null) {
                  for (Object o : activeRatePlanIdx) {
                      log.info(o.getClass().getCanonicalName() + " : " + o);
                  }
              }
              log.info("------------------------------------------");
              return activeRatePlanIdx;
          }
          public void setActiveRatePlanIdx(Collection<Object> activeRatePlanIdx) {
              log.info("invoking setActiveRatePlanIdx: " + conversation.getId() + " - " + conversation.getTimeout());
              this.activeRatePlanIdx = activeRatePlanIdx;
              if (activeRatePlanIdx != null) {
                  for (Object o : activeRatePlanIdx) {
                      log.info(o.getClass().getCanonicalName() + " : " + o);
                  }
              }
              log.info("------------------------------------------");
          }
          public void refreshSvcs() {
              log.info("invoking refreshSvcs: " + conversation.getId() + " - " + conversation.getTimeout());
              if (activeRatePlanIdx != null) {
                  for (Object o : activeRatePlanIdx) {
                      log.info(o.getClass().getCanonicalName() + " : " + o);
                  }
              }
              activeRatePlan = ratePlans.get((Integer)activeRatePlanIdx.iterator().next());
              checkedSvcs.clear();
              for (SvcCode svcCode : activeRatePlan.getPlanSvcs().keySet()) {
                  checkedSvcs.add(svcCode.toString());
              }
              log.info("current selected rate plan : " + activeRatePlan.getId() + " " + activeRatePlan.getName());
              log.info("------------------------------------------");
          }
          public Collection<Object> getCheckedSvcs() {
              log.info("invoking getCheckedSvcs: " + conversation.getId() + " - " + conversation.getTimeout());
              log.info("------------------------------------------");
              return checkedSvcs;
          }
          public void submit() {
              log.info("invoking submit: " + conversation.getId() + " - " + conversation.getTimeout());
              if (checkedSvcs != null) {
                  for (Object o : checkedSvcs) {
                      log.info(o.getClass().getCanonicalName() + " : " + o);
                  }
              }
              log.info("------------------------------------------");
          }
          public void startConversation() {
              log.info("invoking startConversation start: " + conversation.getId() + " - " + conversation.getTimeout());
              conversation.begin();
              conversation.setTimeout(60000);
              log.info("invoking startConversation end: " + conversation.getId() + " - " + conversation.getTimeout());
              log.info("------------------------------------------");
          }
          public void endConversation() {
              log.info("invoking endConversation start: " + conversation.getId() + " - " + conversation.getTimeout());
              conversation.end();
              log.info("invoking endConversation end: " + conversation.getId() + " - " + conversation.getTimeout());
              log.info("------------------------------------------");
          }
      }
      
      //error log:
      //note the first line log is the last log before session time out
      //and the session time out after 30 mins(from 11:50:40,062 to 12:21:11)
      11:50:40,062 INFO  [com.spring.billing.pricing.RatePlanBean] (http--127.0.0.1-8080-2) ------------------------------------------
      12:21:11,500 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/billing3]] (ContainerBackgroundProcessor[StandardEngine[jboss.web]]) Session event listener threw exception: java.lang.RuntimeException: javax.naming.NamingException: Failed to get context with name comp
              at org.jboss.seam.transaction.DefaultSeamTransaction.getSeamTransaction(DefaultSeamTransaction.java:153) [seam-persistence-impl-3.0.0.Final.jar:]
              at org.jboss.seam.transaction.DefaultSeamTransaction.isActive(DefaultSeamTransaction.java:57) [seam-persistence-impl-3.0.0.Final.jar:]
              at org.jboss.seam.persistence.ManagedPersistenceContextProxyHandler.joinTransaction(ManagedPersistenceContextProxyHandler.java:126) [seam-persistence-impl-3.0.0.Final.jar:]
              at org.jboss.seam.persistence.ManagedPersistenceContextProxyHandler.invoke(ManagedPersistenceContextProxyHandler.java:114) [seam-persistence-impl-3.0.0.Final.jar:]
              at $Proxy62.toString(Unknown Source)    at java.lang.String.valueOf(Unknown Source) [:1.6.0_26]
              at java.lang.StringBuilder.append(Unknown Source) [:1.6.0_26]
              at org.jboss.weld.context.SerializableContextualInstanceImpl.toString(SerializableContextualInstanceImpl.java:67) [weld-core-1.1.2.AS7.jar:2011-07-06 12:26]
              at java.lang.String.valueOf(Unknown Source) [:1.6.0_26]
              at java.lang.StringBuilder.append(Unknown Source) [:1.6.0_26]
              at org.jboss.weld.context.beanstore.AttributeBeanStore.attach(AttributeBeanStore.java:120) [weld-core-1.1.2.AS7.jar:2011-07-06 12:26]
              at org.jboss.weld.context.AbstractConversationContext.destroyConversation(AbstractConversationContext.java:363) [weld-core-1.1.2.AS7.jar:2011-07-06 12:26]
              at org.jboss.weld.context.AbstractConversationContext.destroy(AbstractConversationContext.java:345) [weld-core-1.1.2.AS7.jar:2011-07-06 12:26]
              at org.jboss.weld.context.http.HttpConversationContextImpl.destroy(HttpConversationContextImpl.java:12) [weld-core-1.1.2.AS7.jar:2011-07-06 12:26]
              at org.jboss.weld.context.http.HttpSessionContextImpl.destroy(HttpSessionContextImpl.java:78) [weld-core-1.1.2.AS7.jar:2011-07-06 12:26]
              at org.jboss.weld.servlet.WeldListener.sessionDestroyed(WeldListener.java:97) [weld-core-1.1.2.AS7.jar:2011-07-06 12:26]
              at org.apache.catalina.session.StandardSession.expire(StandardSession.java:693) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
              at org.apache.catalina.session.StandardSession.isValid(StandardSession.java:588) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
              at org.apache.catalina.session.ManagerBase.processExpires(ManagerBase.java:390) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
              at org.apache.catalina.session.ManagerBase.backgroundProcess(ManagerBase.java:375) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
              at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1316) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
              at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
              at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
              at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
              at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
              at java.lang.Thread.run(Unknown Source) [:1.6.0_26]
      Caused by: javax.naming.NamingException: Failed to get context with name comp
              at org.jboss.as.naming.context.NamespaceObjectFactory.getObjectInstance(NamespaceObjectFactory.java:71)
              at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source) [:1.6.0_26]
              at javax.naming.spi.NamingManager.getContext(Unknown Source) [:1.6.0_26]
              at javax.naming.spi.ContinuationContext.getTargetContext(Unknown Source) [:1.6.0_26]
              at javax.naming.spi.NamingManager.getContinuationContext(Unknown Source) [:1.6.0_26]
              at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:175)
              at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
              at javax.naming.InitialContext.lookup(Unknown Source) [:1.6.0_26]
              at org.jboss.seam.transaction.DefaultSeamTransaction.getUserTransaction(DefaultSeamTransaction.java:177) [seam-persistence-impl-3.0.0.Final.jar:]
              at org.jboss.seam.transaction.DefaultSeamTransaction.createUTTransaction(DefaultSeamTransaction.java:169) [seam-persistence-impl-3.0.0.Final.jar:]
              at org.jboss.seam.transaction.DefaultSeamTransaction.getSeamTransaction(DefaultSeamTransaction.java:134) [seam-persistence-impl-3.0.0.Final.jar:]
              ... 25 more
      

        • 1. Re: after session timeout throw javax.naming.NamingException: Failed to get context with name comp
          spring liao Newbie

          from the DefaultSeamTransaction.java the log means lookup java:comp/UserTransaction.
          now I'm checking my jboss 7.

          • 2. Re: after session timeout throw javax.naming.NamingException: Failed to get context with name comp
            spring liao Newbie

            I check my jboss 7 jndi view.
            But can't realize it. Maybe I need to use ejb ?



            [standalone@localhost:9999 /] /subsystem=naming:jndi-view
            {
                "outcome" => "success",
                "result" => {
                    "java: contexts" => {
                        "java:jboss" => {
                            "billing"                            => {"class-name" => "org.jboss.as.naming.context.ModularReference", "value" => "org.jboss.jca.adapters.jdbc.WrapperDataSource@150f4cd"},
                            "jaas"                               => {"class-name" => "org.jboss.as.naming.context.ModularReference", "children" => {"other" => {"class-name" => "org.jboss.as.security.plugins.SecurityDomainContext", "value" => "org.jboss.security.authentication.JBossCachedAuthenticationManager@1ef347f"}}},
                            "TransactionManager"                 => {"class-name" => "org.jboss.as.naming.context.ModularReference", "value" => "com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate@d0ab09"},
                            "billing2xa"                         => {"class-name" => "org.jboss.as.naming.context.ModularReference", "value" => "org.jboss.jca.adapters.jdbc.WrapperDataSource@66959e"},
                            "TransactionSynchronizationRegistry" => {"class-name" => "org.jboss.as.naming.context.ModularReference", "value" => "com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple@17e2943"},
                            "billing2"                           => {"class-name" => "org.jboss.as.naming.context.ModularReference", "value" => "org.jboss.jca.adapters.jdbc.WrapperDataSource@1af9e21"}},
                        "java:global" => undefined},
                    "applications" => {"billing3.war" => {
                        "java:app" => {"AppName" => {
                            "class-name" => "org.jboss.as.naming.context.ModularReference",
                            "value" => "billing3"
                        }},
                        "modules" => {"billing3" => {"java:module" => {
                            "BeanManager" => {
                                "class-name" => "org.jboss.as.naming.context.ModularReference",
                                "value" => "ManagerEnabled alternatives: [] []
                                            Registered contexts: [interface javax.enterprise.context.ConversationScoped, interface javax.inject.Singleton, interface org.jboss.seam.transaction.TransactionScoped, interface javax.enterprise.context.SessionScoped, interface javax.enterprise.context.Dependent, interface javax.enterprise.context.ApplicationScoped, interface javax.enterprise.context.RequestScoped]
                                            Registered beans: 50
                                            Specialized beans: 0
                                            "
                            },
                            "Validator" => {
                                "class-name" => "org.jboss.as.naming.context.ModularReference",
                                "value" => "org.hibernate.validator.engine.ValidatorImpl@666a65"
                            },
                            "UserTransaction" => {
                                "class-name" => "org.jboss.as.naming.context.ModularReference",
                                "value" => "Transaction: unknown"
                            },
                            "ValidatorFactory" => {
                                "class-name" => "org.jboss.as.naming.context.ModularReference",
                                "value" => "org.jboss.as.ee.beanvalidation.LazyValidatorFactory@1777ae2"
                            },
                            "ModuleName" => {
                                "class-name" => "org.jboss.as.naming.context.ModularReference",
                                "value" => "billing3"
                            },
                            "TransactionSynchronizationRegistry" => {
                                "class-name" => "org.jboss.as.naming.context.ModularReference",
                                "value" => "com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple@17e2943"
                            }
                        }}}
                    }}
                }
            }

            • 3. Re: after session timeout throw javax.naming.NamingException: Failed to get context with name comp
              Jason Porter Master

              For AS7 you must use something newer than 3.0.0.Final for transactions, there was a bug in 3.0.0.Final

              • 4. Re: after session timeout throw javax.naming.NamingException: Failed to get context with name comp
                spring liao Newbie

                Hi Jason,


                Thanks for your reply, will post the result after trying the newer than 3.0.0.Final.


                Thanks

                • 5. Re: after session timeout throw javax.naming.NamingException: Failed to get context with name comp
                  spring liao Newbie

                  Hi Jason,




                  I follow your suggestion and upgrade :
                     1.jboss-as-7.0.0.Final              ---> jboss-as-7.0.2.Final
                     2.seam-persistence-impl-3.0.0.final ---> seam-persistence-impl-3.0.1-SNAPSHOT
                  The newer jboss-as has these following jndi names:
                     1.java:jboss/TransactionManager
                     2.java:jboss/UserTransaction
                     3.java:/jboss/TransactionSynchronizationRegistry
                  The newer org.jboss.seam.transaction.TransactionManagerSynchronizations
                  in seam-persistence-impl has added one additional jndi "java:jboss/TransactionManager".
                  
                  My app works now.
                  Your suggestion inspire me very very much !
                  Thanks again !