Author: dkulp
Date: Mon Oct 5 19:15:53 2009
New Revision: 821971
URL: http://svn.apache.org/viewvc?rev=821971&view=rev
Log:
Merged revisions 821963 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r821963 | dkulp | 2009-10-05 15:01:04 -0400 (Mon, 05 Oct 2009) | 2 lines
[CXF-1459] use reflection on the actual connection's class to get the
methods so it should work with the BEA versions as well.
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java
cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionInfo.java
Propchange: cxf/branches/2.2.x-fixes/
('svn:mergeinfo' removed)
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java?rev=821971&r1=821970&r2=821971&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java
Mon Oct 5 19:15:53 2009
@@ -90,10 +90,6 @@
* Cache the last SSLContext to avoid recreation
*/
SSLSocketFactory socketFactory;
-
- private Class deprecatedSunHttpsURLConnectionClass;
-
- private Class deprecatedSunHostnameVerifierClass;
/**
* This constructor initialized the factory with the configured TLS
@@ -232,11 +228,11 @@
}
conn.setSSLSocketFactory(socketFactory);
} else {
- // handle the deprecated sun case
+ // handle the deprecated sun case and other possible hidden API's
+ // that are similar to the Sun cases
try {
- Class<?> connectionClass =
getDeprecatedSunHttpsURLConnectionClass();
- Class<?> verifierClass =
getDeprecatedSunHostnameVerifierClass();
- Method setHostnameVerifier =
connectionClass.getMethod("setHostnameVerifier", verifierClass);
+ Method method =
connection.getClass().getMethod("getHostnameVerifier");
+
InvocationHandler handler = new InvocationHandler() {
public Object invoke(Object proxy,
Method method,
@@ -245,33 +241,27 @@
}
};
Object proxy =
java.lang.reflect.Proxy.newProxyInstance(this.getClass().getClassLoader(),
- new
Class[] {verifierClass},
-
handler);
- setHostnameVerifier.invoke(connectionClass.cast(connection),
verifierClass.cast(proxy));
- Method setSSLSocketFactory =
connectionClass.getMethod("setSSLSocketFactory",
-
SSLSocketFactory.class);
- setSSLSocketFactory.invoke(connectionClass.cast(connection),
socketFactory);
+ new
Class[] {method.getReturnType()},
+
handler);
+
+ method =
connection.getClass().getMethod("setHostnameVerifier", method.getReturnType());
+ method.invoke(connection, proxy);
+ } catch (Exception ex) {
+ //Ignore this one, we're just setting it to a completely
stupid verifier anyway
+ //that is pretty pointless.
+ }
+ try {
+ Method setSSLSocketFactory =
connection.getClass().getMethod("setSSLSocketFactory",
+
SSLSocketFactory.class);
+ setSSLSocketFactory.invoke(connection, socketFactory);
} catch (Exception ex) {
+ //if we cannot set the SSLSocketFactor, we're in serious
trouble.
throw new IllegalArgumentException("Error decorating
connection class "
+ connection.getClass().getName(), ex);
}
}
}
- private Class getDeprecatedSunHttpsURLConnectionClass() throws
ClassNotFoundException {
- if (deprecatedSunHttpsURLConnectionClass == null) {
- deprecatedSunHttpsURLConnectionClass =
Class.forName("com.sun.net.ssl.HttpsURLConnection");
- }
- return deprecatedSunHttpsURLConnectionClass;
- }
-
- private Class getDeprecatedSunHostnameVerifierClass() throws
ClassNotFoundException {
- if (deprecatedSunHostnameVerifierClass == null) {
- deprecatedSunHostnameVerifierClass =
Class.forName("com.sun.net.ssl.HostnameVerifier");
- }
- return deprecatedSunHostnameVerifierClass;
- }
-
/*
* For development and testing only
*/
Modified:
cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionInfo.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionInfo.java?rev=821971&r1=821970&r2=821971&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionInfo.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionInfo.java
Mon Oct 5 19:15:53 2009
@@ -25,7 +25,6 @@
import java.security.Principal;
import java.security.cert.Certificate;
-import javax.imageio.IIOException;
import javax.net.ssl.HttpsURLConnection;
import org.apache.cxf.transport.http.HttpURLConnectionInfo;
@@ -66,7 +65,6 @@
*/
protected Principal peerPrincipal;
- private Class deprecatedSunHttpsURLConnectionOldImplClass;
/**
* This constructor is used to create the info object
@@ -87,13 +85,12 @@
} else {
Exception ex = null;
try {
- Class<?> deprecatedSunClass =
getDeprecatedSunHttpsURLConnectionOldImplClass();
Method method = null;
- method = deprecatedSunClass.getMethod("getCipherSuite",
(Class[]) null);
+ method = connection.getClass().getMethod("getCipherSuite",
(Class[]) null);
enabledCipherSuite = (String) method.invoke(connection,
(Object[]) null);
- method = deprecatedSunClass.getMethod("getLocalCertificates",
(Class[]) null);
+ method =
connection.getClass().getMethod("getLocalCertificates", (Class[]) null);
localCertificates = (Certificate[]) method.invoke(connection,
(Object[]) null);
- method = deprecatedSunClass.getMethod("getServerCertificates",
(Class[]) null);
+ method =
connection.getClass().getMethod("getServerCertificates", (Class[]) null);
serverCertificates = (Certificate[]) method.invoke(connection,
(Object[]) null);
//TODO Obtain localPrincipal and peerPrincipal using the
com.sun.net.ssl api
@@ -104,21 +101,17 @@
if (ex instanceof IOException) {
throw (IOException) ex;
}
- throw new IIOException("Error constructing
HttpsURLConnectionInfo for connection class "
- + connection.getClass().getName(), ex);
+ IOException ioe = new IOException("Error constructing
HttpsURLConnectionInfo "
+ + "for connection class "
+ +
connection.getClass().getName());
+ ioe.initCause(ex);
+ throw ioe;
+
}
}
}
}
- private Class getDeprecatedSunHttpsURLConnectionOldImplClass() throws
ClassNotFoundException {
- if (deprecatedSunHttpsURLConnectionOldImplClass == null) {
- deprecatedSunHttpsURLConnectionOldImplClass =
-
Class.forName("com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl");
- }
- return deprecatedSunHttpsURLConnectionOldImplClass;
- }
-
/**
* This method returns the cipher suite employed in this
* HttpsURLConnection.