[CXF-6778] Use exceptionlistener optionally to react faster if supported
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a9834591 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a9834591 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a9834591 Branch: refs/heads/jms-exception-handling Commit: a98345918f30b8288621ff7b3e7dc09947e86527 Parents: 1f9cbe3 Author: Christian Schneider <ch...@die-schneider.net> Authored: Thu Apr 20 16:07:38 2017 +0200 Committer: Christian Schneider <ch...@die-schneider.net> Committed: Thu Apr 20 16:07:38 2017 +0200 ---------------------------------------------------------------------- .../apache/cxf/transport/jms/JMSConduit.java | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/a9834591/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java ---------------------------------------------------------------------- diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java index 2654353..e588542 100644 --- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java +++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java @@ -32,6 +32,7 @@ import java.util.logging.Logger; import javax.jms.Connection; import javax.jms.Destination; +import javax.jms.ExceptionListener; import javax.jms.JMSException; import javax.jms.MessageListener; import javax.jms.Session; @@ -107,6 +108,7 @@ public class JMSConduit extends AbstractConduit implements JMSExchangeSender, Me result = connection; if (result == null) { result = JMSFactory.createConnection(jmsConfig); + trySetExListener(result); result.start(); connection = result; } @@ -116,6 +118,26 @@ public class JMSConduit extends AbstractConduit implements JMSExchangeSender, Me } /** + * Register exception listener to react faster when a connection is reset. + * + * @param conn + */ + private void trySetExListener(Connection conn) { + try { + conn.setExceptionListener(new ExceptionListener() { + + @Override + public void onException(JMSException exception) { + jmsConfig.resetCachedReplyDestination(); + staticReplyDestination = null; + } + }); + } catch (JMSException e) { + // setException is not supported on all providers + } + } + + /** * Send the JMS message and if the MEP is not oneway receive the response. * * @param exchange the Exchange containing the outgoing message