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

fmariani pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 14302ea76f1 Handle exception thrown in beanProcessor.process
14302ea76f1 is described below

commit 14302ea76f1da6b5abf4c399585b084882faaeca
Author: Croway <[email protected]>
AuthorDate: Mon May 15 17:33:35 2023 +0200

    Handle exception thrown in beanProcessor.process
---
 .../component/mybatis/MyBatisBeanProducer.java     |  5 ++
 .../mybatis/bean/MyBatisBeanWrongMethodTest.java   | 53 ++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git 
a/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisBeanProducer.java
 
b/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisBeanProducer.java
index 6476c1862e7..dc762e63e6f 100644
--- 
a/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisBeanProducer.java
+++ 
b/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/MyBatisBeanProducer.java
@@ -77,6 +77,11 @@ public class MyBatisBeanProducer extends DefaultProducer {
         beanProcessor.process(copy);
         beanProcessor.stop();
 
+        if (copy.getException() != null) {
+            session.rollback();
+            throw copy.getException();
+        }
+
         Object result = copy.getMessage().getBody();
         if (result != input) {
             if (endpoint.getOutputHeader() != null) {
diff --git 
a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanWrongMethodTest.java
 
b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanWrongMethodTest.java
new file mode 100644
index 00000000000..c7d8260c262
--- /dev/null
+++ 
b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanWrongMethodTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.component.mybatis.bean;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class MyBatisBeanWrongMethodTest extends CamelTestSupport {
+
+    @Test
+    public void testSelectList() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        Exception ex = Assertions.assertThrows(CamelExecutionException.class,
+                () -> template.sendBody("direct:start", null));
+
+        Assertions.assertTrue(
+                ex.getCause().getMessage().contains("Method with name: 
wrongMethodThatDoesNotExists not found on bean: " +
+                                                    
"org.apache.ibatis.binding.MapperProxy"));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:start")
+                        
.to("mybatis-bean:AccountService:wrongMethodThatDoesNotExists")
+                        .to("mock:result");
+            }
+        };
+    }
+
+}

Reply via email to