6 Replies Latest reply on Jul 22, 2013 9:40 AM by Andy Taylor

    Caused by: java.lang.IllegalStateException: Connection is null

    Ben Gao Novice

      my program is always ok,but some time it will throw javax.jms.JMSException: Failed to create session.

       

      log:

      DEBUG com.cup.chmgm.etl.SyncCommonParameterServiceBean - Sending message to online central MDB...

      2013-07-20 23:34:06,447 [http-0.0.0.0-36100-1] ERROR com.cup.chmgm.etl.SyncCommonParameterServiceBean - sync pub para message send error

      javax.jms.JMSException: Failed to create session

                at org.hornetq.core.client.impl.ClientSessionFactoryImpl.createSessionInternal(ClientSessionFactoryImpl.java:864)

                at org.hornetq.core.client.impl.ClientSessionFactoryImpl.createSession(ClientSessionFactoryImpl.java:279)

                at org.hornetq.jms.client.HornetQConnection.createSessionInternal(HornetQConnection.java:513)

                at org.hornetq.jms.client.HornetQConnection.createQueueSession(HornetQConnection.java:369)

                at com.cup.chmgm.etl.SyncCommonParameterServiceBean.doSync(SyncCommonParameterServiceBean.java:118)

                at sun.reflect.GeneratedMethodAccessor1070.invoke(Unknown Source)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                at java.lang.reflect.Method.invoke(Method.java:597)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)

                at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:72)

                at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:76)

                at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:62)

                at sun.reflect.GeneratedMethodAccessor365.invoke(Unknown Source)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                at java.lang.reflect.Method.invoke(Method.java:597)

                at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)

                at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_1103075712.invoke(InvocationContextInterceptor_z_fillMethod_1103075712.java)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)

                at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_1103075712.invoke(InvocationContextInterceptor_z_setup_1103075712.java)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)

                at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:182)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.core.context.CurrentInvocationContextInterceptor.invoke(CurrentInvocationContextInterceptor.java:47)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.interceptor.EJB3TCCLInterceptor.invoke(EJB3TCCLInterceptor.java:86)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:363)

                at org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:88)

                at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:75)

                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)

                at $Proxy237.invoke(Unknown Source)

                at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:188)

                at $Proxy264.doSync(Unknown Source)

                at com.cup.chmgm.ws.BatchSynchResultNotifyService.notify(BatchSynchResultNotifyService.java:33)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                at java.lang.reflect.Method.invoke(Method.java:597)

                at org.jboss.wsf.container.jboss50.invocation.InvocationHandlerJSE.invoke(InvocationHandlerJSE.java:117)

                at org.jboss.wsf.stack.cxf.AbstractInvoker._invokeInternal(AbstractInvoker.java:154)

                at org.jboss.wsf.stack.cxf.AbstractInvoker.invoke(AbstractInvoker.java:104)

                at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)

                at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)

                at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

                at java.util.concurrent.FutureTask.run(FutureTask.java:138)

                at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)

                at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)

                at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243)

                at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:111)

                at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:99)

                at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:431)

                at org.jboss.wsf.stack.cxf.ServletControllerExt.invoke(ServletControllerExt.java:173)

                at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:61)

                at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:185)

                at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)

                at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:103)

                at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)

                at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

                at com.unionpay.common.authorization.SessionFilter.doFilter(SessionFilter.java:105)

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

                at edu.yale.its.tp.cas.client.filter.CASFilter.doFilter(CASFilter.java:160)

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)

                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

                at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:183)

                at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:95)

                at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)

                at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

                at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

                at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.internalProcess(ActiveRequestResponseCacheValve.java:74)

                at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:47)

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)

                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)

                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:599)

                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:451)

                at java.lang.Thread.run(Thread.java:662)

      Caused by: HornetQException[errorCode=0 message=Failed to create session]

                ... 111 more

      Caused by: java.lang.IllegalStateException: Connection is null

                at org.hornetq.core.client.impl.ClientSessionFactoryImpl.createSessionInternal(ClientSessionFactoryImpl.java:745)

                ... 110 more

       

      my class:

      @Stateless(mappedName = "TestService", name = "TestService")

      @Remote(TestService.class)

      public class TestServiceBean implements TestService{

       

       

      static final String QUEUE_NAME = "/queue/paraQueue";

       

                @PostConstruct

                public void init() {

                          InitialContext ic = null;

                          try {

                                    ic = new InitialContext();

                        QueueConnectionFactory cf =

                              (QueueConnectionFactory) ic.lookup("/ConnectionFactory");

                         

                                    jmsConnection = cf.createQueueConnection();

                          } catch (Exception e) {

                                    log.error("get jms ConnntectionFactory Error");

                          }

                          try {

                                    queue = (Queue) ic.lookup(QUEUE_NAME);

                          } catch (Exception ex) {

                                    log.error("Looking up Activation Queue failed.", ex);

                          }

       

       

                          try {

                                    if (queue == null) {

                                              QueueSession session = jmsConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

                                              queue = session.createQueue(QUEUE_NAME);

                                              ic.bind(QUEUE_NAME, queue);

                                    }

                          } catch (Exception ne) {

                                    log.error("creating activation queue failed", ne);

                          }

                }

                public String doSync(String arg1, String arg2){

                          String result = "1";

                          try {

                                    if(arg1==null || arg1.trim().length()==0){

                                              return result;

                                    }

                                    if(arg2==null || arg2.trim().length()==0){

                                              return result;

                                    }

                                    log.debug("Sending message to online central MDB...");

                                    jmsConnection.start();

       

                                    QueueSession session = jmsConnection.createQueueSession(false, //non transacted

                                                        Session.AUTO_ACKNOWLEDGE);

       

                                    QueueSender sender = session.createSender(queue);

       

                                    ObjectMessage message = session.createObjectMessage();

       

                                    message.setStringProperty(CommonConstants.JMS_TRANS_TYPE, CommonConstants.JMS_EVENT_TYPE_PARAMETER_COMMON);

                                    WTCMessageObject mo = new WTCMessageObject();

                                    mo.setarg2(arg2.trim());

                                    message.setObject(mo);

       

                                    sender.send(message);

       

                                    sender.close();

                                    session.close();

                                    jmsConnection.stop();

       

                                    result = "0";

                          } catch (Exception ex) {

                                    log.error("xxxxxxxxxx", ex);

                                    result = "1";

                          }

                          return result;

                }

       

      }