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

[camel] branch camel-2.x updated (9d32ced -> d11e46e)

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

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


    from 9d32ced  Upgrade Awaitility to version 4.0.1
     new eb48ec1  CAMEL-13886: camel-servlet + camel-http4 with null body causes "Stream closed" IOException
     new d11e46e  CAMEL-13886: Add integration test to camel-servlet-starter

The 2 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:
 .../org/apache/camel/http/common/HttpMessage.java    | 15 +++++++++++++--
 ...gurationTest.java => ServletHttpMessageTest.java} | 20 ++++++++++++--------
 2 files changed, 25 insertions(+), 10 deletions(-)
 copy platforms/spring-boot/components-starter/camel-servlet-starter/src/test/java/org/apache/camel/component/servlet/springboot/test/{ServletMappingAutoConfigurationTest.java => ServletHttpMessageTest.java} (74%)


[camel] 02/02: CAMEL-13886: Add integration test to camel-servlet-starter

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

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

commit d11e46e4d5fb477e08fe7dcc061acba7650d0dcc
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Fri Sep 13 18:28:47 2019 +0900

    CAMEL-13886: Add integration test to camel-servlet-starter
    
    (cherry picked from commit 3ec2cc5d70243d2b569229f95f0f646697cf1eba)
---
 .../springboot/test/ServletHttpMessageTest.java    | 74 ++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/platforms/spring-boot/components-starter/camel-servlet-starter/src/test/java/org/apache/camel/component/servlet/springboot/test/ServletHttpMessageTest.java b/platforms/spring-boot/components-starter/camel-servlet-starter/src/test/java/org/apache/camel/component/servlet/springboot/test/ServletHttpMessageTest.java
new file mode 100644
index 0000000..d9f8f5e
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-servlet-starter/src/test/java/org/apache/camel/component/servlet/springboot/test/ServletHttpMessageTest.java
@@ -0,0 +1,74 @@
+/**
+ * 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.servlet.springboot.test;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * Testing HttpMessage used with Servlet component.
+ */
+@RunWith(SpringRunner.class)
+@SpringBootApplication
+@DirtiesContext
+@ContextConfiguration(classes = ServletHttpMessageTest.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class ServletHttpMessageTest {
+
+    @Autowired
+    private TestRestTemplate restTemplate;
+
+    @Autowired
+    private CamelContext context;
+
+    @Before
+    public void setup() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+
+                rest().get("/outMessageNullBody")
+                        .produces("text/plain")
+                        .route()
+                        // read body at least once
+                        .log("${body}")
+                        // simulate endpoints that may put null to out message body
+                        .process(e -> e.getOut().setBody(null))
+                        // ensure reading body again does not cause an exception
+                        .log("${body}");
+            }
+        });
+    }
+
+    @Test
+    public void testOutMessageNullBody() {
+        Assert.assertNull(restTemplate.getForEntity("/camel/outMessageNullBody", String.class).getBody());
+    }
+
+}
+


[camel] 01/02: CAMEL-13886: camel-servlet + camel-http4 with null body causes "Stream closed" IOException

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

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

commit eb48ec1d4761bc56cc9b8a7ae81bdf9a2e6f14cf
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Thu Sep 12 18:19:06 2019 +0900

    CAMEL-13886: camel-servlet + camel-http4 with null body causes "Stream closed" IOException
    
    Normally servlet request can be read only once, but when
    Exchange#getOut() is invoked HttpMessage may be copied for the out
    message with the original request that has been already read.
    This fix protects it from being read again.
---
 .../java/org/apache/camel/http/common/HttpMessage.java    | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java
index a799a08..6a0ea0c 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java
@@ -33,11 +33,13 @@ public class HttpMessage extends DefaultMessage {
     private final HttpServletRequest request;
     private final HttpServletResponse response;
     private final HttpCommonEndpoint endpoint;
+    private boolean requestRead;
 
     public HttpMessage(Exchange exchange, HttpCommonEndpoint endpoint, HttpServletRequest request, HttpServletResponse response) {
         setExchange(exchange);
         setCamelContext(exchange.getContext());
         this.endpoint = endpoint;
+        this.requestRead = false;
 
         this.request = request;
         this.response = response;
@@ -56,12 +58,14 @@ public class HttpMessage extends DefaultMessage {
         endpoint.getHttpBinding().readRequest(request, this);
     }
 
-    private HttpMessage(HttpServletRequest request, HttpServletResponse response, Exchange exchange, HttpCommonEndpoint endpoint) {
+    private HttpMessage(HttpServletRequest request, HttpServletResponse response, Exchange exchange, HttpCommonEndpoint endpoint,
+                        boolean requestRead) {
         this.request = request;
         this.response = response;
         setExchange(getExchange());
         this.endpoint = endpoint;
         setCamelContext(exchange.getContext());
+        this.requestRead = requestRead;
     }
 
     public HttpServletRequest getRequest() {
@@ -74,16 +78,23 @@ public class HttpMessage extends DefaultMessage {
 
     @Override
     protected Object createBody() {
+        // HTTP request may be read only once
+        if (requestRead) {
+            return null;
+        }
+
         try {
             return endpoint.getHttpBinding().parseBody(this);
         } catch (IOException e) {
             throw new RuntimeCamelException(e);
+        } finally {
+            requestRead = true;
         }
     }
 
     @Override
     public HttpMessage newInstance() {
-        return new HttpMessage(request, response, getExchange(), endpoint);
+        return new HttpMessage(request, response, getExchange(), endpoint, requestRead);
     }
 
     @Override