From 5d63998add4e6e3a665df7cc53680ce1774d577e Mon Sep 17 00:00:00 2001 From: antelder Date: Thu, 3 Nov 2011 14:27:22 +0000 Subject: TUSCANY-3970 Improve error handling in TransportServiceInterceptor.invoke() git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1197137 13f79535-47bb-0310-9956-ffa450edef68 --- .../jms/transport/TransportServiceInterceptor.java | 39 +++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca') diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java index 266f02b9f1..ab3392fcce 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java @@ -79,18 +79,41 @@ public class TransportServiceInterceptor extends InterceptorAsyncImpl { try { return invokeResponse(next.invoke(invokeRequest(msg))); } catch (Throwable e) { + try { + // Normally only runtime exceptions (whether thrown by the application or the runtime) + // reach this catch block. Business exceptions are handled in the normal invokeResponse path. logger.log(Level.SEVERE, "Exception invoking service '" + service.getName(), e); - JMSBindingContext context = msg.getBindingContext(); - javax.jms.Message replyJMSMsg = responseMessageProcessor.createFaultMessage(context.getJmsResponseSession(), - (Throwable)e); - msg.setBody(replyJMSMsg); - invokeResponse(msg); + + Operation operation = msg.getOperation(); + if (operation != null && !operation.isNonBlocking()) { + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsResponseSession(); + javax.jms.Message replyJMSMsg = responseMessageProcessor.createFaultMessage(session, e); + msg.setBody(replyJMSMsg); + invokeResponse(msg); + } + + } catch (Throwable e2) {} + // Rethrow a runtime exception so that the JMS resource adapter can rollback + // the message (if delivery is transacted) and increment the failed delivery count. + if (e instanceof Error) { + throw (Error)e; + } + if (e instanceof RuntimeException) { + throw (RuntimeException)e; + } return msg; } finally { try { - ((JMSBindingContext)msg.getBindingContext()).closeJmsResponseSession(); - if (jmsResourceFactory.isConnectionClosedAfterUse()) - jmsResourceFactory.closeResponseConnection(); + try { + ((JMSBindingContext)msg.getBindingContext()).closeJmsResponseSession(); + } catch (Throwable e) { + } + // Use the resource factory in the binding context to close the response connection, + // to ensure we use same resource factory used to close response session. + JMSResourceFactory rf = ((JMSBindingContext)msg.getBindingContext()).getJmsResourceFactory(); + if (rf.isConnectionClosedAfterUse()) + rf.closeResponseConnection(); } catch (JMSException e) { } } -- cgit v1.2.3