summaryrefslogtreecommitdiff
path: root/javax/net/ssl/HttpsURLConnection.java
diff options
context:
space:
mode:
authorChris Burdess <dog@bluezoo.org>2005-01-11 12:00:31 +0000
committerChris Burdess <dog@bluezoo.org>2005-01-11 12:00:31 +0000
commit119708fba79c7c22fc83144580f7a0a41d82cdd3 (patch)
treef3e0988bcf71bed2636e268321691ae0aee3d319 /javax/net/ssl/HttpsURLConnection.java
parentc57e22e95ff5f455ed8c4ee99af24851f086adaa (diff)
downloadclasspath-119708fba79c7c22fc83144580f7a0a41d82cdd3.tar.gz
2005-01-11 Chris Burdess <dog@gnu.org>
* gnu/java/net/protocol/http/HTTPConnection.java: Use correct form of Host header when using a non-default port number. 2005-01-11 Chris Burdess <dog@gnu.org> * javax/net/ssl/HttpsURLConnection.java: Do not request SSLv3 provider during class initialization.
Diffstat (limited to 'javax/net/ssl/HttpsURLConnection.java')
-rw-r--r--javax/net/ssl/HttpsURLConnection.java70
1 files changed, 47 insertions, 23 deletions
diff --git a/javax/net/ssl/HttpsURLConnection.java b/javax/net/ssl/HttpsURLConnection.java
index a7b86c184..38e686af8 100644
--- a/javax/net/ssl/HttpsURLConnection.java
+++ b/javax/net/ssl/HttpsURLConnection.java
@@ -59,10 +59,18 @@ public abstract class HttpsURLConnection extends HttpURLConnection
// Fields.
// ------------------------------------------------------------------
- /** The default verifier. */
+ /**
+ * The default verifier.
+ * This is lazily initialized as required.
+ * @see #getDefaultHostnameVerifier
+ */
private static HostnameVerifier defaultVerifier;
- /** The default factory. */
+ /**
+ * The default factory.
+ * This is lazily initialized as required.
+ * @see #getDefaultSSLSocketFactory
+ */
private static SSLSocketFactory defaultFactory;
/**
@@ -75,21 +83,6 @@ public abstract class HttpsURLConnection extends HttpURLConnection
*/
private SSLSocketFactory factory;
- // Static initializer.
- // ------------------------------------------------------------------
-
- static {
- defaultVerifier = new TrivialHostnameVerifier();
- try
- {
- defaultFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
- }
- catch (Throwable t)
- {
- t.printStackTrace();
- }
- }
-
// Constructor.
// ------------------------------------------------------------------
@@ -102,8 +95,6 @@ public abstract class HttpsURLConnection extends HttpURLConnection
protected HttpsURLConnection(URL url) throws IOException
{
super(url);
- hostnameVerifier = defaultVerifier;
- factory = defaultFactory;
}
// Class methods.
@@ -112,11 +103,17 @@ public abstract class HttpsURLConnection extends HttpURLConnection
/**
* Returns the default hostname verifier used in all new
* connections.
+ * If the default verifier has not been set, a new default one will be
+ * provided by this method.
*
* @return The default hostname verifier.
*/
- public static HostnameVerifier getDefaultHostnameVerifier()
+ public static synchronized HostnameVerifier getDefaultHostnameVerifier()
{
+ if (defaultVerifier == null)
+ {
+ defaultVerifier = new TrivialHostnameVerifier();
+ }
return defaultVerifier;
}
@@ -137,17 +134,33 @@ public abstract class HttpsURLConnection extends HttpURLConnection
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPermission(new SSLPermission("setHostnameVerifier"));
- defaultVerifier = newDefault;
+ synchronized (HttpsURLConnection.class)
+ {
+ defaultVerifier = newDefault;
+ }
}
/**
* Returns the default SSL socket factory used in all new
* connections.
+ * If the default SSL socket factory has not been set, a new default one
+ * will be provided by this method.
*
* @return The default SSL socket factory.
*/
- public static SSLSocketFactory getDefaultSSLSocketFactory()
+ public static synchronized SSLSocketFactory getDefaultSSLSocketFactory()
{
+ if (defaultFactory == null)
+ {
+ try
+ {
+ defaultFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ }
return defaultFactory;
}
@@ -168,7 +181,10 @@ public abstract class HttpsURLConnection extends HttpURLConnection
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkSetFactory();
- defaultFactory = newDefault;
+ synchronized (HttpsURLConnection.class)
+ {
+ defaultFactory = newDefault;
+ }
}
// Instance methods.
@@ -181,6 +197,10 @@ public abstract class HttpsURLConnection extends HttpURLConnection
*/
public HostnameVerifier getHostnameVerifier()
{
+ if (hostnameVerifier == null)
+ {
+ hostnameVerifier = getDefaultHostnameVerifier();
+ }
return hostnameVerifier;
}
@@ -205,6 +225,10 @@ public abstract class HttpsURLConnection extends HttpURLConnection
*/
public SSLSocketFactory getSSLSocketFactory()
{
+ if (factory == null)
+ {
+ factory = getDefaultSSLSocketFactory();
+ }
return factory;
}