servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r396901 - in /incubator/servicemix/trunk/servicemix-http/src: main/java/org/apache/servicemix/http/ main/java/org/apache/servicemix/http/processors/ test/java/org/apache/servicemix/http/ test/resources/org/apache/servicemix/http/
Date Tue, 25 Apr 2006 15:52:03 GMT
Author: gnodet
Date: Tue Apr 25 08:52:01 2006
New Revision: 396901

URL: http://svn.apache.org/viewcvs?rev=396901&view=rev
Log:
SM-372: HTTPS support for the servicemix-http component
Patch provided by Mike Gerdes and enhanced to support client side https and to test endpoints
for incompatible ssl parameters.
Need to check why the test case is failing (out of date certificate ?)

Added:
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/SslParameters.java
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/CommonsHttpSSLSocketFactory.java
    incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/client.keystore
  (with props)
    incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/server.keystore
  (with props)
Modified:
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpProcessor.java
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
    incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
    incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java
    incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/spring.xml

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java?rev=396901&r1=396900&r2=396901&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
Tue Apr 25 08:52:01 2006
@@ -49,7 +49,22 @@
     protected ExtensibilityElement binding;
     protected String locationURI;
     protected Map wsdls = new HashMap();
+    protected SslParameters ssl;
     
+    /**
+     * @return Returns the ssl.
+     */
+    public SslParameters getSsl() {
+        return ssl;
+    }
+
+    /**
+     * @param ssl The ssl to set.
+     */
+    public void setSsl(SslParameters ssl) {
+        this.ssl = ssl;
+    }
+
     public ExtensibilityElement getBinding() {
         return binding;
     }

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpProcessor.java?rev=396901&r1=396900&r2=396901&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpProcessor.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpProcessor.java
Tue Apr 25 08:52:01 2006
@@ -20,5 +20,7 @@
 
 public interface HttpProcessor {
 
+    SslParameters getSsl();
+    
     void process(HttpServletRequest request, HttpServletResponse response) throws Exception;
 }

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java?rev=396901&r1=396900&r2=396901&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java
Tue Apr 25 08:52:01 2006
@@ -27,6 +27,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import javax.jbi.JBIException;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -40,6 +41,7 @@
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.handler.AbstractHandler;
 import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.security.SslSocketConnector;
 import org.mortbay.jetty.servlet.ServletHandler;
 import org.mortbay.jetty.servlet.ServletHolder;
 import org.mortbay.jetty.servlet.ServletMapping;
@@ -47,6 +49,7 @@
 import org.mortbay.thread.ThreadPool;
 import org.mortbay.util.ByteArrayISO8859Writer;
 import org.mortbay.util.StringUtil;
+import org.springframework.core.io.ClassPathResource;
 
 public class ServerManager {
 
@@ -55,12 +58,14 @@
     private Map servers;
     private HttpConfiguration configuration;
     private ThreadPool threadPool;
+    private Map sslParams;
     
     protected void init() throws Exception {
         if (configuration == null) {
             configuration = new HttpConfiguration();
         }
         servers = new HashMap();
+        sslParams = new HashMap();
         BoundedThreadPool btp = new BoundedThreadPool();
         btp.setMaxThreads(this.configuration.getJettyThreadPoolSize());
         threadPool = btp;
@@ -90,7 +95,13 @@
         URL url = new URL(strUrl);
         Server server = getServer(url);
         if (server == null) {
-            server = createServer(url);
+            server = createServer(url, processor.getSsl());
+        } else {
+            // Check ssl params
+            SslParameters ssl = (SslParameters) sslParams.get(getKey(url));
+            if (ssl != null && !ssl.equals(processor.getSsl())) {
+                throw new Exception("An https server is already created on port " + url.getPort()
+ " but SSL parameters do not match");
+            }
         }
         String path = url.getPath();
         if (!path.startsWith("/")) {
@@ -160,27 +171,75 @@
     }
 
     protected Server getServer(URL url) {
-        String key = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort();
-        Server server = (Server) servers.get(key);
+        Server server = (Server) servers.get(getKey(url));
         return server;
     }
     
-    protected Server createServer(URL url) throws Exception {
-        if (!url.getProtocol().equals("http")) {
+    protected String getKey(URL url) {
+        String key = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort();
+        return key;
+    }
+    
+    protected Server createServer(URL url, SslParameters ssl) throws Exception {
+        boolean isSsl = false;
+        if (url.getProtocol().equals("https")) {
+            // TODO: put ssl default information on HttpConfiguration
+            if (ssl == null) {
+                throw new IllegalArgumentException("https protocol required but no ssl parameters
found");
+            }
+            isSsl = true;
+        } else if (!url.getProtocol().equals("http")) {
             // TODO: handle https ?
             throw new UnsupportedOperationException("Protocol " + url.getProtocol() + " is
not supported");
         }
         // Create a new server
-        String connectorClassName = configuration.getJettyConnectorClassName();
         Connector connector;
-        try {
-            connector = (Connector) Class.forName(connectorClassName).newInstance();
-        } catch (Exception e) {
-            logger.warn("Could not create a jetty connector of class '" + connectorClassName
+ "'. Defaulting to " + HttpConfiguration.DEFAULT_JETTY_CONNECTOR_CLASS_NAME);
-            if (logger.isDebugEnabled()) {
-                logger.debug("Reason: " + e.getMessage(), e);
+        if (isSsl) {
+            String keyStore = ssl.getKeyStore();
+            if (keyStore == null) {
+                keyStore = System.getProperty("javax.net.ssl.keyStore", "");
+                if (keyStore == null) {
+                    throw new IllegalArgumentException("keyStore or system property javax.net.ssl.keyStore
must be set");
+                }
+            }
+            if (keyStore.startsWith("classpath:")) {
+                try {
+                    String res = keyStore.substring(10);
+                    URL resurl = new ClassPathResource(res).getURL();
+                    keyStore = resurl.toString();
+                } catch (IOException e) {
+                    throw new JBIException("Unable to find keystore " + keyStore, e);
+                }
+            }
+            String keyStorePassword = ssl.getKeyStorePassword();
+            if (keyStorePassword == null) {
+                keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
+                if (keyStorePassword == null) {
+                    throw new IllegalArgumentException("keyStorePassword or system property
javax.net.ssl.keyStorePassword must be set");
+                }
+            }
+            SslSocketConnector sslConnector = new SslSocketConnector();
+            sslConnector.setAlgorithm(ssl.getAlgorithm());
+            sslConnector.setProtocol(ssl.getProtocol());
+            sslConnector.setConfidentialPort(url.getPort());
+            sslConnector.setPassword(ssl.getKeyStorePassword());
+            sslConnector.setKeyPassword(ssl.getKeyPassword() != null ? ssl.getKeyPassword()
: keyStorePassword);
+            sslConnector.setKeystore(keyStore);
+            sslConnector.setKeystoreType(ssl.getKeyStoreType());
+            sslConnector.setNeedClientAuth(ssl.isNeedClientAuth());
+            sslConnector.setWantClientAuth(ssl.isWantClientAuth());
+            connector = sslConnector;
+        } else {
+            String connectorClassName = configuration.getJettyConnectorClassName();
+            try {
+                connector = (Connector) Class.forName(connectorClassName).newInstance();
+            } catch (Exception e) {
+                logger.warn("Could not create a jetty connector of class '" + connectorClassName
+ "'. Defaulting to " + HttpConfiguration.DEFAULT_JETTY_CONNECTOR_CLASS_NAME);
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Reason: " + e.getMessage(), e);
+                }
+                connector = (Connector) Class.forName(HttpConfiguration.DEFAULT_JETTY_CONNECTOR_CLASS_NAME).newInstance();
             }
-            connector = (Connector) Class.forName(HttpConfiguration.DEFAULT_JETTY_CONNECTOR_CLASS_NAME).newInstance();
         }
         connector.setHost(url.getHost());
         connector.setPort(url.getPort());
@@ -190,8 +249,8 @@
         server.setNotFoundHandler(new DisplayServiceHandler());
         connector.start();
         server.start();
-        String key = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort();
-        servers.put(key, server);
+        servers.put(getKey(url), server);
+        sslParams.put(getKey(url), isSsl ? ssl : null);
         return server;
     }
 

Added: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/SslParameters.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/SslParameters.java?rev=396901&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/SslParameters.java
(added)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/SslParameters.java
Tue Apr 25 08:52:01 2006
@@ -0,0 +1,217 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.http;
+
+/**
+ * This class contains all parameters needed to create an SSL server or client
+ * socket.
+ *  
+ * @author gnodet
+ * @org.apache.xbean.XBean 
+ */
+public class SslParameters {
+
+    private String keyPassword;
+    private String keyStore;
+    private String keyStorePassword;
+    private String keyStoreType = "JKS"; // type of the key store
+    private String trustStore;
+    private String trustStorePassword;
+    private String trustStoreType = "JKS";
+    private String protocol = "TLS";
+    private String algorithm = "SunX509"; // cert algorithm
+    private boolean wantClientAuth = false;
+    private boolean needClientAuth = false;
+    
+    /**
+     * @return Returns the algorithm.
+     */
+    public String getAlgorithm() {
+        return algorithm;
+    }
+    /**
+     * @param algorithm The algorithm to set.
+     */
+    public void setAlgorithm(String algorithm) {
+        this.algorithm = algorithm;
+    }
+    /**
+     * @return Returns the keyPassword.
+     */
+    public String getKeyPassword() {
+        return keyPassword;
+    }
+    /**
+     * @param keyPassword The keyPassword to set.
+     */
+    public void setKeyPassword(String keyPassword) {
+        this.keyPassword = keyPassword;
+    }
+    /**
+     * @return Returns the keyStore.
+     */
+    public String getKeyStore() {
+        return keyStore;
+    }
+    /**
+     * @param keyStore The keyStore to set.
+     */
+    public void setKeyStore(String keyStore) {
+        this.keyStore = keyStore;
+    }
+    /**
+     * @return Returns the keyStorePassword.
+     */
+    public String getKeyStorePassword() {
+        return keyStorePassword;
+    }
+    /**
+     * @param keyStorePassword The keyStorePassword to set.
+     */
+    public void setKeyStorePassword(String keyStorePassword) {
+        this.keyStorePassword = keyStorePassword;
+    }
+    /**
+     * @return Returns the keyStoreType.
+     */
+    public String getKeyStoreType() {
+        return keyStoreType;
+    }
+    /**
+     * @param keyStoreType The keyStoreType to set.
+     */
+    public void setKeyStoreType(String keyStoreType) {
+        this.keyStoreType = keyStoreType;
+    }
+    /**
+     * @return Returns the needClientAuth.
+     */
+    public boolean isNeedClientAuth() {
+        return needClientAuth;
+    }
+    /**
+     * @param needClientAuth The needClientAuth to set.
+     */
+    public void setNeedClientAuth(boolean needClientAuth) {
+        this.needClientAuth = needClientAuth;
+    }
+    /**
+     * @return Returns the protocol.
+     */
+    public String getProtocol() {
+        return protocol;
+    }
+    /**
+     * @param protocol The protocol to set.
+     */
+    public void setProtocol(String protocol) {
+        this.protocol = protocol;
+    }
+    /**
+     * @return Returns the wantClientAuth.
+     */
+    public boolean isWantClientAuth() {
+        return wantClientAuth;
+    }
+    /**
+     * @param wantClientAuth The wantClientAuth to set.
+     */
+    public void setWantClientAuth(boolean wantClientAuth) {
+        this.wantClientAuth = wantClientAuth;
+    }
+    /**
+     * @return Returns the trustStore.
+     */
+    public String getTrustStore() {
+        return trustStore;
+    }
+    /**
+     * @param trustStore The trustStore to set.
+     */
+    public void setTrustStore(String trustStore) {
+        this.trustStore = trustStore;
+    }
+    /**
+     * @return Returns the trustStorePassword.
+     */
+    public String getTrustStorePassword() {
+        return trustStorePassword;
+    }
+    /**
+     * @param trustStorePassword The trustStorePassword to set.
+     */
+    public void setTrustStorePassword(String trustStorePassword) {
+        this.trustStorePassword = trustStorePassword;
+    }
+    /**
+     * @return Returns the trustStoreType.
+     */
+    public String getTrustStoreType() {
+        return trustStoreType;
+    }
+    /**
+     * @param trustStoreType The trustStoreType to set.
+     */
+    public void setTrustStoreType(String trustStoreType) {
+        this.trustStoreType = trustStoreType;
+    }
+    
+    public boolean equals(Object o) {
+        if (o == this) {
+            return true;
+        }
+        if (o instanceof SslParameters == false) {
+            return false;
+        }
+        SslParameters s = (SslParameters) o;
+        return eq(algorithm, s.algorithm) &&
+               eq(keyPassword, s.keyPassword) &&
+               eq(keyStore, s.keyStore) &&
+               eq(keyStorePassword, s.keyStorePassword) &&
+               eq(keyStoreType, s.keyStoreType) &&
+               needClientAuth == s.needClientAuth &&
+               eq(protocol, s.protocol) &&
+               eq(trustStore, s.trustStore) &&
+               eq(trustStorePassword, s.trustStorePassword) &&
+               eq(trustStoreType, s.trustStoreType) &&
+               wantClientAuth == s.wantClientAuth;
+               
+    }
+    
+    public int hashCode() {
+        return hash(algorithm) ^
+               hash(keyPassword) ^
+               hash(keyStore) ^
+               hash(keyStorePassword) ^
+               hash(keyStoreType) ^
+               Boolean.valueOf(needClientAuth).hashCode() ^
+               hash(protocol) ^
+               hash(trustStore) ^
+               hash(trustStorePassword) ^
+               hash(trustStoreType) ^
+               Boolean.valueOf(wantClientAuth).hashCode();
+    }
+    
+    private static boolean eq(String s1, String s2) {
+        return (s1 == null) ? s2 == null : s1.equals(s2);
+    }
+    
+    private static int hash(String s) {
+        return s != null ? s.hashCode() : 0;
+    }
+
+
+}

Added: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/CommonsHttpSSLSocketFactory.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/CommonsHttpSSLSocketFactory.java?rev=396901&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/CommonsHttpSSLSocketFactory.java
(added)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/CommonsHttpSSLSocketFactory.java
Tue Apr 25 08:52:01 2006
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.http.processors;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.security.KeyStore;
+
+import javax.jbi.JBIException;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.apache.commons.httpclient.ConnectTimeoutException;
+import org.apache.commons.httpclient.params.HttpConnectionParams;
+import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
+import org.apache.servicemix.http.SslParameters;
+import org.mortbay.resource.Resource;
+import org.springframework.core.io.ClassPathResource;
+
+public class CommonsHttpSSLSocketFactory implements SecureProtocolSocketFactory {
+
+    private SSLSocketFactory factory;
+    
+    public CommonsHttpSSLSocketFactory(SslParameters ssl) throws Exception {
+        SSLContext context = SSLContext.getInstance(ssl.getProtocol());
+        KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(ssl.getAlgorithm());
+        String keyStore = ssl.getKeyStore();
+        if (keyStore == null) {
+            keyStore = System.getProperty("javax.net.ssl.keyStore");
+            if (keyStore == null) {
+                throw new IllegalArgumentException("keyStore or system property javax.net.ssl.keyStore
must be set");
+            }
+        }
+        if (keyStore.startsWith("classpath:")) {
+            try {
+                String res = keyStore.substring(10);
+                URL url = new ClassPathResource(res).getURL();
+                keyStore = url.toString();
+            } catch (IOException e) {
+                throw new JBIException("Unable to find keyStore " + keyStore, e);
+            }
+        }
+        String keyStorePassword = ssl.getKeyStorePassword();
+        if (keyStorePassword == null) {
+            keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
+            if (keyStorePassword == null) {
+                throw new IllegalArgumentException("keyStorePassword or system property javax.net.ssl.keyStorePassword
must be set");
+            }
+        }
+        String trustStore = ssl.getTrustStore();
+        String trustStorePassword = null;
+        if (trustStore == null) {
+            trustStore = System.getProperty("javax.net.ssl.trustStore");
+        }
+        if (trustStore != null && trustStore.startsWith("classpath:")) {
+            try {
+                String res = trustStore.substring(10);
+                URL url = new ClassPathResource(res).getURL();
+                trustStore = url.toString();
+            } catch (IOException e) {
+                throw new JBIException("Unable to find trustStore " + trustStore, e);
+            }
+            trustStorePassword = ssl.getTrustStorePassword();
+            if (trustStorePassword == null) {
+                trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");
+                if (keyStorePassword == null) {
+                    throw new IllegalArgumentException("trustStorePassword or system property
javax.net.ssl.trustStorePassword must be set");
+                }
+            }
+        }
+        KeyStore ks = KeyStore.getInstance(ssl.getKeyStoreType());
+        ks.load(Resource.newResource(keyStore).getInputStream(), keyStorePassword.toCharArray());
+        keyManagerFactory.init(ks, ssl.getKeyPassword() != null ? ssl.getKeyPassword().toCharArray()
: keyStorePassword.toCharArray());
+        if (trustStore != null) {
+            KeyStore ts = KeyStore.getInstance(ssl.getTrustStoreType());
+            ts.load(Resource.newResource(trustStore).getInputStream(), trustStorePassword.toCharArray());
+            TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(ssl.getAlgorithm());
+            trustManagerFactory.init(ts);
+            context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(),
new java.security.SecureRandom());
+        } else {
+            context.init(keyManagerFactory.getKeyManagers(), null, new java.security.SecureRandom());
+        }
+        factory = context.getSocketFactory();
+    }
+    
+    public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws
IOException, UnknownHostException {
+        return factory.createSocket(socket, host, port, autoClose);
+    }
+
+    public Socket createSocket(String host, int port, InetAddress localAddress, int localPort)
throws IOException, UnknownHostException {
+        return factory.createSocket(host, port, localAddress, localPort);
+    }
+
+    public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException
{
+        if (params == null) {
+            throw new IllegalArgumentException("Parameters may not be null");
+        }
+        int timeout = params.getConnectionTimeout();
+        if (timeout == 0) {
+            return createSocket(host, port, localAddress, localPort);
+        } else {
+            Socket socket = factory.createSocket();
+            SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
+            SocketAddress remoteaddr = new InetSocketAddress(host, port);
+            socket.bind(localaddr);
+            socket.connect(remoteaddr, timeout);
+            return socket;
+        }
+    }
+
+    public Socket createSocket(String host, int port) throws IOException, UnknownHostException
{
+        return factory.createSocket(host, port);
+    }
+    
+}
+

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java?rev=396901&r1=396900&r2=396901&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
Tue Apr 25 08:52:01 2006
@@ -37,6 +37,7 @@
 import org.apache.servicemix.http.HttpLifeCycle;
 import org.apache.servicemix.http.HttpProcessor;
 import org.apache.servicemix.http.ServerManager;
+import org.apache.servicemix.http.SslParameters;
 import org.apache.servicemix.soap.Context;
 import org.apache.servicemix.soap.SoapFault;
 import org.apache.servicemix.soap.SoapHelper;
@@ -75,6 +76,10 @@
         this.soapHelper.addPolicy(new AddressingHandler());
         this.locks = new ConcurrentHashMap();
         this.exchanges = new ConcurrentHashMap();
+    }
+    
+    public SslParameters getSsl() {
+        return this.endpoint.getSsl();
     }
     
     public void process(MessageExchange exchange) throws Exception {

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java?rev=396901&r1=396900&r2=396901&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
Tue Apr 25 08:52:01 2006
@@ -36,13 +36,15 @@
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HostConfiguration;
 import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpHost;
 import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.URI;
-import org.apache.commons.httpclient.URIException;
 import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
 import org.apache.servicemix.JbiConstants;
 import org.apache.servicemix.common.ExchangeProcessor;
 import org.apache.servicemix.http.HttpEndpoint;
@@ -68,18 +70,12 @@
     protected DeliveryChannel channel;
     
     public ProviderProcessor(HttpEndpoint endpoint) {
-        try {
-            this.endpoint = endpoint;
-            this.soapMarshaler = new SoapMarshaler(endpoint.isSoap());
-            if (endpoint.isSoap() && "1.1".equals(endpoint.getSoapVersion())) {
-                this.soapMarshaler.setSoapUri(SoapMarshaler.SOAP_11_URI);
-            }
-            this.jbiMarshaler = new JBIMarshaler();
-            this.host = new HostConfiguration();
-            this.host.setHost(new URI(endpoint.getLocationURI(), false));
-        } catch (URIException e) {
-            throw new RuntimeException(e);
+        this.endpoint = endpoint;
+        this.soapMarshaler = new SoapMarshaler(endpoint.isSoap());
+        if (endpoint.isSoap() && "1.1".equals(endpoint.getSoapVersion())) {
+            this.soapMarshaler.setSoapUri(SoapMarshaler.SOAP_11_URI);
         }
+        this.jbiMarshaler = new JBIMarshaler();
     }
 
     public void process(MessageExchange exchange) throws Exception {
@@ -162,6 +158,17 @@
     }
 
     public void start() throws Exception {
+        URI uri = new URI(endpoint.getLocationURI(), false);
+        if (uri.getScheme().equals("https")) {
+            ProtocolSocketFactory sf = new CommonsHttpSSLSocketFactory(endpoint.getSsl());
+            Protocol protocol = new Protocol("https", sf, 443);
+            HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), protocol);
+            this.host = new HostConfiguration();
+            this.host.setHost(host);
+        } else {
+            this.host = new HostConfiguration();
+            this.host.setHost(uri.getHost(), uri.getPort());
+        }
         channel = endpoint.getServiceUnit().getComponent().getComponentContext().getDeliveryChannel();
     }
 

Modified: incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java?rev=396901&r1=396900&r2=396901&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
Tue Apr 25 08:52:01 2006
@@ -42,6 +42,11 @@
 
     private static Log logger =  LogFactory.getLog(HttpSpringTest.class);
 
+    protected void setUp() throws Exception {
+        System.setProperty("javax.net.debug", "all");
+        super.setUp();
+    }
+    
     public void test() throws Exception {
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
         InOut me = client.createInOutExchange();
@@ -60,6 +65,30 @@
             logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
         }
     }
+
+    /*
+     * TODO: this test should be successfull, but an exception is thrown saying
+     *   unable to find valid certifaction path to requested target
+     * 
+    public void testSsl() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("http://test/ssl", "MyProviderService"));
+        me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
+        client.sendSync(me);
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getFault() != null) {
+                fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+            } else if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else {
+            logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
+        }
+    }
+    */
 
     public void testMimeWithHttpClient() throws Exception {
         File f = new File(getClass().getResource("servicemix.jpg").getFile());

Modified: incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java?rev=396901&r1=396900&r2=396901&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java
Tue Apr 25 08:52:01 2006
@@ -172,6 +172,9 @@
     }
 
     public static class TestHttpProcessor implements HttpProcessor {
+        public SslParameters getSsl() {
+            return null;
+        }
         public void process(HttpServletRequest request, HttpServletResponse response) throws
Exception {
             System.out.println(request);
         }

Added: incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/client.keystore
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/client.keystore?rev=396901&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/client.keystore
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/server.keystore
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/server.keystore?rev=396901&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/server.keystore
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/spring.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/spring.xml?rev=396901&r1=396900&r2=396901&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/spring.xml
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/spring.xml
Tue Apr 25 08:52:01 2006
@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns:sm="http://servicemix.apache.org/config/1.0" 
 	   xmlns:http="http://servicemix.apache.org/http/1.0"
-	   xmlns:test="http://test">
+	   xmlns:test="http://test"
+	   xmlns:testSsl="http://test/ssl">
 
   <!-- the JBI container -->
   <sm:container id="jbi" embedded="true">
@@ -12,15 +13,41 @@
       	<sm:component>
             <http:component>
             	<http:endpoints>
-            		<http:endpoint service="test:MyConsumerService"
-            					   endpoint="myConsumer"
-            		               role="consumer" 
-            		               locationURI="http://localhost:8192/Service/"
-            		               defaultMep="http://www.w3.org/2004/08/wsdl/in-out" />
-            		<http:endpoint service="test:MyProviderService"
-            					   endpoint="myProvider"
-            		               role="provider" 
-            		               locationURI="http://localhost:8192/Service/" />
+            	  
+            	  <http:endpoint service="test:MyConsumerService"
+            	    endpoint="myConsumer"
+            	    role="consumer" 
+            	    locationURI="http://localhost:8192/Service/"
+            	    defaultMep="http://www.w3.org/2004/08/wsdl/in-out" />
+            	  
+            	  <http:endpoint service="test:MyProviderService"
+            	    endpoint="myProvider"
+            	    role="provider" 
+            	    locationURI="http://localhost:8192/Service/" />
+            	  
+            	  <http:endpoint service="testSsl:MyConsumerService"
+            	    endpoint="myConsumer"
+            	    role="consumer" 
+            	    locationURI="https://localhost:8193/Service/"
+            	    defaultMep="http://www.w3.org/2004/08/wsdl/in-out">
+            	    <http:ssl>
+            	      <http:sslParameters keyStore="classpath:org/apache/servicemix/http/server.keystore"
+            	      keyStorePassword="password"/>
+            	    </http:ssl>
+            	  </http:endpoint>
+            	  
+            	  <http:endpoint service="testSsl:MyProviderService"
+            	    endpoint="myProvider"
+            	    role="provider" 
+            	    locationURI="https://localhost:8193/Service/">
+            	    <http:ssl>
+            	      <http:sslParameters keyStore="classpath:org/apache/servicemix/http/server.keystore"
+            	        keyStorePassword="password"
+            	        trustStore="classpath:org/apache/servicemix/http/client.keystore"
+            	        trustStorePassword="password"/>
+            	    </http:ssl>
+            	  </http:endpoint>
+            	  
             	</http:endpoints>
             </http:component>
         </sm:component>



Mime
View raw message