servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r391997 - in /incubator/servicemix/trunk/servicemix-components/src: main/java/org/apache/servicemix/components/http/ test/java/org/apache/servicemix/components/http/ test/resources/org/apache/servicemix/components/http/
Date Thu, 06 Apr 2006 14:40:40 GMT
Author: gnodet
Date: Thu Apr  6 07:40:38 2006
New Revision: 391997

URL: http://svn.apache.org/viewcvs?rev=391997&view=rev
Log:
SM-371: support for https in servicemix-components
Thanks to Mike Gerdes for the patch

Added:
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsConnector.java
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsInvoker.java
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsSoapConnector.java
    incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/http/client.keystore
  (with props)
    incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/http/server.keystore
  (with props)
Modified:
    incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpTest.java
    incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/http/example.xml

Added: incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsConnector.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsConnector.java?rev=391997&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsConnector.java
(added)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsConnector.java
Thu Apr  6 07:40:38 2006
@@ -0,0 +1,338 @@
+/*
+ * 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.components.http;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.security.SslSocketConnector;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.servlet.ServletMapping;
+import org.mortbay.thread.BoundedThreadPool;
+import org.springframework.core.io.ClassPathResource;
+
+/**
+ * An embedded Servlet engine to implement a HTTP connector
+ *
+ * @version $Revision: 373823 $
+ */
+public class HttpsConnector extends HttpInOutBinding {
+    private SslSocketConnector listener = new SslSocketConnector();
+    
+	/**
+	 * The maximum number of threads for the Jetty SocketListener. It's set 
+	 * to 256 by default to match the default value in Jetty. 
+	 */
+	private int maxThreads = 256;
+	private static final Log log = LogFactory.getLog(HttpsConnector.class);
+    private Server server;
+    private String host;
+    private int port;
+    private String keyPassword;
+    private String keyStore;
+    private String keyStorePassword;
+    private String keyStoreType = "JKS"; // type of the key store
+    private String protocol = "TLS";
+    private String algorithm = "SunX509"; // cert algorithm
+    private boolean wantClientAuth = false;
+    private boolean needClientAuth = false;
+
+    /**
+     * Constructor
+     *
+     * @param host
+     * @param port
+     */
+    public HttpsConnector(String host, int port, String keyPassword, String keyStorePassword,
String keyStore, boolean needClientAuth, boolean wantClientAuth) {
+        this.host = host;
+        this.port = port;
+        this.keyPassword = keyPassword;
+        this.keyStorePassword = keyStorePassword;
+        this.keyStore = keyStore;
+        this.wantClientAuth = wantClientAuth;
+        this.needClientAuth = needClientAuth;
+    }
+
+    public HttpsConnector() {
+    }
+
+    /**
+     * Constructor
+     *
+     * @param listener
+     */
+    public HttpsConnector(SslSocketConnector listener) {
+        this.listener = listener;
+    }
+
+    /**
+     * Called when the Component is initialized
+     *
+     * @param cc
+     * @throws JBIException
+     */
+    public void init(ComponentContext cc) throws JBIException {
+        super.init(cc);
+        //should set all ports etc here - from the naming context I guess ?
+        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);
+            }
+        }
+        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");
+            }
+        }
+        if (listener == null) {
+            listener = new SslSocketConnector();
+        }
+        listener.setHost(host);
+        listener.setPort(port);
+        listener.setConfidentialPort(port);
+        listener.setPassword(keyStorePassword);
+        listener.setKeyPassword(keyPassword != null ? keyPassword : keyStorePassword);
+        listener.setKeystore(keyStore);
+        listener.setWantClientAuth(wantClientAuth);
+        listener.setNeedClientAuth(needClientAuth);
+        listener.setProtocol(protocol);
+        listener.setAlgorithm(algorithm);
+        listener.setKeystoreType(keyStoreType);
+        server = new Server();
+        BoundedThreadPool btp = new BoundedThreadPool();
+        btp.setMaxThreads(getMaxThreads());
+        server.setThreadPool(btp);
+    }
+    
+    /**
+     * start the Component
+     *
+     * @throws JBIException
+     */
+    public void start() throws JBIException {
+        server.setConnectors(new Connector[] { listener });
+        ContextHandler context = new ContextHandler();
+        context.setContextPath("/");
+        ServletHolder holder = new ServletHolder();
+        holder.setName("jbiServlet");
+        holder.setClassName(BindingServlet.class.getName());
+        ServletHandler handler = new ServletHandler();
+        handler.setServlets(new ServletHolder[] { holder });
+        ServletMapping mapping = new ServletMapping();
+        mapping.setServletName("jbiServlet");
+        mapping.setPathSpec("/*");
+        handler.setServletMappings(new ServletMapping[] { mapping });
+        context.setHandler(handler);
+        server.setHandler(context);
+        context.setAttribute("binding", this);
+        try {
+            server.start();
+        }
+        catch (Exception e) {
+        	log.warn(e.toString());
+            throw new JBIException("Start failed: " + e, e);
+        }
+    }
+
+    /**
+     * stop
+     */
+    public void stop() throws JBIException {
+        try {
+            if (server != null) {
+                server.stop();
+            }
+        }
+        catch (Exception e) {
+        	log.warn(e.toString());
+            throw new JBIException("Stop failed: " + e, e);
+        }
+    }
+
+    /**
+     * shutdown
+     */
+    public void shutDown() throws JBIException {
+        server = null;
+    }
+
+
+    // Properties
+    //-------------------------------------------------------------------------
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
+
+    public Server getServer() {
+        return server;
+    }
+
+    public void setServer(Server server) {
+        this.server = server;
+    }
+
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
+
+	public int getMaxThreads() {
+		return maxThreads;
+	}
+
+	public void setMaxThreads(int maxThreads) {
+		this.maxThreads = maxThreads;
+	}
+
+    /**
+     * @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;
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsInvoker.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsInvoker.java?rev=391997&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsInvoker.java
(added)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsInvoker.java
Thu Apr  6 07:40:38 2006
@@ -0,0 +1,382 @@
+/*
+ * 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.components.http;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.URI;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.security.KeyStore;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+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.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpHost;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.params.HttpConnectionParams;
+import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
+import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.TransformComponentSupport;
+import org.mortbay.resource.Resource;
+import org.springframework.core.io.ClassPathResource;
+
+/**
+ * Performs HTTP client invocations on a remote HTTP site.
+ *
+ * @version $Revision: 373823 $
+ */
+public class HttpsInvoker extends TransformComponentSupport implements MessageExchangeListener
{
+
+    protected HttpClientMarshaler marshaler = new HttpClientMarshaler();
+    protected MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
+    protected HttpClient httpClient = new HttpClient(connectionManager);
+    protected HostConfiguration hostConfiguration = new HostConfiguration();
+    protected String url;
+    protected boolean defaultInOut = true;
+
+    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 class CommonsHttpSSLSocketFactory implements SecureProtocolSocketFactory {
+
+        private SSLSocketFactory factory;
+        
+        public CommonsHttpSSLSocketFactory() throws Exception {
+            SSLContext context = SSLContext.getInstance(protocol);
+            KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(algorithm);
+            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);
+                }
+            }
+            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");
+                }
+            }
+            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);
+                }
+            }
+            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(keyStoreType);
+            ks.load(Resource.newResource(keyStore).getInputStream(), keyStorePassword.toCharArray());
+            keyManagerFactory.init(ks, keyPassword != null ? keyPassword.toCharArray() :
keyStorePassword.toCharArray());
+            if (trustStore != null) {
+                KeyStore ts = KeyStore.getInstance(trustStoreType);
+                ts.load(Resource.newResource(trustStore).getInputStream(), trustStorePassword.toCharArray());
+                TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(algorithm);
+                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);
+        }
+        
+    }
+    
+    protected void init() throws JBIException {
+        super.init();
+        try {
+            URI uri = new URI(url);
+            ProtocolSocketFactory sf = new CommonsHttpSSLSocketFactory();
+            Protocol protocol = new Protocol("https", sf, 443);
+            HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), protocol);
+            hostConfiguration.setHost(host);
+        } catch (Exception e) {
+            throw new JBIException("Unable to initialize HttpsInvoker", e);
+        }
+    }
+    
+    public void stop() throws JBIException {
+        super.stop();
+        connectionManager.shutdown();
+    }
+
+    protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage
out) throws MessagingException {
+        String url;
+        // We need to relativize the method url to the host config
+        // so that the hostConfiguration is not overriden by the executeMethod call
+        try {
+            java.net.URI uri = new URI(this.url);
+            uri = uri.relativize(new URI(hostConfiguration.getHostURL()));
+            url = uri.toString();
+        } catch (Exception e1) {
+            url = this.url;
+        }
+        PostMethod method = new PostMethod(url);
+        try {
+            marshaler.fromNMS(method, exchange, in);
+            if (method.getRequestHeader("Content-Type") == null) {
+                method.setRequestHeader("Content-Type", "text/html; charset=UTF-8");
+            }
+            int response = httpClient.executeMethod(hostConfiguration, method);
+
+            if (response != HttpStatus.SC_OK) {
+                throw new InvalidStatusResponseException(response);
+            }
+
+            // now lets grab the output and set it on the out message
+            if (defaultInOut) {
+                marshaler.toNMS(out, method);
+            }
+            return defaultInOut;
+        }
+        catch (Exception e) {
+            throw new MessagingException("Error executing http request", e);
+        }
+        finally {
+            method.releaseConnection();
+        }
+    }
+
+    public HttpClient getHttpClient() {
+        return httpClient;
+    }
+
+    public void setHttpClient(HttpClient httpClient) {
+        this.httpClient = httpClient;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public boolean isDefaultInOut() {
+        return defaultInOut;
+    }
+
+    public void setDefaultInOut(boolean defaultInOut) {
+        this.defaultInOut = defaultInOut;
+    }
+
+    public HttpClientMarshaler getMarshaler() {
+        return marshaler;
+    }
+
+    public void setMarshaler(HttpClientMarshaler marshaler) {
+        this.marshaler = marshaler;
+    }
+
+    /**
+     * @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 protocol.
+     */
+    public String getProtocol() {
+        return protocol;
+    }
+
+    /**
+     * @param protocol The protocol to set.
+     */
+    public void setProtocol(String protocol) {
+        this.protocol = protocol;
+    }
+
+    /**
+     * @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;
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsSoapConnector.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsSoapConnector.java?rev=391997&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsSoapConnector.java
(added)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsSoapConnector.java
Thu Apr  6 07:40:38 2006
@@ -0,0 +1,329 @@
+/*
+ * 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.components.http;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.security.SslSocketConnector;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.servlet.ServletMapping;
+import org.mortbay.thread.BoundedThreadPool;
+import org.springframework.core.io.ClassPathResource;
+
+public class HttpsSoapConnector extends HttpSoapInOutBinding {
+    private SslSocketConnector listener = new SslSocketConnector();
+	
+	/**
+	 * The maximum number of threads for the Jetty SocketListener. It's set 
+	 * to 256 by default to match the default value in Jetty. 
+	 */
+	private int maxThreads = 256;
+	private Server server;
+	private static final Log log = LogFactory.getLog(HttpsConnector.class);
+	private String host;
+	private int port;
+    private String keyPassword;
+    private String keyStore;
+    private String keyStorePassword;
+    private String keyStoreType = "JKS"; // type of the key store
+    private String protocol = "TLS";
+    private String algorithm = "SunX509"; // cert algorithm
+    private boolean wantClientAuth = false;
+    private boolean needClientAuth = false;
+
+    /**
+     * Constructor
+     *
+     * @param host
+     * @param port
+     */
+    public HttpsSoapConnector(String host, int port, String keyPassword, String keyStorePassword,
String keyStore, boolean needClientAuth, boolean wantClientAuth) {
+        this.host = host;
+        this.port = port;
+        this.keyPassword = keyPassword;
+        this.keyStorePassword = keyStorePassword;
+        this.keyStore = keyStore;
+        this.wantClientAuth = wantClientAuth;
+        this.needClientAuth = needClientAuth;
+    }
+
+	public HttpsSoapConnector() {
+	}
+
+	/**
+	 * Constructor
+	 *
+	 * @param listener
+	 */
+	public HttpsSoapConnector(SslSocketConnector listener) {
+		this.listener = listener;
+	}
+
+	/**
+	 * Called when the Component is initialized
+	 *
+	 * @param cc
+	 * @throws JBIException
+	 */
+	public void init(ComponentContext cc) throws JBIException {
+		super.init(cc);
+		//should set all ports etc here - from the naming context I guess ?
+        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);
+            }
+        }
+        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");
+            }
+        }
+        if (listener == null) {
+            listener = new SslSocketConnector();
+        }
+        listener.setHost(host);
+        listener.setPort(port);
+        listener.setConfidentialPort(port);
+        listener.setPassword(keyStorePassword);
+        listener.setKeyPassword(keyPassword != null ? keyPassword : keyStorePassword);
+        listener.setKeystore(keyStore);
+        listener.setWantClientAuth(wantClientAuth);
+        listener.setNeedClientAuth(needClientAuth);
+        listener.setProtocol(protocol);
+        listener.setAlgorithm(algorithm);
+        listener.setKeystoreType(keyStoreType);
+		server = new Server();
+        BoundedThreadPool btp = new BoundedThreadPool();
+        btp.setMaxThreads(getMaxThreads());
+        server.setThreadPool(btp);
+	}
+
+	/**
+	 * start the Component
+	 *
+	 * @throws JBIException
+	 */
+	public void start() throws JBIException {
+        server.setConnectors(new Connector[] { listener });
+        ContextHandler context = new ContextHandler();
+        context.setContextPath("/");
+        ServletHolder holder = new ServletHolder();
+        holder.setName("jbiServlet");
+        holder.setClassName(BindingServlet.class.getName());
+        ServletHandler handler = new ServletHandler();
+        handler.setServlets(new ServletHolder[] { holder });
+        ServletMapping mapping = new ServletMapping();
+        mapping.setServletName("jbiServlet");
+        mapping.setPathSpec("/*");
+        handler.setServletMappings(new ServletMapping[] { mapping });
+        context.setHandler(handler);
+        server.setHandler(context);
+        context.setAttribute("binding", this);
+        try {
+            server.start();
+        }
+        catch (Exception e) {
+        	log.warn(e.toString());
+            throw new JBIException("Start failed: " + e, e);
+        }
+	}
+
+	/**
+	 * stop
+	 */
+	public void stop() throws JBIException {
+        try {
+            if (server != null) {
+                server.stop();
+            }
+        } catch (Exception e) {
+            throw new JBIException("Stop failed: " + e, e);
+        }
+    }
+
+	/**
+	 * shutdown
+	 */
+	public void shutDown() throws JBIException {
+		server = null;
+	}
+
+	// Properties
+	//-------------------------------------------------------------------------
+	public int getPort() {
+		return port;
+	}
+
+	public void setPort(int port) {
+		this.port = port;
+	}
+
+	public Server getServer() {
+		return server;
+	}
+
+	public void setServer(Server server) {
+		this.server = server;
+	}
+
+	public String getHost() {
+		return host;
+	}
+
+	public void setHost(String host) {
+		this.host = host;
+	}
+
+	public int getMaxThreads() {
+		return maxThreads;
+	}
+
+	public void setMaxThreads(int maxThreads) {
+		this.maxThreads = maxThreads;
+	}
+
+    /**
+     * @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;
+    }
+}

Modified: incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpTest.java?rev=391997&r1=391996&r2=391997&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpTest.java
Thu Apr  6 07:40:38 2006
@@ -16,6 +16,7 @@
 package org.apache.servicemix.components.http;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
@@ -25,9 +26,9 @@
 import javax.xml.namespace.QName;
 
 import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.w3c.dom.Node;
-import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
 
 /**
  * @version $Revision$
@@ -35,6 +36,24 @@
 public class HttpTest extends TestSupport {
 
     protected String quote = "SUNW";
+    
+    protected void setUp() throws Exception {
+        System.setProperty("javax.net.debug", "all");
+        // The following properties will be used by default if not specified in the xml conf
+        /*
+        System.setProperty("javax.net.ssl.trustStore", getResourceFilePath("client.keystore"));
+        System.setProperty("javax.net.ssl.trustStorePassword", "password");
+        System.setProperty("javax.net.ssl.keyStore", getResourceFilePath("server.keystore"));
+        System.setProperty("javax.net.ssl.keyStorePassword", "password");
+        */
+        super.setUp();
+    }
+    
+    String getResourceFilePath(String resource) throws Exception {
+        URL url = getClass().getResource(resource);
+        File f = new File(url.toURI());
+        return f.toString();
+    }
 
     public void testCurrencyQuotes() throws Exception {
         QName serviceName = new QName("http://servicemix.org/cheese/", "httpSender");

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

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

Modified: incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/http/example.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/http/example.xml?rev=391997&r1=391996&r2=391997&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/http/example.xml
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/http/example.xml
Thu Apr  6 07:40:38 2006
@@ -24,15 +24,21 @@
       <!-- END SNIPPET: binding -->
 
       <sm:activationSpec componentName="httpSender2" service="foo:httpSender2">
-        <sm:component><bean class="org.apache.servicemix.components.http.HttpInvoker">
-          <property name="url" value="http://localhost:8913"/>
+        <sm:component><bean class="org.apache.servicemix.components.http.HttpsInvoker">
+          <property name="url" value="https://localhost:8913"/>
+          <property name="keyStore" value="classpath:org/apache/servicemix/components/http/server.keystore"
/>
+          <property name="keyStorePassword" value="password" />
+          <property name="trustStore" value="classpath:org/apache/servicemix/components/http/client.keystore"
/>
+          <property name="trustStorePassword" value="password" />
         </bean></sm:component>
       </sm:activationSpec>
       
       <sm:activationSpec componentName="httpReceiver2" service="foo:httpBinding2" destinationService="foo:stockQuote">
-        <sm:component><bean class="org.apache.servicemix.components.http.HttpConnector">
+        <sm:component><bean class="org.apache.servicemix.components.http.HttpsConnector">
           <property name="host" value="localhost"/>
           <property name="port" value="8913"/>
+          <property name="keyStore" value="classpath:org/apache/servicemix/components/http/server.keystore"
/>
+          <property name="keyStorePassword" value="password" />
         </bean></sm:component>
       </sm:activationSpec>
       

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

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



Mime
View raw message