src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java

Print this page




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package sun.rmi.transport.proxy;
  26 
  27 import java.io.*;
  28 import java.net.*;
  29 import java.security.*;
  30 import java.util.*;
  31 import java.rmi.server.LogStream;
  32 import java.rmi.server.RMISocketFactory;
  33 import sun.rmi.runtime.Log;
  34 import sun.rmi.runtime.NewThreadAction;
  35 import sun.security.action.GetBooleanAction;
  36 import sun.security.action.GetLongAction;
  37 import sun.security.action.GetPropertyAction;
  38 
  39 /**
  40  * RMIMasterSocketFactory attempts to create a socket connection to the
  41  * specified host using successively less efficient mechanisms
  42  * until one succeeds.  If the host is successfully connected to,
  43  * the factory for the successful mechanism is stored in an internal
  44  * hash table keyed by the host name, so that future attempts to
  45  * connect to the same host will automatically use the same
  46  * mechanism.
  47  */
  48 @SuppressWarnings("deprecation")
  49 public class RMIMasterSocketFactory extends RMISocketFactory {
  50 
  51     /** "proxy" package log level */
  52     static int logLevel = LogStream.parseLevel(getLogLevel());
  53 
  54     private static String getLogLevel() {
  55         return java.security.AccessController.doPrivileged(
  56             new sun.security.action.GetPropertyAction("sun.rmi.transport.proxy.logLevel"));
  57     }
  58 
  59     /* proxy package log */
  60     static final Log proxyLog =
  61         Log.getLog("sun.rmi.transport.tcp.proxy",
  62                    "transport", RMIMasterSocketFactory.logLevel);
  63 
  64     /** timeout for attemping direct socket connections */
  65     private static long connectTimeout = getConnectTimeout();
  66 
  67     private static long getConnectTimeout() {
  68         return java.security.AccessController.doPrivileged(
  69                 new GetLongAction("sun.rmi.transport.proxy.connectTimeout",
  70                               15000)).longValue(); // default: 15 seconds
  71     }
  72 
  73     /** whether to fallback to HTTP on general connect failures */
  74     private static final boolean eagerHttpFallback =
  75         java.security.AccessController.doPrivileged(new GetBooleanAction(
  76             "sun.rmi.transport.proxy.eagerHttpFallback")).booleanValue();
  77 
  78     /** table of hosts successfully connected to and the factory used */
  79     private Hashtable<String, RMISocketFactory> successTable =
  80         new Hashtable<>();
  81 
  82     /** maximum number of hosts to remember successful connection to */
  83     private static final int MaxRememberedHosts = 64;
  84 
  85     /** list of the hosts in successTable in initial connection order */
  86     private Vector<String> hostList = new Vector<>(MaxRememberedHosts);
  87 
  88     /** default factory for initial use for direct socket connection */
  89     protected RMISocketFactory initialFactory = new RMIDirectSocketFactory();
  90 
  91     /** ordered list of factories to try as alternate connection
  92       * mechanisms if a direct socket connections fails */
  93     protected Vector<RMISocketFactory> altFactoryList;
  94 
  95     /**
  96      * Create a RMIMasterSocketFactory object.  Establish order of
  97      * connection mechanisms to attempt on createSocket, if a direct
  98      * socket connection fails.
  99      */
 100     public RMIMasterSocketFactory() {
 101         altFactoryList = new Vector<>(2);
 102         boolean setFactories = false;
 103 
 104         try {
 105             String proxyHost;
 106             proxyHost = java.security.AccessController.doPrivileged(
 107                 new GetPropertyAction("http.proxyHost"));
 108 
 109             if (proxyHost == null)
 110                 proxyHost = java.security.AccessController.doPrivileged(
 111                     new GetPropertyAction("proxyHost"));
 112 
 113             boolean disable = java.security.AccessController.doPrivileged(
 114                 new GetPropertyAction("java.rmi.server.disableHttp", "true"))
 115                 .equalsIgnoreCase("true");
 116 
 117             if (!disable && proxyHost != null && proxyHost.length() > 0) {
 118                 setFactories = true;
 119             }
 120         } catch (Exception e) {
 121             // unable to obtain the properties, so use the default behavior.
 122         }
 123 
 124         if (setFactories) {
 125             altFactoryList.addElement(new RMIHttpToPortSocketFactory());
 126             altFactoryList.addElement(new RMIHttpToCGISocketFactory());
 127         }
 128     }
 129 
 130     /**
 131      * Create a new client socket.  If we remember connecting to this host
 132      * successfully before, then use the same factory again.  Otherwise,
 133      * try using a direct socket connection and then the alternate factories
 134      * in the order specified in altFactoryList.




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package sun.rmi.transport.proxy;
  26 
  27 import java.io.*;
  28 import java.net.*;
  29 import java.security.*;
  30 import java.util.*;
  31 import java.rmi.server.LogStream;
  32 import java.rmi.server.RMISocketFactory;
  33 import sun.rmi.runtime.Log;
  34 import sun.rmi.runtime.NewThreadAction;



  35 
  36 /**
  37  * RMIMasterSocketFactory attempts to create a socket connection to the
  38  * specified host using successively less efficient mechanisms
  39  * until one succeeds.  If the host is successfully connected to,
  40  * the factory for the successful mechanism is stored in an internal
  41  * hash table keyed by the host name, so that future attempts to
  42  * connect to the same host will automatically use the same
  43  * mechanism.
  44  */
  45 @SuppressWarnings("deprecation")
  46 public class RMIMasterSocketFactory extends RMISocketFactory {
  47 
  48     /** "proxy" package log level */
  49     static int logLevel = LogStream.parseLevel(getLogLevel());
  50 
  51     private static String getLogLevel() {
  52         return java.security.AccessController.doPrivileged(
  53             (PrivilegedAction<String>) () -> System.getProperty("sun.rmi.transport.proxy.logLevel"));
  54     }
  55 
  56     /* proxy package log */
  57     static final Log proxyLog =
  58         Log.getLog("sun.rmi.transport.tcp.proxy",
  59                    "transport", RMIMasterSocketFactory.logLevel);
  60 
  61     /** timeout for attemping direct socket connections */
  62     private static long connectTimeout = getConnectTimeout();
  63 
  64     private static long getConnectTimeout() {
  65         return java.security.AccessController.doPrivileged((PrivilegedAction<Long>) () ->
  66             Long.getLong("sun.rmi.transport.proxy.connectTimeout", 15000)); // default: 15 seconds

  67     }
  68 
  69     /** whether to fallback to HTTP on general connect failures */
  70     private static final boolean eagerHttpFallback =
  71         java.security.AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
  72             Boolean.getBoolean("sun.rmi.transport.proxy.eagerHttpFallback"));
  73 
  74     /** table of hosts successfully connected to and the factory used */
  75     private Hashtable<String, RMISocketFactory> successTable =
  76         new Hashtable<>();
  77 
  78     /** maximum number of hosts to remember successful connection to */
  79     private static final int MaxRememberedHosts = 64;
  80 
  81     /** list of the hosts in successTable in initial connection order */
  82     private Vector<String> hostList = new Vector<>(MaxRememberedHosts);
  83 
  84     /** default factory for initial use for direct socket connection */
  85     protected RMISocketFactory initialFactory = new RMIDirectSocketFactory();
  86 
  87     /** ordered list of factories to try as alternate connection
  88       * mechanisms if a direct socket connections fails */
  89     protected Vector<RMISocketFactory> altFactoryList;
  90 
  91     /**
  92      * Create a RMIMasterSocketFactory object.  Establish order of
  93      * connection mechanisms to attempt on createSocket, if a direct
  94      * socket connection fails.
  95      */
  96     public RMIMasterSocketFactory() {
  97         altFactoryList = new Vector<>(2);
  98         boolean setFactories = false;
  99 
 100         try {
 101             String proxyHost;
 102             proxyHost = java.security.AccessController.doPrivileged(
 103                (PrivilegedAction<String>) () -> System.getProperty("http.proxyHost"));
 104 
 105             if (proxyHost == null)
 106                 proxyHost = java.security.AccessController.doPrivileged(
 107                     (PrivilegedAction<String>) () -> System.getProperty("proxyHost"));
 108 
 109             boolean disable = java.security.AccessController.doPrivileged(
 110                 (PrivilegedAction<String>) () -> System.getProperty("java.rmi.server.disableHttp", "true"))
 111                 .equalsIgnoreCase("true");
 112 
 113             if (!disable && proxyHost != null && proxyHost.length() > 0) {
 114                 setFactories = true;
 115             }
 116         } catch (Exception e) {
 117             // unable to obtain the properties, so use the default behavior.
 118         }
 119 
 120         if (setFactories) {
 121             altFactoryList.addElement(new RMIHttpToPortSocketFactory());
 122             altFactoryList.addElement(new RMIHttpToCGISocketFactory());
 123         }
 124     }
 125 
 126     /**
 127      * Create a new client socket.  If we remember connecting to this host
 128      * successfully before, then use the same factory again.  Otherwise,
 129      * try using a direct socket connection and then the alternate factories
 130      * in the order specified in altFactoryList.