View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  package org.apache.http.impl.conn;
28  
29  import org.apache.http.annotation.ThreadSafe;
30  import org.apache.http.conn.scheme.PlainSocketFactory;
31  import org.apache.http.conn.scheme.Scheme;
32  import org.apache.http.conn.scheme.SchemeRegistry;
33  import org.apache.http.conn.ssl.SSLSocketFactory;
34  
35  /**
36   * @since 4.1
37   */
38  @ThreadSafe
39  public final class SchemeRegistryFactory {
40  
41      /**
42       * Initializes default scheme registry based on JSSE defaults. System properties will
43       * not be taken into consideration.
44       */
45      public static SchemeRegistry createDefault() {
46          SchemeRegistry registry = new SchemeRegistry();
47          registry.register(
48                  new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
49          registry.register(
50                  new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
51          return registry;
52      }
53  
54      /**
55       * Initializes default scheme registry using system properties as described in
56       * <a href="http://download.oracle.com/javase/1,5.0/docs/guide/security/jsse/JSSERefGuide.html">
57       * "JavaTM Secure Socket Extension (JSSE) Reference Guide for the JavaTM 2 Platform
58       * Standard Edition 5</a>
59       * <p>
60       * The following system properties are taken into account by this method:
61       * <ul>
62       *  <li>ssl.TrustManagerFactory.algorithm</li>
63       *  <li>javax.net.ssl.trustStoreType</li>
64       *  <li>javax.net.ssl.trustStore</li>
65       *  <li>javax.net.ssl.trustStoreProvider</li>
66       *  <li>javax.net.ssl.trustStorePassword</li>
67       *  <li>java.home</li>
68       *  <li>ssl.KeyManagerFactory.algorithm</li>
69       *  <li>javax.net.ssl.keyStoreType</li>
70       *  <li>javax.net.ssl.keyStore</li>
71       *  <li>javax.net.ssl.keyStoreProvider</li>
72       *  <li>javax.net.ssl.keyStorePassword</li>
73       * </ul>
74       * <p>
75       *
76       * @since 4.2
77       */
78      public static SchemeRegistry createSystemDefault() {
79          SchemeRegistry registry = new SchemeRegistry();
80          registry.register(
81                  new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
82          registry.register(
83                  new Scheme("https", 443, SSLSocketFactory.getSystemSocketFactory()));
84          return registry;
85      }
86  }
87