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 2013/08/01 19:44:00 UTC
[2/3] git commit: Added camel-netty-http SSL unit test using XML DSL
Added camel-netty-http SSL unit test using XML DSL
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/337c2718
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/337c2718
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/337c2718
Branch: refs/heads/master
Commit: 337c27181a80097616e0b4bccd96b2f122137988
Parents: 87ccdd3
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Aug 1 19:01:41 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Aug 1 19:01:41 2013 +0200
----------------------------------------------------------------------
.../netty/http/SpringNettyHttpSSLTest.java | 79 ++++++++++++++++++++
.../netty/http/SpringNettyHttpSSLTest.xml | 62 +++++++++++++++
2 files changed, 141 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/337c2718/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/SpringNettyHttpSSLTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/SpringNettyHttpSSLTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/SpringNettyHttpSSLTest.java
new file mode 100644
index 0000000..39ff57a
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/SpringNettyHttpSSLTest.java
@@ -0,0 +1,79 @@
+/**
+ * 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 java.net.URL;
+import javax.annotation.Resource;
+
+import junit.framework.TestCase;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"/org/apache/camel/component/netty/http/SpringNettyHttpSSLTest.xml"})
+public class SpringNettyHttpSSLTest extends TestCase {
+
+ @Produce
+ private ProducerTemplate template;
+
+ @EndpointInject(uri = "mock:input")
+ private MockEndpoint mockEndpoint;
+
+ private Integer port;
+
+ public Integer getPort() {
+ return port;
+ }
+
+ @Resource(name = "dynaPort")
+ public void setPort(Integer port) {
+ this.port = port;
+ }
+
+ @BeforeClass
+ public static void setUpJaas() throws Exception {
+ // ensure jsse clients can validate the self signed dummy localhost cert,
+ // use the server keystore as the trust store for these tests
+ URL trustStoreUrl = NettyHttpSSLTest.class.getClassLoader().getResource("jsse/localhost.ks");
+ System.setProperty("javax.net.ssl.trustStore", trustStoreUrl.toURI().getPath());
+ }
+
+ @AfterClass
+ public static void tearDownJaas() throws Exception {
+ System.clearProperty("java.security.auth.login.config");
+ }
+
+ @Test
+ public void testSSLInOutWithNettyConsumer() throws Exception {
+ mockEndpoint.expectedBodiesReceived("Hello World");
+
+ String out = template.requestBody("https://localhost:" + getPort(), "Hello World", String.class);
+ assertEquals("Bye World", out);
+
+ mockEndpoint.assertIsSatisfied();
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/337c2718/components/camel-netty-http/src/test/resources/org/apache/camel/component/netty/http/SpringNettyHttpSSLTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/resources/org/apache/camel/component/netty/http/SpringNettyHttpSSLTest.xml b/components/camel-netty-http/src/test/resources/org/apache/camel/component/netty/http/SpringNettyHttpSSLTest.xml
new file mode 100644
index 0000000..152b397
--- /dev/null
+++ b/components/camel-netty-http/src/test/resources/org/apache/camel/component/netty/http/SpringNettyHttpSSLTest.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:camel="http://camel.apache.org/schema/spring"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <bean id="dynaPort" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+ <property name="targetClass">
+ <value>org.apache.camel.test.AvailablePortFinder</value>
+ </property>
+ <property name="targetMethod">
+ <value>getNextAvailable</value>
+ </property>
+ <property name="arguments">
+ <list>
+ <value>9000</value>
+ </list>
+ </property>
+ </bean>
+
+ <camel:sslContextParameters id="mySsl">
+ <camel:keyManagers keyPassword="changeit">
+ <camel:keyStore resource="jsse/localhost.ks" password="changeit"/>
+ </camel:keyManagers>
+ <camel:trustManagers>
+ <camel:keyStore resource="jsse/localhost.ks" password="changeit"/>
+ </camel:trustManagers>
+ </camel:sslContextParameters>
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <endpoint id="input1" uri="netty-http:https://0.0.0.0:#{dynaPort}?ssl=true&sslContextParameters=#mySsl"/>
+
+ <route>
+ <from ref="input1"/>
+ <to uri="mock:input"/>
+ <transform>
+ <simple>Bye World</simple>
+ </transform>
+ </route>
+
+ </camelContext>
+
+</beans>