You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2011/11/03 15:27:23 UTC

svn commit: r1197137 - /tuscany/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java

Author: antelder
Date: Thu Nov  3 14:27:22 2011
New Revision: 1197137

URL: http://svn.apache.org/viewvc?rev=1197137&view=rev
Log:
TUSCANY-3970 Improve error handling in TransportServiceInterceptor.invoke()

Modified:
    tuscany/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java?rev=1197137&r1=1197136&r2=1197137&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java Thu Nov  3 14:27:22 2011
@@ -79,18 +79,41 @@ public class TransportServiceInterceptor
         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) {
             }
         }