You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/12/10 07:32:33 UTC

[camel] branch camel-2.22.x updated (621c32b -> fae4d5d)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 621c32b  CAMEL-12774 - Error during type conversion from type: java.lang.String to the required type: org.elasticsearch.action.update.UpdateRequest - Take 2
     new c8c96c4  CAMEL-12985: TransactionErrorHandler fails if UnitOfWork is null
     new 2ec7d74  CAMEL-12985: Added a test that fails on master
     new fae4d5d  CAMEL-12985 - Fixed CS

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/spring/spi/TransactionErrorHandler.java  | 12 ++++++--
 ...nterceptUsingAdviceWithSendToEndpointTest.java} | 33 ++++++++++++++++++----
 2 files changed, 37 insertions(+), 8 deletions(-)
 copy components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/{TransactedInterceptSendToEndpointTest.java => TransactedInterceptUsingAdviceWithSendToEndpointTest.java} (70%)


[camel] 03/03: CAMEL-12985 - Fixed CS

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit fae4d5d0b806aefce551cb8eed01212e75093639
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Dec 10 08:24:30 2018 +0100

    CAMEL-12985 - Fixed CS
---
 .../org/apache/camel/spring/spi/TransactionErrorHandler.java   | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
index 6436476..79d6bbb 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
@@ -95,7 +95,9 @@ public class TransactionErrorHandler extends RedeliveryErrorHandler {
     public void process(Exchange exchange) throws Exception {
         // we have to run this synchronously as Spring Transaction does *not* support
         // using multiple threads to span a transaction
-        if (transactionTemplate.getPropagationBehavior() != TransactionDefinition.PROPAGATION_REQUIRES_NEW && exchange.getUnitOfWork() != null && exchange.getUnitOfWork().isTransactedBy(transactionKey)) {
+        if (transactionTemplate.getPropagationBehavior() != TransactionDefinition.PROPAGATION_REQUIRES_NEW 
+            && exchange.getUnitOfWork() != null 
+            && exchange.getUnitOfWork().isTransactedBy(transactionKey)) {
             // already transacted by this transaction template
             // so lets just let the error handler process it
             processByErrorHandler(exchange);
@@ -129,8 +131,9 @@ public class TransactionErrorHandler extends RedeliveryErrorHandler {
 
         try {
             // mark the beginning of this transaction boundary
-            if (exchange.getUnitOfWork() != null)
+            if (exchange.getUnitOfWork() != null) {
                 exchange.getUnitOfWork().beginTransactedBy(transactionKey);
+            }
 
             // do in transaction
             logTransactionBegin(redelivered, ids);
@@ -145,8 +148,9 @@ public class TransactionErrorHandler extends RedeliveryErrorHandler {
             logTransactionRollback(redelivered, ids, e, false);
         } finally {
             // mark the end of this transaction boundary
-            if (exchange.getUnitOfWork() != null)
+            if (exchange.getUnitOfWork() != null) {
                 exchange.getUnitOfWork().endTransactedBy(transactionKey);
+            }
         }
 
         // if it was a local rollback only then remove its marker so outer transaction wont see the marker


[camel] 02/03: CAMEL-12985: Added a test that fails on master

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 2ec7d747a505868d19efafaa12cc725f64cbd6f9
Author: Jess Sightler <je...@gmail.com>
AuthorDate: Fri Dec 7 19:07:18 2018 -0500

    CAMEL-12985: Added a test that fails on master
---
 ...InterceptUsingAdviceWithSendToEndpointTest.java | 93 ++++++++++++++++++++++
 1 file changed, 93 insertions(+)

diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactedInterceptUsingAdviceWithSendToEndpointTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactedInterceptUsingAdviceWithSendToEndpointTest.java
new file mode 100644
index 0000000..39bbf5c
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactedInterceptUsingAdviceWithSendToEndpointTest.java
@@ -0,0 +1,93 @@
+/**
+ * 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.camel.spring.interceptor;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringRouteBuilder;
+import org.junit.Test;
+
+/**
+ * Easier transaction configuration as we do not have to setup a transaction error handler
+ */
+public class TransactedInterceptUsingAdviceWithSendToEndpointTest extends TransactionalClientDataSourceTest {
+
+    @Test
+    public void testTransactionSuccess() throws Exception {
+        MockEndpoint intercepted = getMockEndpoint("mock:intercepted");
+        
+        addInterceptor("ok_route");
+        
+        intercepted.expectedBodiesReceived("Hello World");
+
+        super.testTransactionSuccess();
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testTransactionRollback() throws Exception {
+        MockEndpoint intercepted = getMockEndpoint("mock:intercepted");
+        
+        addInterceptor("fail_route");
+        
+        intercepted.expectedBodiesReceived("Tiger in Action");
+
+        super.testTransactionRollback();
+
+        assertMockEndpointsSatisfied();
+    }
+    
+    private void addInterceptor(String routeId) throws Exception {
+        context.getRouteDefinition(routeId).adviceWith(context, new SpringRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                interceptSendToEndpoint("direct:(foo|bar)")
+                    .to("mock:intercepted");
+            }
+        });
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new SpringRouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:okay")
+                    .routeId("ok_route")
+                    .transacted()
+                    .enrich("direct:foo", (oldExchange, newExchange) -> {
+                        return newExchange;
+                    })
+                    .setBody(constant("Tiger in Action")).bean("bookService")
+                    .setBody(constant("Elephant in Action")).bean("bookService");
+
+                from("direct:fail")
+                    .routeId("fail_route")
+                    .transacted()
+                    .setBody(constant("Tiger in Action")).bean("bookService")
+                    .enrich("direct:bar", (oldExchange, newExchange) -> {
+                        return newExchange;
+                    })
+                    .setBody(constant("Donkey in Action")).bean("bookService");
+
+                from("direct:foo").to("log:okay");
+
+                from("direct:bar").to("mock:fail");
+            }
+        };
+    }
+
+}
\ No newline at end of file


[camel] 01/03: CAMEL-12985: TransactionErrorHandler fails if UnitOfWork is null

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c8c96c4ddea0db4fb5429701b9484e78145ddf62
Author: Jess Sightler <je...@gmail.com>
AuthorDate: Fri Dec 7 13:07:43 2018 -0500

    CAMEL-12985: TransactionErrorHandler fails if UnitOfWork is null
---
 .../java/org/apache/camel/spring/spi/TransactionErrorHandler.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
index 653ea84..6436476 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
@@ -95,7 +95,7 @@ public class TransactionErrorHandler extends RedeliveryErrorHandler {
     public void process(Exchange exchange) throws Exception {
         // we have to run this synchronously as Spring Transaction does *not* support
         // using multiple threads to span a transaction
-        if (transactionTemplate.getPropagationBehavior() != TransactionDefinition.PROPAGATION_REQUIRES_NEW && exchange.getUnitOfWork().isTransactedBy(transactionKey)) {
+        if (transactionTemplate.getPropagationBehavior() != TransactionDefinition.PROPAGATION_REQUIRES_NEW && exchange.getUnitOfWork() != null && exchange.getUnitOfWork().isTransactedBy(transactionKey)) {
             // already transacted by this transaction template
             // so lets just let the error handler process it
             processByErrorHandler(exchange);
@@ -129,7 +129,8 @@ public class TransactionErrorHandler extends RedeliveryErrorHandler {
 
         try {
             // mark the beginning of this transaction boundary
-            exchange.getUnitOfWork().beginTransactedBy(transactionKey);
+            if (exchange.getUnitOfWork() != null)
+                exchange.getUnitOfWork().beginTransactedBy(transactionKey);
 
             // do in transaction
             logTransactionBegin(redelivered, ids);
@@ -144,7 +145,8 @@ public class TransactionErrorHandler extends RedeliveryErrorHandler {
             logTransactionRollback(redelivered, ids, e, false);
         } finally {
             // mark the end of this transaction boundary
-            exchange.getUnitOfWork().endTransactedBy(transactionKey);
+            if (exchange.getUnitOfWork() != null)
+                exchange.getUnitOfWork().endTransactedBy(transactionKey);
         }
 
         // if it was a local rollback only then remove its marker so outer transaction wont see the marker