You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/07/17 09:37:25 UTC

[2/3] camel git commit: CAMEL-8946: camel-netty may hide exception. Thanks to Joe Qiang Luo for unit test

CAMEL-8946: camel-netty may hide exception. Thanks to Joe Qiang Luo for unit test


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6473653e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6473653e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6473653e

Branch: refs/heads/master
Commit: 6473653e65dc73a0bf88804211689898cc2614e2
Parents: 10f3ff6
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Jul 17 09:42:16 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jul 17 09:42:16 2015 +0200

----------------------------------------------------------------------
 .../http/NettyHttpSSLHandshakeErrorTest.java    |  61 +++++++++++++++++++
 .../src/test/resources/jsse/client-keystore.jks | Bin 0 -> 1344 bytes
 .../test/resources/jsse/client-truststore.jks   | Bin 0 -> 639 bytes
 .../src/test/resources/jsse/server-keystore.jks | Bin 0 -> 1345 bytes
 .../test/resources/jsse/server-truststore.jks   | Bin 0 -> 639 bytes
 .../netty4/handlers/ClientChannelHandler.java   |   9 ++-
 6 files changed, 68 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6473653e/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSSLHandshakeErrorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSSLHandshakeErrorTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSSLHandshakeErrorTest.java
new file mode 100644
index 0000000..f917d48
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSSLHandshakeErrorTest.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.netty4.http;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultExchange;
+import org.junit.Test;
+
+public class NettyHttpSSLHandshakeErrorTest extends BaseNettyTest {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testHttpsHandshakeError() throws Exception {
+        // ibm jdks dont have sun security algorithms
+        if (isJavaVendor("ibm")) {
+            return;
+        }
+
+        getMockEndpoint("mock:target").expectedMessageCount(0);
+
+        context.addRoutes(new RouteBuilder() {
+            public void configure() {
+                from("netty4-http:https://localhost:{{port}}?ssl=true&needClientAuth=true&keyStoreFormat=JKS&passphrase=storepassword&keyStoreResource=jsse/server-keystore.jks&trustStoreResource=jsse/server-truststore.jks")
+                        .to("mock:target");
+            }
+        });
+        context.start();
+
+        DefaultExchange exchange = new DefaultExchange(context);
+
+        Exchange response = template.send("netty4-http:https://localhost:{{port}}?requestTimeout=10000&throwExceptionOnFailure=false&ssl=true&keyStoreFormat=JKS&passphrase=storepassword&keyStoreResource=jsse/client-keystore.jks&trustStoreResource=jsse/server-truststore.jks", exchange);
+
+        Exception ex = response.getException();
+
+        assertTrue("should have failed", response.isFailed());
+        assertNotNull(ex.getCause());
+        assertEquals("exception expected", javax.net.ssl.SSLHandshakeException.class, ex.getCause().getClass());
+
+        assertMockEndpointsSatisfied();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/6473653e/components/camel-netty4-http/src/test/resources/jsse/client-keystore.jks
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/resources/jsse/client-keystore.jks b/components/camel-netty4-http/src/test/resources/jsse/client-keystore.jks
new file mode 100644
index 0000000..bc744f9
Binary files /dev/null and b/components/camel-netty4-http/src/test/resources/jsse/client-keystore.jks differ

http://git-wip-us.apache.org/repos/asf/camel/blob/6473653e/components/camel-netty4-http/src/test/resources/jsse/client-truststore.jks
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/resources/jsse/client-truststore.jks b/components/camel-netty4-http/src/test/resources/jsse/client-truststore.jks
new file mode 100644
index 0000000..216bddb
Binary files /dev/null and b/components/camel-netty4-http/src/test/resources/jsse/client-truststore.jks differ

http://git-wip-us.apache.org/repos/asf/camel/blob/6473653e/components/camel-netty4-http/src/test/resources/jsse/server-keystore.jks
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/resources/jsse/server-keystore.jks b/components/camel-netty4-http/src/test/resources/jsse/server-keystore.jks
new file mode 100644
index 0000000..22fd44e
Binary files /dev/null and b/components/camel-netty4-http/src/test/resources/jsse/server-keystore.jks differ

http://git-wip-us.apache.org/repos/asf/camel/blob/6473653e/components/camel-netty4-http/src/test/resources/jsse/server-truststore.jks
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/resources/jsse/server-truststore.jks b/components/camel-netty4-http/src/test/resources/jsse/server-truststore.jks
new file mode 100644
index 0000000..2447028
Binary files /dev/null and b/components/camel-netty4-http/src/test/resources/jsse/server-truststore.jks differ

http://git-wip-us.apache.org/repos/asf/camel/blob/6473653e/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/handlers/ClientChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/handlers/ClientChannelHandler.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/handlers/ClientChannelHandler.java
index fb71a88..28d6e22 100644
--- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/handlers/ClientChannelHandler.java
+++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/handlers/ClientChannelHandler.java
@@ -77,8 +77,13 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<Object> {
 
         // the state may not be set
         if (exchange != null && callback != null) {
-            // set the cause on the exchange
-            exchange.setException(cause);
+            Throwable initialCause = exchange.getException();
+            if (initialCause != null && initialCause.getCause() == null) {
+                initialCause.initCause(cause);
+            } else {
+                // set the cause on the exchange
+                exchange.setException(cause);
+            }
 
             // close channel in case an exception was thrown
             NettyHelper.close(ctx.channel());