Repository: camel Updated Branches: refs/heads/master ccf5b2823 -> ba5c56f55
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/10f3ff66 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/10f3ff66 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/10f3ff66 Branch: refs/heads/master Commit: 10f3ff6616599fa849a95cd75bc6d9b7dd331153 Parents: ccf5b28 Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Jul 17 09:36:14 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Jul 17 09:36:14 2015 +0200 ---------------------------------------------------------------------- .../http/NettyHttpSSLHandshakeErrorTest.java | 60 +++++++++++++++++++ .../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 .../netty/handlers/ClientChannelHandler.java | 9 ++- 6 files changed, 67 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/10f3ff66/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLHandshakeErrorTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLHandshakeErrorTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLHandshakeErrorTest.java new file mode 100644 index 0000000..b6b45b5 --- /dev/null +++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLHandshakeErrorTest.java @@ -0,0 +1,60 @@ +/** + * 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.netty.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("netty-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("netty-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()); + assertEquals("exception expected", javax.net.ssl.SSLHandshakeException.class, ex.getClass()); + + assertMockEndpointsSatisfied(); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/10f3ff66/components/camel-netty-http/src/test/resources/jsse/client-keystore.jks ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/test/resources/jsse/client-keystore.jks b/components/camel-netty-http/src/test/resources/jsse/client-keystore.jks new file mode 100644 index 0000000..bc744f9 Binary files /dev/null and b/components/camel-netty-http/src/test/resources/jsse/client-keystore.jks differ http://git-wip-us.apache.org/repos/asf/camel/blob/10f3ff66/components/camel-netty-http/src/test/resources/jsse/client-truststore.jks ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/test/resources/jsse/client-truststore.jks b/components/camel-netty-http/src/test/resources/jsse/client-truststore.jks new file mode 100644 index 0000000..216bddb Binary files /dev/null and b/components/camel-netty-http/src/test/resources/jsse/client-truststore.jks differ http://git-wip-us.apache.org/repos/asf/camel/blob/10f3ff66/components/camel-netty-http/src/test/resources/jsse/server-keystore.jks ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/test/resources/jsse/server-keystore.jks b/components/camel-netty-http/src/test/resources/jsse/server-keystore.jks new file mode 100644 index 0000000..22fd44e Binary files /dev/null and b/components/camel-netty-http/src/test/resources/jsse/server-keystore.jks differ http://git-wip-us.apache.org/repos/asf/camel/blob/10f3ff66/components/camel-netty-http/src/test/resources/jsse/server-truststore.jks ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/test/resources/jsse/server-truststore.jks b/components/camel-netty-http/src/test/resources/jsse/server-truststore.jks new file mode 100644 index 0000000..2447028 Binary files /dev/null and b/components/camel-netty-http/src/test/resources/jsse/server-truststore.jks differ http://git-wip-us.apache.org/repos/asf/camel/blob/10f3ff66/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java ---------------------------------------------------------------------- diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java index 7a6d31f..c314e39 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java @@ -83,8 +83,13 @@ public class ClientChannelHandler extends SimpleChannelUpstreamHandler { // 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(exceptionEvent.getChannel());