You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ff...@apache.org on 2019/09/05 13:39:58 UTC

[camel] 01/02: [CAMEL-13942]UnitOfWork should be done after send back response

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

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

commit 4b176b5a3b7cbff552312fb443d3b4d98eb7d43d
Author: Freeman Fang <fr...@gmail.com>
AuthorDate: Wed Sep 4 15:55:43 2019 -0400

    [CAMEL-13942]UnitOfWork should be done after send back response
    
    (cherry picked from commit 101c4eb80b4d1aa6bd267a72d8fe315f74d917a9)
---
 .../camel/component/undertow/UndertowConsumer.java |  3 +-
 .../undertow/UndertowHttpStreamCachingTest.java    | 61 ++++++++++++++++++++++
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
index a94e93a..148c2b9 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
@@ -148,13 +148,14 @@ public class UndertowConsumer extends DefaultConsumer implements HttpHandler {
         createUoW(camelExchange);
         try {
             getProcessor().process(camelExchange);
+            sendResponse(httpExchange, camelExchange);
         } catch (Exception e) {
             getExceptionHandler().handleException(e);
         } finally {
             doneUoW(camelExchange);
         }
 
-        sendResponse(httpExchange, camelExchange);
+        
     }
 
     private void sendResponse(HttpServerExchange httpExchange, Exchange camelExchange) throws IOException, NoTypeConversionAvailableException {
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowHttpStreamCachingTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowHttpStreamCachingTest.java
new file mode 100644
index 0000000..e9bcfaa
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowHttpStreamCachingTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.undertow;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpMethods;
+import org.junit.Test;
+
+public class UndertowHttpStreamCachingTest extends BaseUndertowTest {
+    
+    private String data = "abcdefg";
+
+
+    @Test
+    public void testTwoWayStreaming() throws Exception {
+        Exchange exchange = template.request("undertow:http://localhost:{{port}}/client", null);
+        
+        assertTrue(new String((byte[])exchange.getMessage().getBody()).equals(data));
+    }
+
+    
+
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                
+                getContext().setStreamCaching(true);
+                getContext().getStreamCachingStrategy().setSpoolThreshold(3);
+
+                
+
+                //from("undertow:http://localhost:8080/client?useStreaming=true")
+                from("undertow:http://localhost:{{port}}/client")
+                    .setHeader(Exchange.HTTP_METHOD, constant(HttpMethods.POST))
+                    .to("http://localhost:{{port}}/server?bridgeEndpoint=true").to("log:lgName?showBody=true")
+                    .end();
+                from("undertow:http://localhost:{{port}}/server?httpMethodRestrict=POST").setBody(simple(data))
+                    .to("log:lgName?showBody=true").end();
+            }
+        };
+    }
+
+}