java.lang.reflect.UndeclaredThrowableException

Spring JIRA | Pavel Chuchma | 10 years ago
  1. 0

    Let's have deployment on JBoss cluster with required JMS failover. It is necesary to create following setup (please correct me if I am wrong): - JMS resources should be mapped in WEB-INF\jboss-web.xml file as "jnp://${jboss.bind.address}:1100/..." - connection factory must be defined as JNDI bean with disabled cache: <bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>java:comp/env/jms/QueueConnectionFactory</value> </property> <property name="cache" value="false"/> <property name="proxyInterface" value="javax.jms.ConnectionFactory"/> </bean> - definition of listener container should use JNDI destination name and resolver <bean id="listenerContainerScheduleTimer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="jmsQueueConnectionFactory"/> <property name="destinationName" value="java:comp/env/jms/scheduleTimerQueue"/> <property name="destinationResolver" ref="jndiDestinationResolver"/> <property name="messageListener" ref="messageListenerSchedulerTime"/> <property name="pubSubDomain" value="false"/> </bean> JMS connection factories and destinations are implemented as HA-Singleton in JBoss 4.0 which means that they are running only on one "master" node in a cluster. These singletons are moved to another node if the "master" node fails. But the movement of these JMS takes a non-zero time when there is no runnig JMS bean and there are no records in cluster JNDI trees about these beans. Lookup of any of these bean during this "off" time throws a NamingException. Spring code does the following: The DefaultMessageListenerContainer waits for incoming messages in the receiveMessage() method. If the destination fails (and closes connection) then: - the listener is immediately notified by an exception - the listener tries to recover a connection to a destination (DefaultMessageListenerContainer.refreshConnectionUntilSuccessful()) - the listener gets an instance of the connection factory and calls createConnection() method on it. (AbstractMessageListenerContainer.createConnection() throws JMSException) But in real, the instance of a connection factory is a proxy because of the bean's "cache" property is set to "false" (see to the config above) - the proxy tries to lookup a real instance of connection factory using a cluster JNDI, but it throws an NamingException because a new instance of JBoss HA-Singleton is not started yet. (as described above) - NamingException is wrapped by java.lang.reflect.UndeclaredThrowableException because AbstractMessageListenerContainer.createConnection() throws only JMSException. - the method DefaultMessageListenerContainer.refreshConnectionUntilSuccessful() catches only JMSException and it doens't caught the unexpected UndeclaredThrowableException. - This exception runs through the whole stack and ends the listening thread. - THE RESULT: listening of JMS messages is terminated forever! Probability of this failure (a JNDI lookup before the HA-Singleton is moved) was 100% in my configuration. (2 JBoss instances with 3 JMS destinations and 2 connection factories running on one machine with 2x Xeon 5160 @ 3GHz, 6GB of RAM) The stack trace of UndeclaredThrowableException: java.lang.reflect.UndeclaredThrowableException at $Proxy103.createConnection(Unknown Source) at org.springframework.jms.listener.AbstractMessageListenerContainer.createConnection(AbstractMessageListenerContainer.java:991) at org.springframework.jms.listener.AbstractMessageListenerContainer.refreshSharedConnection(AbstractMessageListenerContainer.java:457) at org.springframework.jms.listener.DefaultMessageListenerContainer.refreshConnectionUntilSuccessful(DefaultMessageListenerContainer.java:701) at org.springframework.jms.listener.DefaultMessageListenerContainer.recoverAfterListenerSetupFailure(DefaultMessageListenerContainer.java:683) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:881) at org.springframework.core.task.SimpleAsyncTaskExecutor$ConcurrencyThrottlingRunnable.run(SimpleAsyncTaskExecutor.java:203) at java.lang.Thread.run(Thread.java:534) at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1067) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:700) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:716) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) at javax.naming.InitialContext.lookup(InitialContext.java:347) at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:124) at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:86) at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:122) at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:147) at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:91) at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:101) at org.springframework.jndi.JndiObjectTargetSource.getTarget(JndiObjectTargetSource.java:116) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:184) ... 9 more Caused by: javax.naming.NameNotFoundException: ConnectionFactory not bound at org.jnp.server.NamingServer.getBinding(NamingServer.java:529) at org.jnp.server.NamingServer.getBinding(NamingServer.java:537) at org.jnp.server.NamingServer.getObject(NamingServer.java:543) at org.jnp.server.NamingServer.lookup(NamingServer.java:296) at org.jboss.ha.jndi.TreeHead.lookupLocally(TreeHead.java:296) at org.jboss.ha.jndi.TreeHead.lookup(TreeHead.java:215) at org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:155) at sun.reflect.GeneratedMethodAccessor141.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.jboss.ha.framework.interfaces.HARMIClient.invoke(HARMIClient.java:258) at $Proxy102.lookup(Unknown Source) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) at javax.naming.InitialContext.lookup(InitialContext.java:347) at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1061) ... 21 more Proposed solution: Add the following catch block to the method DefaultMessageListenerContainer.refreshConnectionUntilSuccessful() catch (UndeclaredThrowableException ex) { if (ex.getUndeclaredThrowable() instanceof NamingException) { if (logger.isInfoEnabled()) { logger.info("Could not refresh...", ex); } } else { throw ex; } } I have tested this fix in an overridden class and it works fine.

    Spring JIRA | 10 years ago | Pavel Chuchma
    java.lang.reflect.UndeclaredThrowableException
  2. 0

    Let's have deployment on JBoss cluster with required JMS failover. It is necesary to create following setup (please correct me if I am wrong): - JMS resources should be mapped in WEB-INF\jboss-web.xml file as "jnp://${jboss.bind.address}:1100/..." - connection factory must be defined as JNDI bean with disabled cache: <bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>java:comp/env/jms/QueueConnectionFactory</value> </property> <property name="cache" value="false"/> <property name="proxyInterface" value="javax.jms.ConnectionFactory"/> </bean> - definition of listener container should use JNDI destination name and resolver <bean id="listenerContainerScheduleTimer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="jmsQueueConnectionFactory"/> <property name="destinationName" value="java:comp/env/jms/scheduleTimerQueue"/> <property name="destinationResolver" ref="jndiDestinationResolver"/> <property name="messageListener" ref="messageListenerSchedulerTime"/> <property name="pubSubDomain" value="false"/> </bean> JMS connection factories and destinations are implemented as HA-Singleton in JBoss 4.0 which means that they are running only on one "master" node in a cluster. These singletons are moved to another node if the "master" node fails. But the movement of these JMS takes a non-zero time when there is no runnig JMS bean and there are no records in cluster JNDI trees about these beans. Lookup of any of these bean during this "off" time throws a NamingException. Spring code does the following: The DefaultMessageListenerContainer waits for incoming messages in the receiveMessage() method. If the destination fails (and closes connection) then: - the listener is immediately notified by an exception - the listener tries to recover a connection to a destination (DefaultMessageListenerContainer.refreshConnectionUntilSuccessful()) - the listener gets an instance of the connection factory and calls createConnection() method on it. (AbstractMessageListenerContainer.createConnection() throws JMSException) But in real, the instance of a connection factory is a proxy because of the bean's "cache" property is set to "false" (see to the config above) - the proxy tries to lookup a real instance of connection factory using a cluster JNDI, but it throws an NamingException because a new instance of JBoss HA-Singleton is not started yet. (as described above) - NamingException is wrapped by java.lang.reflect.UndeclaredThrowableException because AbstractMessageListenerContainer.createConnection() throws only JMSException. - the method DefaultMessageListenerContainer.refreshConnectionUntilSuccessful() catches only JMSException and it doens't caught the unexpected UndeclaredThrowableException. - This exception runs through the whole stack and ends the listening thread. - THE RESULT: listening of JMS messages is terminated forever! Probability of this failure (a JNDI lookup before the HA-Singleton is moved) was 100% in my configuration. (2 JBoss instances with 3 JMS destinations and 2 connection factories running on one machine with 2x Xeon 5160 @ 3GHz, 6GB of RAM) The stack trace of UndeclaredThrowableException: java.lang.reflect.UndeclaredThrowableException at $Proxy103.createConnection(Unknown Source) at org.springframework.jms.listener.AbstractMessageListenerContainer.createConnection(AbstractMessageListenerContainer.java:991) at org.springframework.jms.listener.AbstractMessageListenerContainer.refreshSharedConnection(AbstractMessageListenerContainer.java:457) at org.springframework.jms.listener.DefaultMessageListenerContainer.refreshConnectionUntilSuccessful(DefaultMessageListenerContainer.java:701) at org.springframework.jms.listener.DefaultMessageListenerContainer.recoverAfterListenerSetupFailure(DefaultMessageListenerContainer.java:683) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:881) at org.springframework.core.task.SimpleAsyncTaskExecutor$ConcurrencyThrottlingRunnable.run(SimpleAsyncTaskExecutor.java:203) at java.lang.Thread.run(Thread.java:534) at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1067) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:700) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:716) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) at javax.naming.InitialContext.lookup(InitialContext.java:347) at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:124) at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:86) at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:122) at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:147) at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:91) at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:101) at org.springframework.jndi.JndiObjectTargetSource.getTarget(JndiObjectTargetSource.java:116) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:184) ... 9 more Caused by: javax.naming.NameNotFoundException: ConnectionFactory not bound at org.jnp.server.NamingServer.getBinding(NamingServer.java:529) at org.jnp.server.NamingServer.getBinding(NamingServer.java:537) at org.jnp.server.NamingServer.getObject(NamingServer.java:543) at org.jnp.server.NamingServer.lookup(NamingServer.java:296) at org.jboss.ha.jndi.TreeHead.lookupLocally(TreeHead.java:296) at org.jboss.ha.jndi.TreeHead.lookup(TreeHead.java:215) at org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:155) at sun.reflect.GeneratedMethodAccessor141.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.jboss.ha.framework.interfaces.HARMIClient.invoke(HARMIClient.java:258) at $Proxy102.lookup(Unknown Source) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) at javax.naming.InitialContext.lookup(InitialContext.java:347) at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1061) ... 21 more Proposed solution: Add the following catch block to the method DefaultMessageListenerContainer.refreshConnectionUntilSuccessful() catch (UndeclaredThrowableException ex) { if (ex.getUndeclaredThrowable() instanceof NamingException) { if (logger.isInfoEnabled()) { logger.info("Could not refresh...", ex); } } else { throw ex; } } I have tested this fix in an overridden class and it works fine.

    Spring JIRA | 10 years ago | Pavel Chuchma
    java.lang.reflect.UndeclaredThrowableException
  3. 0

    Jboss 6 : Not able to push messages in Jboss 4.2.2.GA queue

    Stack Overflow | 3 years ago | Deterrator
    javax.naming.NameNotFoundException: A not bound</strong>
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Encryption algorithm - Port3101.org : Your BES Connection

    port3101.org | 1 year ago
    javax.naming.NameNotFoundException: XAConnectionFactory not bound

    6 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. javax.naming.NameNotFoundException

      ConnectionFactory not bound

      at org.jnp.server.NamingServer.getBinding()
    2. org.jnp.server
      NamingServer.lookup
      1. org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
      2. org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
      3. org.jnp.server.NamingServer.getObject(NamingServer.java:543)
      4. org.jnp.server.NamingServer.lookup(NamingServer.java:296)
      4 frames
    3. org.jboss.ha
      HAJNDI.lookup
      1. org.jboss.ha.jndi.TreeHead.lookupLocally(TreeHead.java:296)
      2. org.jboss.ha.jndi.TreeHead.lookup(TreeHead.java:215)
      3. org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:155)
      3 frames
    4. Java RT
      Method.invoke
      1. sun.reflect.GeneratedMethodAccessor141.invoke(Unknown Source)
      2. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      3. java.lang.reflect.Method.invoke(Method.java:324)
      3 frames
    5. org.jboss.ha
      HARMIClient.invoke
      1. org.jboss.ha.framework.interfaces.HARMIClient.invoke(HARMIClient.java:258)
      1 frame
    6. Unknown
      $Proxy102.lookup
      1. $Proxy102.lookup(Unknown Source)
      1 frame
    7. org.jnp.interfaces
      NamingContext.lookup
      1. org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
      2. org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
      2 frames
    8. Java RT
      InitialContext.lookup
      1. javax.naming.InitialContext.lookup(InitialContext.java:347)
      1 frame
    9. org.jnp.interfaces
      NamingContext.resolveLink
      1. org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1061)
      1 frame
    10. Unknown
      $Proxy103.createConnection
      1. $Proxy103.createConnection(Unknown Source)
      1 frame
    11. Spring Framework
      DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run
      1. org.springframework.jms.listener.AbstractMessageListenerContainer.createConnection(AbstractMessageListenerContainer.java:991)
      2. org.springframework.jms.listener.AbstractMessageListenerContainer.refreshSharedConnection(AbstractMessageListenerContainer.java:457)
      3. org.springframework.jms.listener.DefaultMessageListenerContainer.refreshConnectionUntilSuccessful(DefaultMessageListenerContainer.java:701)
      4. org.springframework.jms.listener.DefaultMessageListenerContainer.recoverAfterListenerSetupFailure(DefaultMessageListenerContainer.java:683)
      5. org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:881)
      5 frames
    12. Spring Core
      SimpleAsyncTaskExecutor$ConcurrencyThrottlingRunnable.run
      1. org.springframework.core.task.SimpleAsyncTaskExecutor$ConcurrencyThrottlingRunnable.run(SimpleAsyncTaskExecutor.java:203)
      1 frame
    13. Java RT
      Thread.run
      1. java.lang.Thread.run(Thread.java:534)
      1 frame
    14. org.jnp.interfaces
      NamingContext.lookup
      1. org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1067)
      2. org.jnp.interfaces.NamingContext.lookup(NamingContext.java:700)
      3. org.jnp.interfaces.NamingContext.lookup(NamingContext.java:716)
      4. org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
      4 frames
    15. Java RT
      InitialContext.lookup
      1. javax.naming.InitialContext.lookup(InitialContext.java:347)
      1 frame
    16. Spring Context
      JndiObjectTargetSource.getTarget
      1. org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:124)
      2. org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:86)
      3. org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:122)
      4. org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:147)
      5. org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:91)
      6. org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:101)
      7. org.springframework.jndi.JndiObjectTargetSource.getTarget(JndiObjectTargetSource.java:116)
      7 frames
    17. Spring AOP
      JdkDynamicAopProxy.invoke
      1. org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:184)
      1 frame