Author: dkulp
Date: Fri Jul  8 19:46:03 2011
New Revision: 1144456

URL: http://svn.apache.org/viewvc?rev=1144456&view=rev
Log:
Merged revisions 1097761 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1097761 | davsclaus | 2011-04-29 06:36:13 -0400 (Fri, 29 Apr 2011) | 1 line
  
  CAMEL-3913: Fixed JMS consumer may WARN a ClassCastException during 
processing message. Fixed and improved logic for detecting if JMS consumer 
should send back a reply or not.
........

Added:
    
camel/branches/camel-2.7.x/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsHttpPostIssueTest.java
      - copied unchanged from r1097761, 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsHttpPostIssueTest.java
    
camel/branches/camel-2.7.x/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsHttpPostIssueWithMockTest.java
      - copied unchanged from r1097761, 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsHttpPostIssueWithMockTest.java
Modified:
    camel/branches/camel-2.7.x/   (props changed)
    
camel/branches/camel-2.7.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java

Propchange: camel/branches/camel-2.7.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jul  8 19:46:03 2011
@@ -1 +1 @@
-/camel/trunk:1083696,1083723-1083724,1084150,1085277,1085543,1085549,1085905,1085909,1086165,1086231,1087005,1087276,1087612,1087620,1087856,1088583,1088916-1088917,1089275,1089348,1090166,1090204,1090564,1090960-1090969,1091082,1091518,1091771,1091799,1092034,1092068,1092577,1092667,1093978,1093980,1093999,1094123,1094147,1094156,1095405,1095469,1095471,1095475-1095476,1096346,1096736,1097909,1097912,1097978,1098630,1099417,1100975,1102162,1102181,1104076,1124497,1127744,1127988,1131411,1134252,1134501,1135223,1135364,1136290,1138285,1139163,1140096-1140102,1141783,1143925,1144248,1144324
+/camel/trunk:1083696,1083723-1083724,1084150,1085277,1085543,1085549,1085905,1085909,1086165,1086231,1087005,1087276,1087612,1087620,1087856,1088583,1088916-1088917,1089275,1089348,1090166,1090204,1090564,1090960-1090969,1091082,1091518,1091771,1091799,1092034,1092068,1092577,1092667,1093978,1093980,1093999,1094123,1094147,1094156,1095405,1095469,1095471,1095475-1095476,1096346,1096736,1097761,1097909,1097912,1097978,1098630,1099417,1100975,1102162,1102181,1104076,1124497,1127744,1127988,1131411,1134252,1134501,1135223,1135364,1136290,1138285,1139163,1140096-1140102,1141783,1143925,1144248,1144324

Propchange: camel/branches/camel-2.7.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: 
camel/branches/camel-2.7.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java?rev=1144456&r1=1144455&r2=1144456&view=diff
==============================================================================
--- 
camel/branches/camel-2.7.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
 (original)
+++ 
camel/branches/camel-2.7.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
 Fri Jul  8 19:46:03 2011
@@ -70,9 +70,14 @@ public class EndpointMessageListener imp
             LOG.debug(endpoint + " consumer received JMS message: " + message);
         }
 
+        boolean sendReply;
         RuntimeCamelException rce = null;
         try {
             Object replyDestination = getReplyToDestination(message);
+            // we can only send back a reply if there was a reply destination 
configured
+            // and disableReplyTo hasn't been explicit enabled
+            sendReply = replyDestination != null && !disableReplyTo;
+
             final Exchange exchange = createExchange(message, 
replyDestination);
             if (eagerLoadingOfProperties) {
                 exchange.getIn().getHeaders();
@@ -88,6 +93,8 @@ public class EndpointMessageListener imp
                 LOG.debug("Received Message has JMSCorrelationID [" + 
correlationId + "]");
             }
 
+            // process the exchange
+            LOG.trace("onMessage.process START");
             try {
                 processor.process(exchange);
             } catch (Throwable e) {
@@ -97,39 +104,44 @@ public class EndpointMessageListener imp
                 LOG.trace("onMessage.process END");
             }
 
-            // get the correct jms message to send as reply
-            JmsMessage body = null;
+            // now we evaluate the processing of the exchange and determine if 
it was a success or failure
+            // we also grab information from the exchange to be used for 
sending back a reply (if we are to do so)
+            // so the following logic seems a bit complicated at first glance
+
+            // if we send back a reply it can either be the message body or 
transferring a caused exception
+            org.apache.camel.Message body = null;
             Exception cause = null;
-            boolean sendReply = false;
+
             if (exchange.isFailed() || exchange.isRollbackOnly()) {
-                if (exchange.getException() != null) {
+                if (exchange.isRollbackOnly()) {
+                    // rollback only so wrap an exception so we can rethrow 
the exception to cause rollback
+                    rce = wrapRuntimeCamelException(new 
RollbackExchangeException(exchange));
+                } else if (exchange.getException() != null) {
                     // an exception occurred while processing
                     if (endpoint.isTransferException()) {
-                        // send the exception as reply
+                        // send the exception as reply, so null body and set 
the exception as the cause
                         body = null;
                         cause = exchange.getException();
-                        sendReply = true;
                     } else {
                         // only throw exception if endpoint is not configured 
to transfer exceptions back to caller
                         // do not send a reply but wrap and rethrow the 
exception
                         rce = 
wrapRuntimeCamelException(exchange.getException());
                     }
-                } else if (exchange.isRollbackOnly()) {
-                    // rollback only so wrap an exception so we can rethrow 
the exception to cause rollback
-                    rce = wrapRuntimeCamelException(new 
RollbackExchangeException(exchange));
-                } else if (exchange.getOut().getBody() != null) {
+                } else if (exchange.hasOut() && exchange.getOut().isFault()) {
                     // a fault occurred while processing
-                    body = (JmsMessage) exchange.getOut();
-                    sendReply = true;
+                    body = exchange.getOut();
+                    cause = null;
+                }
+            } else {
+                // process OK so get the reply body if we are InOut and has a 
body
+                if (sendReply && exchange.getPattern().isOutCapable() && 
exchange.hasOut()) {
+                    body = exchange.getOut();
+                    cause = null;
                 }
-            } else if (exchange.hasOut()) {
-                // process OK so get the reply
-                body = (JmsMessage) exchange.getOut();
-                sendReply = true;
             }
 
-            // send the reply if we got a response and the exchange is out 
capable
-            if (rce == null && sendReply && !disableReplyTo && 
exchange.getPattern().isOutCapable()) {
+            // send back reply if there was no error and we are supposed to 
send back a reply
+            if (rce == null && sendReply && (body != null || cause != null)) {
                 LOG.trace("onMessage.sendReply START");
                 if (replyDestination instanceof Destination) {
                     sendReply((Destination)replyDestination, message, 
exchange, body, cause);
@@ -143,6 +155,7 @@ public class EndpointMessageListener imp
             rce = wrapRuntimeCamelException(e);
         }
 
+        // an exception occurred so rethrow to trigger rollback on JMS listener
         if (rce != null) {
             handleException(rce);
             if (LOG.isTraceEnabled()) {
@@ -270,7 +283,7 @@ public class EndpointMessageListener imp
     }
 
     protected void sendReply(Destination replyDestination, final Message 
message, final Exchange exchange,
-                             final JmsMessage out, final Exception cause) {
+                             final org.apache.camel.Message out, final 
Exception cause) {
         if (replyDestination == null) {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Cannot send reply message as there is no 
replyDestination for: " + out);
@@ -292,7 +305,7 @@ public class EndpointMessageListener imp
     }
 
     protected void sendReply(String replyDestination, final Message message, 
final Exchange exchange,
-                             final JmsMessage out, final Exception cause) {
+                             final org.apache.camel.Message out, final 
Exception cause) {
         if (replyDestination == null) {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Cannot send reply message as there is no 
replyDestination for: " + out);


Reply via email to