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/08/21 06:27:22 UTC

[camel] branch camel-2.x updated (86b60a3 -> 63ec0ac)

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 86b60a3  Backporting atmos test fix
     new eb33736  CAMEL-13886: camel-servlet + camel-http4 with null body causes "Stream closed" IOException
     new 63ec0ac  Fix CS

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:
 components/camel-http-common/pom.xml               |  5 ++++
 .../org/apache/camel/http/common/HttpHelper.java   |  4 +--
 .../http/common/HttpHeaderFilterStrategyTest.java  |  1 -
 .../apache/camel/http/common/HttpHelperTest.java}  | 34 ++++++++++++++--------
 4 files changed, 29 insertions(+), 15 deletions(-)
 copy components/{camel-crypto-cms/src/test/java/org/apache/camel/component/crypto/cms/util/ExchangeUtil.java => camel-http-common/src/test/java/org/apache/camel/http/common/HttpHelperTest.java} (56%)


[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 eb33736ab1ddc84b83147ebc19fefd8ce104d75b
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Wed Aug 21 15:19:23 2019 +0900

    CAMEL-13886: camel-servlet + camel-http4 with null body causes "Stream closed" IOException
---
 components/camel-http-common/pom.xml               |  5 +++
 .../org/apache/camel/http/common/HttpHelper.java   |  4 +-
 .../apache/camel/http/common/HttpHelperTest.java   | 50 ++++++++++++++++++++++
 3 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/components/camel-http-common/pom.xml b/components/camel-http-common/pom.xml
index 16e9d5e..6f690f4 100644
--- a/components/camel-http-common/pom.xml
+++ b/components/camel-http-common/pom.xml
@@ -84,6 +84,11 @@
       <version>${assertj-version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
 </project>
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
index c2d271c..6d7dae4 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
@@ -203,7 +203,7 @@ public final class HttpHelper {
      * @throws IOException is thrown if error reading response body
      */
     public static Object readRequestBodyFromInputStream(InputStream is, Exchange exchange) throws IOException {
-        if (is == null) {
+        if (is == null || is.available() <= 0) {
             return null;
         }
         boolean disableStreamCaching = false;
@@ -232,7 +232,7 @@ public final class HttpHelper {
      * @throws IOException is thrown if error reading response body
      */
     public static Object readResponseBodyFromInputStream(InputStream is, Exchange exchange) throws IOException {
-        if (is == null) {
+        if (is == null || is.available() <= 0) {
             return null;
         }
         // convert the input stream to StreamCache if the stream cache is not disabled
diff --git a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHelperTest.java b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHelperTest.java
new file mode 100644
index 0000000..0cfca20
--- /dev/null
+++ b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHelperTest.java
@@ -0,0 +1,50 @@
+/**
+ * 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.http.common;
+
+import java.io.IOException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class HttpHelperTest {
+
+    @Test
+    public void readRequestBodyFromServletRequest() throws IOException {
+        HttpServletRequest request = mock(HttpServletRequest.class);
+        ServletInputStream is = mock(ServletInputStream.class);
+        when(request.getInputStream()).thenReturn(is);
+        when(is.available()).thenReturn(0);
+
+        CamelContext context = new DefaultCamelContext();
+        Exchange exchange = new DefaultExchange(context);
+
+        assertNull(HttpHelper.readRequestBodyFromServletRequest(null, exchange));
+        assertNull(HttpHelper.readRequestBodyFromServletRequest(request, exchange));
+    }
+
+}


[camel] 02/02: Fix CS

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 63ec0ac5cc983d653e1b8171b98dd7bb14b25a68
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Wed Aug 21 15:23:44 2019 +0900

    Fix CS
---
 .../java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java  | 1 -
 1 file changed, 1 deletion(-)

diff --git a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java
index c2e79ca..01d987f 100644
--- a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java
+++ b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java
@@ -17,7 +17,6 @@
 package org.apache.camel.http.common;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.http.common.HttpHeaderFilterStrategy;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.DefaultExchange;
 import org.apache.camel.test.junit4.CamelTestSupport;