/[classpath]/classpath/javax/net/ssl/HttpsURLConnection.java
ViewVC logotype

Diff of /classpath/javax/net/ssl/HttpsURLConnection.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2.2.1 by gnu_andrew, Fri Jan 14 10:24:16 2005 UTC revision 1.2.2.2 by gnu_andrew, Sun Jan 16 15:15:13 2005 UTC
# Line 59  public abstract class HttpsURLConnection Line 59  public abstract class HttpsURLConnection
59    // Fields.    // Fields.
60    // ------------------------------------------------------------------    // ------------------------------------------------------------------
61    
62    /** The default verifier. */    /**
63       * The default verifier.
64       * This is lazily initialized as required.
65       * @see #getDefaultHostnameVerifier
66       */
67    private static HostnameVerifier defaultVerifier;    private static HostnameVerifier defaultVerifier;
68    
69    /** The default factory. */    /**
70       * The default factory.
71       * This is lazily initialized as required.
72       * @see #getDefaultSSLSocketFactory
73       */
74    private static SSLSocketFactory defaultFactory;    private static SSLSocketFactory defaultFactory;
75    
76    /**    /**
# Line 75  public abstract class HttpsURLConnection Line 83  public abstract class HttpsURLConnection
83     */     */
84    private SSLSocketFactory factory;    private SSLSocketFactory factory;
85    
   // Static initializer.  
   // ------------------------------------------------------------------  
   
   static {  
     defaultVerifier = new TrivialHostnameVerifier();  
     try  
       {  
         defaultFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();  
       }  
     catch (Throwable t)  
       {  
         t.printStackTrace();  
       }  
   }  
   
86    // Constructor.    // Constructor.
87    // ------------------------------------------------------------------    // ------------------------------------------------------------------
88    
# Line 102  public abstract class HttpsURLConnection Line 95  public abstract class HttpsURLConnection
95    protected HttpsURLConnection(URL url) throws IOException    protected HttpsURLConnection(URL url) throws IOException
96    {    {
97      super(url);      super(url);
     hostnameVerifier = defaultVerifier;  
     factory = defaultFactory;  
98    }    }
99    
100    // Class methods.    // Class methods.
# Line 112  public abstract class HttpsURLConnection Line 103  public abstract class HttpsURLConnection
103    /**    /**
104     * Returns the default hostname verifier used in all new     * Returns the default hostname verifier used in all new
105     * connections.     * connections.
106       * If the default verifier has not been set, a new default one will be
107       * provided by this method.
108     *     *
109     * @return The default hostname verifier.     * @return The default hostname verifier.
110     */     */
111    public static HostnameVerifier getDefaultHostnameVerifier()    public static synchronized HostnameVerifier getDefaultHostnameVerifier()
112    {    {
113        if (defaultVerifier == null)
114          {
115            defaultVerifier = new TrivialHostnameVerifier();
116          }
117      return defaultVerifier;      return defaultVerifier;
118    }    }
119    
# Line 137  public abstract class HttpsURLConnection Line 134  public abstract class HttpsURLConnection
134      SecurityManager sm = System.getSecurityManager();      SecurityManager sm = System.getSecurityManager();
135      if (sm != null)      if (sm != null)
136        sm.checkPermission(new SSLPermission("setHostnameVerifier"));        sm.checkPermission(new SSLPermission("setHostnameVerifier"));
137      defaultVerifier = newDefault;      synchronized (HttpsURLConnection.class)
138          {
139            defaultVerifier = newDefault;
140          }
141    }    }
142    
143    /**    /**
144     * Returns the default SSL socket factory used in all new     * Returns the default SSL socket factory used in all new
145     * connections.     * connections.
146       * If the default SSL socket factory has not been set, a new default one
147       * will be provided by this method.
148     *     *
149     * @return The default SSL socket factory.     * @return The default SSL socket factory.
150     */     */
151    public static SSLSocketFactory getDefaultSSLSocketFactory()    public static synchronized SSLSocketFactory getDefaultSSLSocketFactory()
152    {    {
153        if (defaultFactory == null)
154          {
155            try
156              {
157                defaultFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
158              }
159            catch (Throwable t)
160              {
161                t.printStackTrace();
162              }
163          }
164      return defaultFactory;      return defaultFactory;
165    }    }
166    
# Line 168  public abstract class HttpsURLConnection Line 181  public abstract class HttpsURLConnection
181      SecurityManager sm = System.getSecurityManager();      SecurityManager sm = System.getSecurityManager();
182      if (sm != null)      if (sm != null)
183        sm.checkSetFactory();        sm.checkSetFactory();
184      defaultFactory = newDefault;      synchronized (HttpsURLConnection.class)
185          {
186            defaultFactory = newDefault;
187          }
188    }    }
189    
190    // Instance methods.    // Instance methods.
# Line 181  public abstract class HttpsURLConnection Line 197  public abstract class HttpsURLConnection
197     */     */
198    public HostnameVerifier getHostnameVerifier()    public HostnameVerifier getHostnameVerifier()
199    {    {
200        if (hostnameVerifier == null)
201          {
202            hostnameVerifier = getDefaultHostnameVerifier();
203          }
204      return hostnameVerifier;      return hostnameVerifier;
205    }    }
206    
# Line 205  public abstract class HttpsURLConnection Line 225  public abstract class HttpsURLConnection
225     */     */
226    public SSLSocketFactory getSSLSocketFactory()    public SSLSocketFactory getSSLSocketFactory()
227    {    {
228        if (factory == null)
229          {
230            factory = getDefaultSSLSocketFactory();
231          }
232      return factory;      return factory;
233    }    }
234    

Legend:
Removed from v.1.2.2.1  
changed lines
  Added in v.1.2.2.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26