aevers 2003/01/28 02:34:42
Modified: src/java/org/apache/xmlrpc XmlRpcClient.java
XmlRpcTransportFactory.java
xdocs changes.xml
Added: src/java/org/apache/xmlrpc
DefaultXmlRpcTransportFactory.java
src/java/org/apache/xmlrpc/secure/sunssl
SunSSLTransportFactory.java
Log:
Refactor XmlRpcTransportFactory and add DefaultXmlRpcTransportFactory that
can load other transport factories via reflection.
Merge edited code from Larry Meader and Chris Jackson to use the Sun SSL
provider as a transport.
Submitted by: "Chris Jackson" <[EMAIL PROTECTED]>, "Larry Meader"
<[EMAIL PROTECTED]>
Revision Changes Path
1.16 +2 -2 xml-rpc/src/java/org/apache/xmlrpc/XmlRpcClient.java
Index: XmlRpcClient.java
===================================================================
RCS file: /home/cvs/xml-rpc/src/java/org/apache/xmlrpc/XmlRpcClient.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- XmlRpcClient.java 5 Dec 2002 08:49:24 -0000 1.15
+++ XmlRpcClient.java 28 Jan 2003 10:34:36 -0000 1.16
@@ -415,7 +415,7 @@
}
}
- protected XmlRpcTransport createTransport()
+ protected XmlRpcTransport createTransport() throws XmlRpcClientException
{
if (transportFactory == null)
{
1.2 +24 -2 xml-rpc/src/java/org/apache/xmlrpc/XmlRpcTransportFactory.java
Index: XmlRpcTransportFactory.java
===================================================================
RCS file: /home/cvs/xml-rpc/src/java/org/apache/xmlrpc/XmlRpcTransportFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XmlRpcTransportFactory.java 5 Dec 2002 08:49:24 -0000 1.1
+++ XmlRpcTransportFactory.java 28 Jan 2003 10:34:36 -0000 1.2
@@ -57,6 +57,7 @@
import java.io.InputStream;
import java.io.IOException;
+import java.util.Properties;
/**
* Interface from XML-RPC to an underlying transport, most likely base on HTTP.
@@ -64,8 +65,29 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Andrew Evers</a>
* @version $Id$
* @since 1.2
+ *
+ * Constructors for SSL implementations of XmlRpcTransportFactory should have a
constructor
+ * with a signature defined by CONSTRUCTOR_SIGNATURE:
+ * <code>
+ * ClassName(Properties properties)
+ * </code>
+ *
+ * and use the default properties defined in this interface.
*/
public interface XmlRpcTransportFactory
{
- public XmlRpcTransport createTransport();
+ public static final String TRANSPORT_URL = "url"; // Name of property
containing URL
+ public static final String TRANSPORT_AUTH = "auth"; // Name of property
containing Basic Authentication information
+
+ public static final Class [] CONSTRUCTOR_SIGNATURE = new Class [] {
Properties.class };
+ public static final String CONSTRUCTOR_SIGNATURE_STRING =
"(java.util.Properties properties)";
+
+ /**
+ * Create a new XML-RPC transport.
+ *
+ * @return XmlRpcTransport an instance created according to the rules
+ * specified to the constructor.
+ */
+ public XmlRpcTransport createTransport()
+ throws XmlRpcClientException;
}
1.1
xml-rpc/src/java/org/apache/xmlrpc/DefaultXmlRpcTransportFactory.java
Index: DefaultXmlRpcTransportFactory.java
===================================================================
package org.apache.xmlrpc;
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "XML-RPC" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.Properties;
import java.util.Hashtable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* Default XML-RPC transport factory, produces HTTP, HTTPS with SSL or TLS based on
URI protocol.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Larry Meader</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Chris Jackson</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Andrew Evers</a>
* @version $Id: DefaultXmlRpcTransportFactory.java,v 1.1 2003/01/28 10:34:36 aevers
Exp $
* @since 1.2
*/
public class DefaultXmlRpcTransportFactory implements XmlRpcTransportFactory
{
// Default properties to pass to transport factory
protected URL url;
protected String auth;
protected static XmlRpcTransportFactory secureTransportFactory;
public static final String DEFAULT_SSL_PROVIDER = "comnetsun";
private static Hashtable sslTransports = new Hashtable (1);
static
{
// A mapping of short identifiers to the fully qualified class names of
// common SSL transport factories. If more mappings are added here,
// increase the size of the sslTransports Hashtable used to store them.
sslTransports.put("comnetsun",
"org.apache.xmlrpc.secure.sunssl.SunSSLTransportFactory");
}
public static void setTransport(String transport, Properties properties)
throws XmlRpcClientException
{
String transportFactoryClassName = null;
Class transportFactoryClass;
Constructor transportFactoryConstructor;
Object transportFactoryInstance;
try
{
transportFactoryClassName = (String) sslTransports.get(transport);
if (transportFactoryClassName == null)
{
// Identifier lookup failed, assuming we were provided
// with the fully qualified class name.
transportFactoryClassName = transport;
}
transportFactoryClass = Class.forName(transportFactoryClassName);
transportFactoryConstructor = transportFactoryClass.getConstructor(
XmlRpcTransportFactory.CONSTRUCTOR_SIGNATURE);
transportFactoryInstance = transportFactoryConstructor.newInstance(
new Object [] { properties });
if (transportFactoryInstance instanceof XmlRpcTransportFactory)
{
secureTransportFactory = (XmlRpcTransportFactory)
transportFactoryInstance;
}
else
{
throw new XmlRpcClientException("Class '" +
transportFactoryClass.getName() + "' does not implement '" +
XmlRpcTransportFactory.class.getName() + "'", null);
}
}
catch (ClassNotFoundException cnfe)
{
throw new XmlRpcClientException("Transport Factory not found: " +
transportFactoryClassName, cnfe);
}
catch (NoSuchMethodException nsme)
{
throw new XmlRpcClientException("Transport Factory constructor not
found: " +
transportFactoryClassName +
XmlRpcTransportFactory.CONSTRUCTOR_SIGNATURE_STRING, nsme);
}
catch (IllegalAccessException iae)
{
throw new XmlRpcClientException("Unable to access Transport Factory
constructor: " +
transportFactoryClassName, iae);
}
catch (InstantiationException ie)
{
throw new XmlRpcClientException("Unable to instantiate Transport
Factory: " +
transportFactoryClassName, ie);
}
catch (InvocationTargetException ite)
{
throw new XmlRpcClientException("Error calling Transport Factory
constructor: ",
ite.getTargetException());
}
}
public DefaultXmlRpcTransportFactory(URL url)
{
this(url, null);
}
public DefaultXmlRpcTransportFactory(URL url, String auth)
{
this.url = url;
this.auth = auth;
}
public XmlRpcTransport createTransport()
throws XmlRpcClientException
{
if ("https".equals(url.getProtocol()))
{
if (secureTransportFactory == null)
{
Properties properties = new Properties();
properties.put(XmlRpcTransportFactory.TRANSPORT_URL, url);
properties.put(XmlRpcTransportFactory.TRANSPORT_AUTH, auth);
setTransport(DEFAULT_SSL_PROVIDER, properties);
}
return secureTransportFactory.createTransport();
}
return new DefaultXmlRpcTransport(url);
}
public URL getURL()
{
return url;
}
}
1.1
xml-rpc/src/java/org/apache/xmlrpc/secure/sunssl/SunSSLTransportFactory.java
Index: SunSSLTransportFactory.java
===================================================================
package org.apache.xmlrpc.secure.sunssl;
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "XML-RPC" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;
import java.security.Security;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import org.apache.xmlrpc.secure.SecurityTool;
import org.apache.xmlrpc.XmlRpcTransportFactory;
import org.apache.xmlrpc.DefaultXmlRpcTransport;
import org.apache.xmlrpc.XmlRpcTransport;
import com.sun.net.ssl.X509TrustManager;
import com.sun.net.ssl.HostnameVerifier;
import com.sun.net.ssl.SSLContext;
import com.sun.net.ssl.HttpsURLConnection;
/**
* Interface from XML-RPC to the HTTPS transport based on the
* @see javax.net.ssl.httpsURLConnection class.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Larry Meader</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Chris Jackson</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Andrew Evers</a>
* @version $Id: SunSSLTransportFactory.java,v 1.1 2003/01/28 10:34:40 aevers Exp $
* @since 1.2
*/
public class SunSSLTransportFactory implements XmlRpcTransportFactory
{
protected URL url;
protected String auth;
public static final String TRANSPORT_TRUSTMANAGER = "hostnameverifier";
public static final String TRANSPORT_HOSTNAMEVERIFIER = "trustmanager";
// The openTrustManager trusts all certificates
private static X509TrustManager openTrustManager = new X509TrustManager()
{
public boolean isClientTrusted(X509Certificate[] chain)
{
return true;
}
public boolean isServerTrusted(X509Certificate[] chain)
{
return true;
}
public X509Certificate[] getAcceptedIssuers()
{
return null;
}
};
// The openHostnameVerifier trusts all hostnames
private static HostnameVerifier openHostnameVerifier = new HostnameVerifier()
{
public boolean verify(String hostname, String session)
{
return true;
}
};
public static Properties getProperties()
{
Properties properties = new Properties();
properties.setProperty(XmlRpcTransportFactory.TRANSPORT_URL, "(java.net.URL)
- URL to connect to");
properties.setProperty(XmlRpcTransportFactory.TRANSPORT_AUTH,
"(java.lang.String) - HTTP Basic Authentication string (encoded).");
properties.setProperty(TRANSPORT_TRUSTMANAGER,
"(com.sun.net.ssl.X509TrustManager) - X.509 Trust Manager to use");
properties.setProperty(TRANSPORT_HOSTNAMEVERIFIER,
"(com.sun.net.ssl.HostnameVerifier) - Hostname verifier to use");
return properties;
}
public SunSSLTransportFactory(Properties properties)
throws GeneralSecurityException
{
X509TrustManager trustManager;
HostnameVerifier hostnameVerifier;
SSLContext sslContext;
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
url = (URL) properties.get(XmlRpcTransportFactory.TRANSPORT_URL);
auth = properties.getProperty(XmlRpcTransportFactory.TRANSPORT_AUTH);
trustManager = (X509TrustManager) properties.get(TRANSPORT_TRUSTMANAGER);
if (trustManager == null)
{
trustManager = openTrustManager;
}
hostnameVerifier = (HostnameVerifier)
properties.get(TRANSPORT_HOSTNAMEVERIFIER);
if (hostnameVerifier == null)
{
hostnameVerifier = openHostnameVerifier;
}
sslContext = SSLContext.getInstance(SecurityTool.getSecurityProtocol());
X509TrustManager[] tmArray = new X509TrustManager[] { trustManager };
sslContext.init(null, tmArray, new SecureRandom());
// Set the default SocketFactory and HostnameVerifier
// for javax.net.ssl.HttpsURLConnection
if (sslContext != null)
{
HttpsURLConnection.setDefaultSSLSocketFactory(
sslContext.getSocketFactory());
}
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
}
public XmlRpcTransport createTransport()
{
return new DefaultXmlRpcTransport(url, auth);
}
}
1.19 +14 -0 xml-rpc/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/xml-rpc/xdocs/changes.xml,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- changes.xml 26 Jan 2003 02:35:34 -0000 1.18
+++ changes.xml 28 Jan 2003 10:34:40 -0000 1.19
@@ -14,6 +14,20 @@
<ul>
<li>
+ <strong>28 Jan 2003</strong>
+ <ul>
+
+ <li>
+ Refactor XmlRpcTransportFactory and add DefaultXmlRpcTransportFactory
that
+ can load other transport factories via reflection.
+ Merge edited code from Larry Meader and Chris Jackson to use the
Sun SSL
+ provider as a transport.
+ </li>
+
+ </ul>
+ </li>
+
+ <li>
<strong>25 Jan 2003</strong>
<ul>