You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2010/10/25 12:37:58 UTC

svn commit: r1027034 - in /servicemix/components/engines/servicemix-camel/trunk/src: main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java test/java/org/apache/servicemix/camel/JbiTryCatchExceptionTest.java

Author: gertv
Date: Mon Oct 25 10:37:57 2010
New Revision: 1027034

URL: http://svn.apache.org/viewvc?rev=1027034&view=rev
Log:
SMXCOMP-816: Only use Fault message in JBI if Camel out message has the fault flag set

Added:
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTryCatchExceptionTest.java
Modified:
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java?rev=1027034&r1=1027033&r2=1027034&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java Mon Oct 25 10:37:57 2010
@@ -157,7 +157,7 @@ public class CamelProviderEndpoint exten
     public void onFailure(Exchange exchange) {
         MessageExchange me = JbiBinding.getMessageExchange(exchange);
         try {
-            if (exchange.hasOut()) {
+            if (exchange.hasOut() && exchange.getOut().isFault()) {
                 Fault fault = me.createFault();
                 binding.copyFromCamelToJbi(exchange.getOut(), fault);
                 if (isFaultCapable(me)) {

Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTryCatchExceptionTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTryCatchExceptionTest.java?rev=1027034&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTryCatchExceptionTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTryCatchExceptionTest.java Mon Oct 25 10:37:57 2010
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.camel;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+
+import java.util.List;
+
+/**
+ * Tests on handling Camel exception with the doTry()...doCatch() DSL
+ */
+public class JbiTryCatchExceptionTest extends JbiTestSupport {
+    
+    private static final String MESSAGE = "<just><a>test</a></just>";
+
+    public void testInOnlyExchangeConvertBody() throws Exception {
+        MockEndpoint caught = getMockEndpoint("mock:caught");
+        caught.expectedMessageCount(1);
+
+        client.sendBody("direct:test", MESSAGE);
+
+        caught.assertIsSatisfied();
+    }
+    
+    @Override
+    protected void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList) {
+        // no additional activation specs required
+    }
+
+    @Override
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+
+            @Override
+            public void configure() throws Exception {
+                // let's not retry things too often as this will only slow down the unit tests
+                errorHandler(deadLetterChannel("mock:errors").maximumRedeliveries(0).handled(false));
+
+                // throwing an exception from within the Camel route
+                from("jbi:endpoint:urn:test:throwsException")
+                    .errorHandler(noErrorHandler())
+                    .to("mock:thrown")
+                    .throwException(new CustomBusinessException());
+
+                // Camel route that handles this exception with doTry()...doCatch()...
+                from("direct:test")
+                    .doTry()
+                        .to("jbi:endpoint:urn:test:throwsException?mep=in-out")
+                    .doCatch(CustomBusinessException.class)
+                        .to("mock:caught")
+                    .end();                
+            }
+        };
+    }
+
+    /*
+     * Exception class to test with
+     */
+    private static final class CustomBusinessException extends Exception {
+
+    }
+}