You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2009/02/11 15:21:26 UTC

svn commit: r743345 - in /camel/trunk/components/camel-jetty: ./ src/test/java/org/apache/camel/component/jetty/ src/test/resources/org/ src/test/resources/org/apache/ src/test/resources/org/apache/camel/ src/test/resources/org/apache/camel/component/ ...

Author: janstey
Date: Wed Feb 11 14:21:25 2009
New Revision: 743345

URL: http://svn.apache.org/viewvc?rev=743345&view=rev
Log:
Add Spring example for https connection using jetty

Added:
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java   (with props)
    camel/trunk/components/camel-jetty/src/test/resources/org/
    camel/trunk/components/camel-jetty/src/test/resources/org/apache/
    camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/
    camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/
    camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/
    camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml   (with props)
Modified:
    camel/trunk/components/camel-jetty/pom.xml

Modified: camel/trunk/components/camel-jetty/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/pom.xml?rev=743345&r1=743344&r2=743345&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/pom.xml (original)
+++ camel/trunk/components/camel-jetty/pom.xml Wed Feb 11 14:21:25 2009
@@ -59,6 +59,17 @@
       <type>test-jar</type>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-spring</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>    
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-spring</artifactId>
+      <scope>test</scope>
+    </dependency>
     <!-- to allow Spring annotations (jmx) to be tested -->
     <dependency>
       <groupId>org.springframework</groupId>

Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java?rev=743345&view=auto
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java Wed Feb 11 14:21:25 2009
@@ -0,0 +1,122 @@
+/**
+ * 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.jetty;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.SocketException;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+
+public class SpringHttpsRouteTest extends ContextTestSupport {
+    private static final String NULL_VALUE_MARKER = ContextTestSupport.class.getCanonicalName();
+    protected String expectedBody = "<hello>world!</hello>";
+    protected String pwd = "changeit";
+    protected Properties originalValues = new Properties();
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();        
+        // ensure jsse clients can validate the self signed dummy localhost cert, 
+        // use the server keystore as the trust store for these tests
+        URL trustStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
+        setSystemProp("javax.net.ssl.trustStore", trustStoreUrl.getPath());
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        restoreSystemProperties();
+        super.tearDown();
+        JettyHttpComponent component = context.getComponent("jetty", JettyHttpComponent.class);
+        component.stop();    
+    }
+
+    private void setSystemProp(String key, String value) {
+        String originalValue = System.setProperty(key, value);
+        originalValues.put(key, originalValue != null ? originalValue : NULL_VALUE_MARKER);
+    }
+
+    private void restoreSystemProperties() {
+        for (Object key : originalValues.keySet()) {
+            Object value = (String) originalValues.get(key);  
+            if (NULL_VALUE_MARKER.equals(value)) {
+                System.getProperties().remove(key);    
+            } else {
+                System.setProperty((String)key, (String)value);
+            }
+        }
+    }
+
+    public void testEndpoint() throws Exception {
+        MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
+        mockEndpoint.expectedBodiesReceived(expectedBody);
+
+        invokeHttpEndpoint();
+
+        mockEndpoint.assertIsSatisfied();
+        List<Exchange> list = mockEndpoint.getReceivedExchanges();
+        Exchange exchange = list.get(0);
+        assertNotNull("exchange", exchange);
+
+        Message in = exchange.getIn();
+        assertNotNull("in", in);
+
+        Map<String, Object> headers = in.getHeaders();
+
+        log.info("Headers: " + headers);
+
+        assertTrue("Should be more than one header but was: " + headers, headers.size() > 0);
+    }
+    
+    
+    public void testEndpointWithoutHttps() {
+        MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);    
+        try {
+            template.sendBodyAndHeader("jetty:http://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
+            fail("expect exception on access to https endpoint via http");
+        } catch (RuntimeCamelException expected) {
+        }
+        assertTrue("mock endpoint was not called", mockEndpoint.getExchanges().isEmpty());
+    }
+
+
+    
+    protected void invokeHttpEndpoint() throws IOException {
+        template.sendBodyAndHeader("jetty:https://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, "org/apache/camel/component/jetty/jetty-https.xml");
+    }
+}
+

Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml?rev=743345&view=auto
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml (added)
+++ camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml Wed Feb 11 14:21:25 2009
@@ -0,0 +1,37 @@
+<?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"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+  <bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent">
+    <property name="sslPassword" value="changeit"/>
+    <property name="sslKeyPassword" value="changeit"/>
+    <property name="keystore" value="src/test/resources/jsse/localhost.ks"/>
+  </bean>  
+    
+  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+    <route>
+      <from uri="jetty:https://localhost:9080/test"/>
+      <to uri="mock:a"/>
+    </route>
+  </camelContext>
+
+</beans>

Propchange: camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml
------------------------------------------------------------------------------
    svn:eol-style = native