camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dval...@apache.org
Subject svn commit: r1326746 - in /camel/trunk/components/camel-spring-ws/src: main/java/org/apache/camel/component/spring/ws/ test/java/org/apache/camel/component/spring/ws/ test/resources/ test/resources/org/apache/camel/component/spring/ws/
Date Mon, 16 Apr 2012 19:03:25 GMT
Author: dvaleri
Date: Mon Apr 16 19:03:24 2012
New Revision: 1326746

URL: http://svn.apache.org/viewvc?rev=1326746&view=rev
Log:
[CAMEL-4279] [CAMEL-4998] Added support to Spring WS Producer for JSSE Configuration Util
and refactored risky code for setting connection timeout.

Added:
    camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/SSLContextParametersLocalRouteTest.java
  (with props)
    camel/trunk/components/camel-spring-ws/src/test/resources/localhost.ks
    camel/trunk/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/SSLContextParametersLocalRouteTest-context.xml
  (with props)
Modified:
    camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
    camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java
    camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ProducerRemoteRouteTimeOutTest.java

Modified: camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java?rev=1326746&r1=1326745&r2=1326746&view=diff
==============================================================================
--- camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
(original)
+++ camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
Mon Apr 16 19:03:24 2012
@@ -23,10 +23,11 @@ import org.apache.camel.component.spring
 import org.apache.camel.component.spring.ws.bean.CamelEndpointMapping;
 import org.apache.camel.component.spring.ws.type.EndpointMappingKey;
 import org.apache.camel.converter.jaxp.XmlConverter;
+import org.apache.camel.util.jsse.SSLContextParameters;
 import org.springframework.ws.client.core.WebServiceTemplate;
 
 public class SpringWebserviceConfiguration {
-
+    
     /* Producer configuration */
     private WebServiceTemplate webServiceTemplate;
     private String soapAction;
@@ -37,9 +38,10 @@ public class SpringWebserviceConfigurati
     private CamelEndpointMapping endpointMapping;
     private CamelEndpointDispatcher endpointDispatcher;
     private EndpointMappingKey endpointMappingKey;
+    private SSLContextParameters sslContextParameters;
 
     private XmlConverter xmlConverter;
-
+    
     public WebServiceTemplate getWebServiceTemplate() {
         return webServiceTemplate;
     }
@@ -101,6 +103,14 @@ public class SpringWebserviceConfigurati
     public void setEndpointMappingKey(EndpointMappingKey endpointMappingKey) {
         this.endpointMappingKey = endpointMappingKey;
     }
+    
+    public SSLContextParameters getSslContextParameters() {
+        return sslContextParameters;
+    }
+
+    public void setSslContextParameters(SSLContextParameters sslContextParameters) {
+        this.sslContextParameters = sslContextParameters;
+    }
 
     public CamelEndpointDispatcher getEndpointDispatcher() {
         return endpointDispatcher;

Modified: camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java?rev=1326746&r1=1326745&r2=1326746&view=diff
==============================================================================
--- camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java
(original)
+++ camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java
Mon Apr 16 19:03:24 2012
@@ -17,24 +17,21 @@
 package org.apache.camel.component.spring.ws;
 
 import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
 import java.net.HttpURLConnection;
 import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.security.GeneralSecurityException;
 
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
 import javax.xml.transform.Source;
 import javax.xml.transform.TransformerException;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.ExchangeHelper;
-import org.apache.camel.util.ReflectionHelper;
-import org.apache.camel.util.ReflectionHelper.FieldCallback;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -45,10 +42,12 @@ import org.springframework.ws.client.cor
 import org.springframework.ws.client.core.WebServiceTemplate;
 import org.springframework.ws.soap.addressing.client.ActionCallback;
 import org.springframework.ws.soap.client.core.SoapActionCallback;
+import org.springframework.ws.transport.WebServiceConnection;
 import org.springframework.ws.transport.WebServiceMessageSender;
+import org.springframework.ws.transport.http.AbstractHttpWebServiceMessageSender;
 import org.springframework.ws.transport.http.CommonsHttpMessageSender;
+import org.springframework.ws.transport.http.HttpUrlConnection;
 import org.springframework.ws.transport.http.HttpUrlConnectionMessageSender;
-import org.springframework.ws.transport.http.HttpsUrlConnectionMessageSender;
 
 public class SpringWebserviceProducer extends DefaultProducer {
 
@@ -74,7 +73,7 @@ public class SpringWebserviceProducer ex
         URI wsAddressingAction = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ADDRESSING_ACTION,
URI.class);
 
         // Populate the given (read) timeout if any
-        populateTimeout(getEndpoint().getConfiguration());
+        prepareMessageSenders(getEndpoint().getConfiguration());
 
         WebServiceMessageCallback callback = new DefaultWebserviceMessageCallback(soapAction,
wsAddressingAction, getEndpoint().getConfiguration());
         Object body = null;
@@ -89,104 +88,103 @@ public class SpringWebserviceProducer ex
         }
     }
 
-    private static void populateTimeout(SpringWebserviceConfiguration configuration) throws
Exception {
-        if (!(configuration.getTimeout() > -1)) {
+    private static void prepareMessageSenders(SpringWebserviceConfiguration configuration)
throws Exception {
+        // Skip this whole thing if none of the relevant config options are set.
+        if (!(configuration.getTimeout() > -1) && configuration.getSslContextParameters()
== null) {
             return;
         }
 
         WebServiceTemplate webServiceTemplate = configuration.getWebServiceTemplate();
 
-        // Can't use java.util.Arrays.asList() as it doesn't support the optional remove()
operation which we need here
-        List<WebServiceMessageSender> webServiceMessageSenders = new ArrayList<WebServiceMessageSender>(webServiceTemplate.getMessageSenders().length);
-        Collections.addAll(webServiceMessageSenders, webServiceTemplate.getMessageSenders());
-        for (WebServiceMessageSender webServiceMessageSender : webServiceMessageSenders)
{
-            if (webServiceMessageSender instanceof CommonsHttpMessageSender) {
-                setTimeOut((CommonsHttpMessageSender) webServiceMessageSender, configuration);
-            } else if (webServiceMessageSender instanceof HttpsUrlConnectionMessageSender)
{
-                // Should check HttpsUrlConnectionMessageSender beforehand as it extends
HttpUrlConnectionMessageSender
-                webServiceMessageSenders.remove(webServiceMessageSender);
-                webServiceMessageSenders.add(new CamelHttpsUrlConnectionMessageSender(configuration,
(HttpsUrlConnectionMessageSender) webServiceMessageSender));
-            } else if (webServiceMessageSender instanceof HttpUrlConnectionMessageSender)
{
-                webServiceMessageSenders.remove(webServiceMessageSender);
-                webServiceMessageSenders.add(new CamelHttpUrlConnectionMessageSender(configuration,
(HttpUrlConnectionMessageSender) webServiceMessageSender));
+        WebServiceMessageSender[] messageSenders = webServiceTemplate.getMessageSenders();
+        
+        for (int i = 0; i < messageSenders.length; i++) {
+            WebServiceMessageSender messageSender = messageSenders[i];
+            if (messageSender instanceof CommonsHttpMessageSender) {
+                if (configuration.getSslContextParameters() != null) {
+                    LOG.warn("Not applying SSLContextParameters based configuration to CommonsHttpMessageSender.
 "
+                             + "If you are using this MessageSender, which you are not by
default, you will need "
+                             + "to configure SSL using the Commons HTTP 3.x Protocol registry.");
+                }
+                
+                if (configuration.getTimeout() > -1) {
+                    ((CommonsHttpMessageSender)messageSender).setReadTimeout(configuration.getTimeout());
+                }
+            } else if (messageSender.getClass().equals(HttpUrlConnectionMessageSender.class))
{
+                // Only if exact match denoting likely use of default configuration.  We
don't want to get
+                // sub-classes that might have been otherwise injected.
+                messageSenders[i] = new AbstractHttpWebServiceMessageSenderDecorator((HttpUrlConnectionMessageSender)messageSender,
configuration);
             } else {
                 // For example this will be the case during unit-testing with the net.javacrumbs.spring-ws-test
API
-                LOG.warn("Ignoring the timeout option for {} as there's no provided API available
to populate it!", webServiceMessageSender);
+                LOG.warn("Ignoring the timeout and SSLContextParameters options for {}. 
You will need to configure "
+                        + "these options directly on your custom configured WebServiceMessageSender",
messageSender);
             }
         }
-
-        webServiceTemplate.setMessageSenders(webServiceMessageSenders.toArray(new WebServiceMessageSender[webServiceMessageSenders.size()]));
-    }
-
-    private static void setTimeOut(HttpURLConnection connection, SpringWebserviceConfiguration
configuration) {
-        connection.setReadTimeout(configuration.getTimeout());
     }
-
-    private static void setTimeOut(CommonsHttpMessageSender commonsHttpMessageSender, SpringWebserviceConfiguration
configuration) {
-        commonsHttpMessageSender.setReadTimeout(configuration.getTimeout());
-    }
-
-    protected static class CamelHttpUrlConnectionMessageSender extends HttpUrlConnectionMessageSender
{
-
+    
+    /**
+     * A decorator of {@link HttpUrlConnectionMessageSender} instances that can apply configuration
options
+     * from the Camel component/endpoint configuration without replacing the actual implementation
which may
+     * actually be an end-user implementation and not one of the built-in implementations.
+     */
+    protected static final class AbstractHttpWebServiceMessageSenderDecorator extends AbstractHttpWebServiceMessageSender
{
+        
+        private final AbstractHttpWebServiceMessageSender delegate;
+        
         private final SpringWebserviceConfiguration configuration;
-
-        CamelHttpUrlConnectionMessageSender(SpringWebserviceConfiguration configuration,
HttpUrlConnectionMessageSender webServiceMessageSender) {
+        
+        private SSLContext sslContext;
+        
+        public AbstractHttpWebServiceMessageSenderDecorator(AbstractHttpWebServiceMessageSender
delegate, SpringWebserviceConfiguration configuration) {
+            this.delegate = delegate;
             this.configuration = configuration;
-
-            // Populate the single acceptGzipEncoding property
-            setAcceptGzipEncoding(webServiceMessageSender.isAcceptGzipEncoding());
         }
 
         @Override
-        protected void prepareConnection(HttpURLConnection connection) throws IOException
{
-            super.prepareConnection(connection);
-
-            setTimeOut(connection, configuration);
-        }
-
-    }
-
-    protected static class CamelHttpsUrlConnectionMessageSender extends HttpsUrlConnectionMessageSender
{
-
-        private final SpringWebserviceConfiguration configuration;
-
-        CamelHttpsUrlConnectionMessageSender(SpringWebserviceConfiguration configuration,
final HttpsUrlConnectionMessageSender webServiceMessageSender) throws Exception {
-            this.configuration = configuration;
-
-            // Populate the single acceptGzipEncoding property beforehand as we have got
a proper set/is API for it
-            setAcceptGzipEncoding(webServiceMessageSender.isAcceptGzipEncoding());
-
-            // Populate the fields not having getXXX available on HttpsUrlConnectionMessageSender
-            ReflectionHelper.doWithFields(HttpsUrlConnectionMessageSender.class, new FieldCallback()
{
-
-                @Override
-                public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException
{
-                    if (Modifier.isStatic(field.getModifiers())) {
-                        return;
-                    }
-
-                    String fieldName = field.getName();
-                    if ("logger".equals(fieldName) || "acceptGzipEncoding".equals(fieldName))
{
-                        // skip them
-                        return;
+        public WebServiceConnection createConnection(URI uri) throws IOException {
+            WebServiceConnection wsc = delegate.createConnection(uri);
+            if (wsc instanceof HttpUrlConnection) {
+                HttpURLConnection connection = ((HttpUrlConnection)wsc).getConnection();
+                
+                if (configuration.getTimeout() > -1) {
+                    connection.setReadTimeout(configuration.getTimeout());
+                }
+                
+                if (configuration.getSslContextParameters() != null && connection
instanceof HttpsURLConnection) {
+                    try {
+                        synchronized (this) {
+                            if (sslContext == null) {
+                                sslContext = configuration.getSslContextParameters().createSSLContext();
+                            }
+                        }
+                    } catch (GeneralSecurityException e) {
+                        throw new RuntimeCamelException("Error creating SSLContext based
on SSLContextParameters.", e);
                     }
-
-                    field.setAccessible(true);
-                    Object value = field.get(webServiceMessageSender);
-                    field.set(CamelHttpsUrlConnectionMessageSender.this, value);
-                    LOG.trace("Populated the field {} with the value {}", fieldName, value);
+                    
+                    ((HttpsURLConnection) connection).setSSLSocketFactory(sslContext.getSocketFactory());
                 }
-
-            });
+            } else {
+                throw new RuntimeCamelException("Unsupported delegate.  Delegate must return
a org.springframework.ws.transport.http.HttpUrlConnection.  Found "
+                        + wsc.getClass());
+            }
+            
+            return wsc;
         }
 
         @Override
-        protected void prepareConnection(HttpURLConnection connection) throws IOException
{
-            super.prepareConnection(connection);
+        public boolean isAcceptGzipEncoding() {
+            return delegate.isAcceptGzipEncoding();
+        }
 
-            setTimeOut(connection, configuration);
+        @Override
+        public void setAcceptGzipEncoding(boolean acceptGzipEncoding) {
+            delegate.setAcceptGzipEncoding(acceptGzipEncoding);
         }
 
+        @Override
+        public boolean supports(URI uri) {
+            return delegate.supports(uri);
+        }
     }
 
     protected static class DefaultWebserviceMessageCallback implements WebServiceMessageCallback
{

Modified: camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ProducerRemoteRouteTimeOutTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ProducerRemoteRouteTimeOutTest.java?rev=1326746&r1=1326745&r2=1326746&view=diff
==============================================================================
--- camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ProducerRemoteRouteTimeOutTest.java
(original)
+++ camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ProducerRemoteRouteTimeOutTest.java
Mon Apr 16 19:03:24 2012
@@ -16,33 +16,19 @@
  */
 package org.apache.camel.component.spring.ws;
 
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
 import java.net.SocketTimeoutException;
-import java.security.SecureRandom;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.KeyManager;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManager;
 
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
-import org.apache.camel.component.spring.ws.SpringWebserviceProducer.CamelHttpUrlConnectionMessageSender;
-import org.apache.camel.component.spring.ws.SpringWebserviceProducer.CamelHttpsUrlConnectionMessageSender;
 
 import org.junit.Ignore;
 import org.junit.Test;
 
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
-import org.springframework.ws.transport.http.HttpUrlConnectionMessageSender;
-import org.springframework.ws.transport.http.HttpsUrlConnectionMessageSender;
 
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -107,53 +93,4 @@ public class ProducerRemoteRouteTimeOutT
 
         return hasThrowableInChain(throwable.getCause(), clazz);
     }
-
-    @Test
-    public void verifyTheFieldPopulationFromHttpUrlConnectionMessageSenderToCamelHttpUrlConnectionMessageSender()
throws Exception {
-        HttpUrlConnectionMessageSender fromMessageSender = new HttpUrlConnectionMessageSender();
-        fromMessageSender.setAcceptGzipEncoding(false);
-
-        CamelHttpUrlConnectionMessageSender toMessageSender = new CamelHttpUrlConnectionMessageSender(new
SpringWebserviceConfiguration(), fromMessageSender);
-        assertFalse("acceptGzipEncoding property didn't get populated properly!", toMessageSender.isAcceptGzipEncoding());
-
-        fromMessageSender.setAcceptGzipEncoding(true);
-        toMessageSender = new CamelHttpUrlConnectionMessageSender(new SpringWebserviceConfiguration(),
fromMessageSender);
-        assertTrue("acceptGzipEncoding property didn't get populated properly!", toMessageSender.isAcceptGzipEncoding());
-    }
-
-    @Test
-    public void verifyTheFieldPopulationFromHttpsUrlConnectionMessageSenderToCamelHttpsUrlConnectionMessageSender()
throws Exception {
-        HttpsUrlConnectionMessageSender fromMessageSender = new HttpsUrlConnectionMessageSender();
-        fromMessageSender.setAcceptGzipEncoding(false);
-        fromMessageSender.setHostnameVerifier(new HostnameVerifier() {
-
-            @Override
-            public boolean verify(String s, SSLSession sslsession) {
-                return false;
-            }
-
-        });
-        fromMessageSender.setKeyManagers(new KeyManager[] {new KeyManager() {
-        }});
-        fromMessageSender.setSecureRandom(new SecureRandom());
-        fromMessageSender.setSslProtocol("sslProtocol");
-        fromMessageSender.setSslProvider("sslProvider");
-        fromMessageSender.setTrustManagers(new TrustManager[] {new TrustManager() {
-        }});
-
-        CamelHttpsUrlConnectionMessageSender toMessageSender = new CamelHttpsUrlConnectionMessageSender(new
SpringWebserviceConfiguration(), fromMessageSender);
-
-        assertFalse("acceptGzipEncoding field didn't get populated properly!", toMessageSender.isAcceptGzipEncoding());
-        for (Field field : fromMessageSender.getClass().getDeclaredFields()) {
-            if (Modifier.isStatic(field.getModifiers())) {
-                continue;
-            }
-
-            field.setAccessible(true);
-            String fieldName = field.getName();
-
-            assertSame("The field '" + fieldName + "' didn't get populated properly!", field.get(fromMessageSender),
field.get(toMessageSender));
-        }
-    }
-
 }

Added: camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/SSLContextParametersLocalRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/SSLContextParametersLocalRouteTest.java?rev=1326746&view=auto
==============================================================================
--- camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/SSLContextParametersLocalRouteTest.java
(added)
+++ camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/SSLContextParametersLocalRouteTest.java
Mon Apr 16 19:03:24 2012
@@ -0,0 +1,110 @@
+/**
+ * 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.spring.ws;
+
+import javax.annotation.Resource;
+import javax.xml.transform.Source;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.StringSource;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+@ContextConfiguration
+public class SSLContextParametersLocalRouteTest extends AbstractJUnit4SpringContextTests
{
+
+    private final String stockQuoteWebserviceUri = "https://localhost";
+    private final String xmlRequestForGoogleStockQuote = "<GetQuote xmlns=\"http://www.webserviceX.NET/\"><symbol>GOOG</symbol></GetQuote>";
+
+    @Produce
+    private ProducerTemplate template;
+
+    @EndpointInject(uri = "mock:result")
+    private MockEndpoint resultEndpoint;
+    
+    @Resource
+    private int port;
+
+    @Test
+    public void consumeStockQuoteWebserviceWithDefaultTemplate() throws Exception {
+        Object result = template.requestBody("direct:stockQuoteWebserviceWithDefaultTemplate",
xmlRequestForGoogleStockQuote);
+
+        assertNotNull(result);
+        assertTrue(result instanceof Source);
+    }
+
+    @Test
+    public void consumeStockQuoteWebserviceAndPreserveHeaders() throws Exception {
+        resultEndpoint.expectedHeaderReceived("helloHeader", "hello world!");
+
+        Object result = template.requestBodyAndHeader("direct:stockQuoteWebserviceMock",
xmlRequestForGoogleStockQuote, "helloHeader", "hello world!");
+
+        assertNotNull(result);
+        resultEndpoint.assertIsSatisfied();
+    }
+
+    @Test
+    public void consumeStockQuoteWebservice() throws Exception {
+        Object result = template.requestBody("direct:stockQuoteWebservice", xmlRequestForGoogleStockQuote);
+
+        assertNotNull(result);
+        assertTrue(result instanceof Source);
+    }
+
+    @Test
+    public void consumeStockQuoteWebserviceWithCamelStringSourceInput() throws Exception
{
+        Object result = template.requestBody("direct:stockQuoteWebservice", new StringSource(xmlRequestForGoogleStockQuote));
+
+        assertNotNull(result);
+        assertTrue(result instanceof Source);
+    }
+
+    @Test
+    public void consumeStockQuoteWebserviceWithNonDefaultMessageFactory() throws Exception
{
+        Object result = template.requestBody("direct:stockQuoteWebserviceWithNonDefaultMessageFactory",
xmlRequestForGoogleStockQuote);
+
+        assertNotNull(result);
+        assertTrue(result instanceof Source);
+    }
+
+    @Test
+    public void consumeStockQuoteWebserviceAndConvertResult() throws Exception {
+        Object result = template.requestBody("direct:stockQuoteWebserviceAsString", xmlRequestForGoogleStockQuote);
+
+        assertNotNull(result);
+        assertTrue(result instanceof String);
+        String resultMessage = (String) result;
+        assertTrue(resultMessage.contains("Google Inc."));
+    }
+
+    @Test
+    public void consumeStockQuoteWebserviceAndProvideEndpointUriByHeader() throws Exception
{
+        Object result = template.requestBodyAndHeader("direct:stockQuoteWebserviceWithoutDefaultUri",
xmlRequestForGoogleStockQuote,
+                SpringWebserviceConstants.SPRING_WS_ENDPOINT_URI, stockQuoteWebserviceUri
+ ":" + port);
+
+        assertNotNull(result);
+        assertTrue(result instanceof String);
+        String resultMessage = (String) result;
+        assertTrue(resultMessage.contains("Google Inc."));
+    }
+}

Propchange: camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/SSLContextParametersLocalRouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-spring-ws/src/test/resources/localhost.ks
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-ws/src/test/resources/localhost.ks?rev=1326746&view=auto
==============================================================================
Files camel/trunk/components/camel-spring-ws/src/test/resources/localhost.ks (added) and camel/trunk/components/camel-spring-ws/src/test/resources/localhost.ks
Mon Apr 16 19:03:24 2012 differ

Added: camel/trunk/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/SSLContextParametersLocalRouteTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/SSLContextParametersLocalRouteTest-context.xml?rev=1326746&view=auto
==============================================================================
--- camel/trunk/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/SSLContextParametersLocalRouteTest-context.xml
(added)
+++ camel/trunk/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/SSLContextParametersLocalRouteTest-context.xml
Mon Apr 16 19:03:24 2012
@@ -0,0 +1,139 @@
+<?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.xsd
+         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+         
+         
+    <bean id="port"
+      class="org.apache.camel.test.AvailablePortFinder"
+      factory-method="getNextAvailable"/>
+
+    <camelContext xmlns="http://camel.apache.org/schema/spring">
+        <!-- producer routes (web service clients) -->
+        <route>
+            <from uri="direct:stockQuoteWebservice"/>
+            <to uri="spring-ws:https://localhost:#{port}?webServiceTemplate=#webServiceTemplate&amp;soapAction=http://www.stockquotes.edu/GetQuote&amp;sslContextParameters=#sslContextParameters"/>
+        </route>
+        <route>
+            <from uri="direct:stockQuoteWebserviceMock"/>
+            <pipeline>
+                <to uri="spring-ws:https://localhost:#{port}?webServiceTemplate=#webServiceTemplate&amp;soapAction=http://www.stockquotes.edu/GetQuote&amp;sslContextParameters=#sslContextParameters"/>
+                <to uri="mock:result" />
+            </pipeline>
+        </route>
+        <route>
+            <from uri="direct:stockQuoteWebserviceAsString"/>
+            <to uri="spring-ws:https://localhost:#{port}?webServiceTemplate=#webServiceTemplate&amp;soapAction=http://www.stockquotes.edu/GetQuote&amp;sslContextParameters=#sslContextParameters"/>
+            <convertBodyTo type="java.lang.String"/>
+        </route>
+        <route>
+            <from uri="direct:stockQuoteWebserviceWithDefaultTemplate"/>
+            <to uri="spring-ws:https://localhost:#{port}?webServiceTemplate=#webServiceTemplate&amp;soapAction=http://www.stockquotes.edu/GetQuote&amp;sslContextParameters=#sslContextParameters"/>
+        </route>
+        <route>
+            <from uri="direct:stockQuoteWebserviceWithNonDefaultMessageFactory"/>
+            <to uri="spring-ws:https://localhost:#{port}?webServiceTemplate=#webServiceTemplate&amp;soapAction=http://www.stockquotes.edu/GetQuote&amp;messageFactory=#messageFactory&amp;sslContextParameters=#sslContextParameters"/>
+        </route>
+        <route>
+            <from uri="direct:stockQuoteWebserviceWithoutDefaultUri"/>
+            <to uri="spring-ws:https://dummy?webServiceTemplate=#webServiceTemplate&amp;soapAction=http://www.stockquotes.edu/GetQuote&amp;sslContextParameters=#sslContextParameters"/>
+            <convertBodyTo type="java.lang.String"/>
+        </route>
+        <!-- consumer route (providing the actual web service) -->
+        <route>
+            <from uri="spring-ws:soapaction:http://www.stockquotes.edu/GetQuote?endpointMapping=#endpointMapping"/>
+            <to uri="responseProcessor"/>
+        </route>
+    </camelContext>
+    
+    <sslContextParameters xmlns="http://camel.apache.org/schema/spring"
+      id="sslContextParameters"
+      sessionTimeout="1"
+      secureSocketProtocol="TLS">
+    
+      <keyManagers
+          keyPassword="changeit">
+        <keyStore
+            resource="localhost.ks"
+            password="changeit"/>
+      </keyManagers>
+    
+      <trustManagers>
+        <keyStore
+            resource="localhost.ks"
+            password="changeit"/>
+      </trustManagers>
+
+    </sslContextParameters>
+
+    <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
+
+    <bean id="endpointMapping"
+          class="org.apache.camel.component.spring.ws.bean.CamelEndpointMapping"/>
+
+    <bean id="responseProcessor"
+          class="org.apache.camel.component.spring.ws.StockQuoteResponseProcessor"/>
+
+    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
+        <property name="defaultUri" value="https://localhost:#{port}/GetQuote"/>
+    </bean>
+    
+    <bean id="httpServer" class="sun.net.httpserver.HttpsServerImpl" init-method="start">
+      <constructor-arg>
+        <bean class="java.net.InetSocketAddress">
+          <constructor-arg value="localhost"/>
+          <constructor-arg ref="port"/>
+        </bean>
+      </constructor-arg>
+      <constructor-arg value="0"/>
+      <property name="httpsConfigurator">
+        <bean class="com.sun.net.httpserver.HttpsConfigurator">
+          <constructor-arg>
+            <bean factory-bean="sslContextParameters" factory-method="createSSLContext"/>
+          </constructor-arg>
+        </bean>
+      </property>
+    </bean>
+
+  <bean id="httpContext"
+    class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+    <property name="targetObject" ref="httpServer" />
+    <property name="targetMethod" value="createContext" />
+    <property name="arguments">
+      <array>
+        <value>/</value>
+        <bean class="org.springframework.ws.transport.http.WebServiceMessageReceiverHttpHandler">
+          <property name="messageFactory" ref="messageFactory"/>
+          <property name="messageReceiver">
+            <bean class="org.springframework.ws.soap.server.SoapMessageDispatcher">
+              <property name="endpointMappings">
+                <list>
+                  <ref bean="endpointMapping"/>
+                </list>
+              </property>
+            </bean>
+          </property>
+        </bean>
+      </array>
+    </property>
+  </bean>
+
+</beans>
\ No newline at end of file

Propchange: camel/trunk/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/SSLContextParametersLocalRouteTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message