camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r778650 - in /camel/trunk/components/camel-ibatis/src: main/java/org/apache/camel/component/ibatis/ test/java/org/apache/camel/component/ibatis/
Date Tue, 26 May 2009 11:17:20 GMT
Author: davsclaus
Date: Tue May 26 11:17:19 2009
New Revision: 778650

URL: http://svn.apache.org/viewvc?rev=778650&view=rev
Log:
CAMEL-1649: camel-ibatis. Only set the response as Body if SELECT statement. Always set response
as header. And honor MEP.

Modified:
    camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisConstants.java
    camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java
    camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java
    camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisUnknownStatementTypeTest.java

Modified: camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisConstants.java?rev=778650&r1=778649&r2=778650&view=diff
==============================================================================
--- camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisConstants.java
(original)
+++ camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisConstants.java
Tue May 26 11:17:19 2009
@@ -21,6 +21,8 @@
  */
 public final class IBatisConstants {
 
+    public static final String IBATIS_RESULT = "CamelIBatisResult";
+
     public static final String IBATIS_STATEMENT_NAME = "CamelIBatisStatementName";
 
     private IBatisConstants() {

Modified: camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java?rev=778650&r1=778649&r2=778650&view=diff
==============================================================================
--- camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java
(original)
+++ camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java
Tue May 26 11:17:19 2009
@@ -23,6 +23,7 @@
 import org.apache.camel.Message;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ExchangeHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -173,8 +174,22 @@
     }
 
     private void doProcessResult(Exchange exchange, Object result) {
-        Message msg = exchange.getOut();
-        msg.setBody(result);
-        msg.setHeader(IBatisConstants.IBATIS_STATEMENT_NAME, statement);
+        if (endpoint.getStatementType() == StatementType.QueryForList || endpoint.getStatementType()
== StatementType.QueryForObject ) {
+            Message answer = exchange.getIn();
+            if (ExchangeHelper.isOutCapable(exchange)) {
+                answer = exchange.getOut();
+                // preserve headers
+                answer.getHeaders().putAll(exchange.getIn().getHeaders());
+            }
+            // set the result as body for insert
+            answer.setBody(result);
+
+            answer.setHeader(IBatisConstants.IBATIS_RESULT, result);
+            answer.setHeader(IBatisConstants.IBATIS_STATEMENT_NAME, statement);
+        } else {
+            Message msg = exchange.getIn();
+            msg.setHeader(IBatisConstants.IBATIS_RESULT, result);
+            msg.setHeader(IBatisConstants.IBATIS_STATEMENT_NAME, statement);
+        }
     }
 }

Modified: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java?rev=778650&r1=778649&r2=778650&view=diff
==============================================================================
--- camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java
(original)
+++ camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java
Tue May 26 11:17:19 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.component.ibatis;
 
 import java.util.List;
+import java.util.ArrayList;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;

Modified: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisUnknownStatementTypeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisUnknownStatementTypeTest.java?rev=778650&r1=778649&r2=778650&view=diff
==============================================================================
--- camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisUnknownStatementTypeTest.java
(original)
+++ camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisUnknownStatementTypeTest.java
Tue May 26 11:17:19 2009
@@ -16,7 +16,9 @@
  */
 package org.apache.camel.component.ibatis;
 
+import org.apache.camel.CamelExecutionException;
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToCreateProducerException;
 import org.apache.camel.builder.RouteBuilder;
 
 /**
@@ -26,15 +28,21 @@
 
     public void testStatementTypeNotSet() throws Exception {
         try {
-            context.addRoutes(new RouteBuilder() {
-                @Override
-                public void configure() throws Exception {
-                    from("direct:start").to("ibatis:selectAllAccounts");
-                }
-            });
+            template.sendBody("direct:start", "Hello");
             fail("Should have thrown an IllegalArgumentException");
-        } catch (IllegalArgumentException e) {
-            assertEquals("statementType must be specified on: Endpoint[ibatis:selectAllAccounts]",
e.getMessage());
+        } catch (CamelExecutionException e) {
+            assertIsInstanceOf(FailedToCreateProducerException.class, e.getCause());
+            assertEquals("statementType must be specified on: Endpoint[ibatis:selectAllAccounts]",
e.getCause().getCause().getMessage());
         }
     }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("ibatis:selectAllAccounts");
+            }
+        };
+    }
 }



Mime
View raw message