java.rmi.server.RMIClientSocketFactory Java Examples

The following examples show how to use java.rmi.server.RMIClientSocketFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RmiServiceExporter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Locate or create the RMI registry for this exporter.
 * @param registryHost the registry host to use (if this is specified,
 * no implicit creation of a RMI registry will happen)
 * @param registryPort the registry port to use
 * @param clientSocketFactory the RMI client socket factory for the registry (if any)
 * @param serverSocketFactory the RMI server socket factory for the registry (if any)
 * @return the RMI registry
 * @throws RemoteException if the registry couldn't be located or created
 */
protected Registry getRegistry(String registryHost, int registryPort,
		@Nullable RMIClientSocketFactory clientSocketFactory, @Nullable RMIServerSocketFactory serverSocketFactory)
		throws RemoteException {

	if (registryHost != null) {
		// Host explicitly specified: only lookup possible.
		if (logger.isDebugEnabled()) {
			logger.debug("Looking for RMI registry at port '" + registryPort + "' of host [" + registryHost + "]");
		}
		Registry reg = LocateRegistry.getRegistry(registryHost, registryPort, clientSocketFactory);
		testRegistry(reg);
		return reg;
	}

	else {
		return getRegistry(registryPort, clientSocketFactory, serverSocketFactory);
	}
}
 
Example #2
Source File: RMIExporterTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Remote exportObject(Remote obj,
                           int port,
                           RMIClientSocketFactory csf,
                           RMIServerSocketFactory ssf)
    throws RemoteException {
    System.out.println("CustomRMIExporter::exportObject():: " +
                       "Remote = " + obj);
    if (obj.toString().startsWith(
            "javax.management.remote.rmi.RMIJRMPServerImpl"))
        rmiServerExported = true;
    if (obj.toString().startsWith(
            "javax.management.remote.rmi.RMIConnectionImpl"))
        rmiConnectionExported = true;
    return UnicastRemoteObject.exportObject(obj, port, csf, ssf);
}
 
Example #3
Source File: RmiServiceExporter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Locate or create the RMI registry for this exporter.
 * @param registryPort the registry port to use
 * @param clientSocketFactory the RMI client socket factory for the registry (if any)
 * @param serverSocketFactory the RMI server socket factory for the registry (if any)
 * @return the RMI registry
 * @throws RemoteException if the registry couldn't be located or created
 */
protected Registry getRegistry(
		int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory)
		throws RemoteException {

	if (clientSocketFactory != null) {
		if (this.alwaysCreateRegistry) {
			logger.info("Creating new RMI registry");
			return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory);
		}
		if (logger.isInfoEnabled()) {
			logger.info("Looking for RMI registry at port '" + registryPort + "', using custom socket factory");
		}
		synchronized (LocateRegistry.class) {
			try {
				// Retrieve existing registry.
				Registry reg = LocateRegistry.getRegistry(null, registryPort, clientSocketFactory);
				testRegistry(reg);
				return reg;
			}
			catch (RemoteException ex) {
				logger.debug("RMI registry access threw exception", ex);
				logger.info("Could not detect RMI registry - creating new one");
				// Assume no registry found -> create new one.
				return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory);
			}
		}
	}

	else {
		return getRegistry(registryPort);
	}
}
 
Example #4
Source File: SingleEntryRegistry.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
SingleEntryRegistry(int port,
                    RMIClientSocketFactory csf,
                    RMIServerSocketFactory ssf,
                    String name,
                    Remote object)
        throws RemoteException {
    super(port, csf, ssf, SingleEntryRegistry::singleRegistryFilter);
    this.name = name;
    this.object = object;
}
 
Example #5
Source File: RMIConnector.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkStub(Remote stub,
        Class<?> stubClass) {

    // Check remote stub is from the expected class.
    //
    if (stub.getClass() != stubClass) {
        if (!Proxy.isProxyClass(stub.getClass())) {
            throw new SecurityException(
                    "Expecting a " + stubClass.getName() + " stub!");
        } else {
            InvocationHandler handler = Proxy.getInvocationHandler(stub);
            if (handler.getClass() != RemoteObjectInvocationHandler.class)
                throw new SecurityException(
                        "Expecting a dynamic proxy instance with a " +
                        RemoteObjectInvocationHandler.class.getName() +
                        " invocation handler!");
            else
                stub = (Remote) handler;
        }
    }

    // Check RemoteRef in stub is from the expected class
    // "sun.rmi.server.UnicastRef2".
    //
    RemoteRef ref = ((RemoteObject)stub).getRef();
    if (ref.getClass() != UnicastRef2.class)
        throw new SecurityException(
                "Expecting a " + UnicastRef2.class.getName() +
                " remote reference in stub!");

    // Check RMIClientSocketFactory in stub is from the expected class
    // "javax.rmi.ssl.SslRMIClientSocketFactory".
    //
    LiveRef liveRef = ((UnicastRef2)ref).getLiveRef();
    RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
    if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class)
        throw new SecurityException(
                "Expecting a " + SslRMIClientSocketFactory.class.getName() +
                " RMI client socket factory in stub!");
}
 
Example #6
Source File: Activation.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
SystemRegistryImpl(int port,
                   RMIClientSocketFactory csf,
                   RMIServerSocketFactory ssf,
                   ActivationSystem systemStub)
    throws RemoteException
{
    super(port, csf, ssf);
    this.systemStub = systemStub;
}
 
Example #7
Source File: LiveRef.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a new live reference for a server object in the local
 * address space, to use sockets of the specified type.
 */
public LiveRef(int port,
               RMIClientSocketFactory csf,
               RMIServerSocketFactory ssf)
{
    this((new ObjID()), port, csf, ssf);
}
 
Example #8
Source File: RmiRegistryFactoryBean.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Locate or create the RMI registry.
 * @param registryPort the registry port to use
 * @param clientSocketFactory the RMI client socket factory for the registry (if any)
 * @param serverSocketFactory the RMI server socket factory for the registry (if any)
 * @return the RMI registry
 * @throws RemoteException if the registry couldn't be located or created
 */
protected Registry getRegistry(
		int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory)
		throws RemoteException {

	if (clientSocketFactory != null) {
		if (this.alwaysCreate) {
			logger.info("Creating new RMI registry");
			this.created = true;
			return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory);
		}
		if (logger.isInfoEnabled()) {
			logger.info("Looking for RMI registry at port '" + registryPort + "', using custom socket factory");
		}
		synchronized (LocateRegistry.class) {
			try {
				// Retrieve existing registry.
				Registry reg = LocateRegistry.getRegistry(null, registryPort, clientSocketFactory);
				testRegistry(reg);
				return reg;
			}
			catch (RemoteException ex) {
				logger.debug("RMI registry access threw exception", ex);
				logger.info("Could not detect RMI registry - creating new one");
				// Assume no registry found -> create new one.
				this.created = true;
				return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory);
			}
		}
	}

	else {
		return getRegistry(registryPort);
	}
}
 
Example #9
Source File: UnicastServerRef2.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Unicast server remote reference to be exported
 * on the specified port.
 */
public UnicastServerRef2(int port,
                         RMIClientSocketFactory csf,
                         RMIServerSocketFactory ssf,
                         ObjectInputFilter filter)
{
    super(new LiveRef(port, csf, ssf), filter);
}
 
Example #10
Source File: LiveRef.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public boolean remoteEquals(Object obj) {
    if (obj != null && obj instanceof LiveRef) {
        LiveRef ref = (LiveRef) obj;

        TCPEndpoint thisEp = ((TCPEndpoint) ep);
        TCPEndpoint refEp = ((TCPEndpoint) ref.ep);

        RMIClientSocketFactory thisClientFactory =
            thisEp.getClientSocketFactory();
        RMIClientSocketFactory refClientFactory =
            refEp.getClientSocketFactory();

        /**
         * Fix for 4254103: LiveRef.remoteEquals should not fail
         * if one of the objects in the comparison has a null
         * server socket.  Comparison should only consider the
         * following criteria:
         *
         * hosts, ports, client socket factories and object IDs.
         */
        if (thisEp.getPort() != refEp.getPort() ||
            !thisEp.getHost().equals(refEp.getHost()))
        {
            return false;
        }
        if ((thisClientFactory == null) ^ (refClientFactory == null)) {
            return false;
        }
        if ((thisClientFactory != null) &&
            !((thisClientFactory.getClass() ==
               refClientFactory.getClass()) &&
              (thisClientFactory.equals(refClientFactory))))
        {
            return false;
        }
        return (id.equals(ref.id));
    } else {
        return false;
    }
}
 
Example #11
Source File: RMIConnectorServer.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private static RMIServerImpl newJRMPServer(Map<String, ?> env, int port)
        throws IOException {
    RMIClientSocketFactory csf = (RMIClientSocketFactory)
        env.get(RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE);
    RMIServerSocketFactory ssf = (RMIServerSocketFactory)
        env.get(RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE);
    return new RMIJRMPServerImpl(port, csf, ssf, env);
}
 
Example #12
Source File: RMIExporterTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Remote exportObject(Remote obj,
                           int port,
                           RMIClientSocketFactory csf,
                           RMIServerSocketFactory ssf)
    throws RemoteException {
    System.out.println("CustomRMIExporter::exportObject():: " +
                       "Remote = " + obj);
    if (obj.toString().startsWith(
            "javax.management.remote.rmi.RMIJRMPServerImpl"))
        rmiServerExported = true;
    if (obj.toString().startsWith(
            "javax.management.remote.rmi.RMIConnectionImpl"))
        rmiConnectionExported = true;
    return UnicastRemoteObject.exportObject(obj, port, csf, ssf);
}
 
Example #13
Source File: UnicastServerRef2.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Unicast server remote reference to be exported
 * on the specified port.
 */
public UnicastServerRef2(int port,
                         RMIClientSocketFactory csf,
                         RMIServerSocketFactory ssf,
                         ObjectInputFilter filter)
{
    super(new LiveRef(port, csf, ssf), filter);
}
 
Example #14
Source File: RmiRegistryFactoryBean.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Locate or create the RMI registry.
 * @param registryPort the registry port to use
 * @param clientSocketFactory the RMI client socket factory for the registry (if any)
 * @param serverSocketFactory the RMI server socket factory for the registry (if any)
 * @return the RMI registry
 * @throws RemoteException if the registry couldn't be located or created
 */
protected Registry getRegistry(int registryPort,
		@Nullable RMIClientSocketFactory clientSocketFactory, @Nullable RMIServerSocketFactory serverSocketFactory)
		throws RemoteException {

	if (clientSocketFactory != null) {
		if (this.alwaysCreate) {
			logger.debug("Creating new RMI registry");
			this.created = true;
			return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory);
		}
		if (logger.isDebugEnabled()) {
			logger.debug("Looking for RMI registry at port '" + registryPort + "', using custom socket factory");
		}
		synchronized (LocateRegistry.class) {
			try {
				// Retrieve existing registry.
				Registry reg = LocateRegistry.getRegistry(null, registryPort, clientSocketFactory);
				testRegistry(reg);
				return reg;
			}
			catch (RemoteException ex) {
				logger.trace("RMI registry access threw exception", ex);
				logger.debug("Could not detect RMI registry - creating new one");
				// Assume no registry found -> create new one.
				this.created = true;
				return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory);
			}
		}
	}

	else {
		return getRegistry(registryPort);
	}
}
 
Example #15
Source File: Activation.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
SystemRegistryImpl(int port,
                   RMIClientSocketFactory csf,
                   RMIServerSocketFactory ssf,
                   ActivationSystem systemStub)
    throws RemoteException
{
    super(port, csf, ssf);
    this.systemStub = systemStub;
}
 
Example #16
Source File: Activation.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
SystemRegistryImpl(int port,
                   RMIClientSocketFactory csf,
                   RMIServerSocketFactory ssf,
                   ActivationSystem systemStub)
    throws RemoteException
{
    super(port, csf, ssf);
    this.systemStub = systemStub;
}
 
Example #17
Source File: Activation.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
SystemRegistryImpl(int port,
                   RMIClientSocketFactory csf,
                   RMIServerSocketFactory ssf,
                   ActivationSystem systemStub)
    throws RemoteException
{
    super(port, csf, ssf);
    this.systemStub = systemStub;
}
 
Example #18
Source File: AdminDUnitTestCase.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private JMXConnector createJMXConnector() throws Exception {
  JMXServiceURL url = new JMXServiceURL(this.urlString);
  RMIServerSocketFactory ssf = new MX4JServerSocketFactory(
      true, true, "any", "any", new LocalLogWriter(LogWriterImpl.FINE_LEVEL), new Properties());
  RMIClientSocketFactory csf = new SslRMIClientSocketFactory();
  
  Map env = new HashMap();
  env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);
  env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
    
  return JMXConnectorFactory.connect(url, env);
}
 
Example #19
Source File: UnicastServerRef2.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Unicast server remote reference to be exported
 * on the specified port.
 */
public UnicastServerRef2(int port,
                         RMIClientSocketFactory csf,
                         RMIServerSocketFactory ssf)
{
    super(new LiveRef(port, csf, ssf));
}
 
Example #20
Source File: TCPEndpoint.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a custom socket factory endpoint for a specified host and port.
 * This should not be used by external classes to create endpoints
 * for servers in this VM; use getLocalEndpoint instead.
 */
public TCPEndpoint(String host, int port, RMIClientSocketFactory csf,
                   RMIServerSocketFactory ssf)
{
    if (host == null)
        host = "";
    this.host = host;
    this.port = port;
    this.csf = csf;
    this.ssf = ssf;
}
 
Example #21
Source File: RMIExporterTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Remote exportObject(Remote obj,
                           int port,
                           RMIClientSocketFactory csf,
                           RMIServerSocketFactory ssf)
    throws RemoteException {
    System.out.println("CustomRMIExporter::exportObject():: " +
                       "Remote = " + obj);
    if (obj.toString().startsWith(
            "javax.management.remote.rmi.RMIJRMPServerImpl"))
        rmiServerExported = true;
    if (obj.toString().startsWith(
            "javax.management.remote.rmi.RMIConnectionImpl"))
        rmiConnectionExported = true;
    return UnicastRemoteObject.exportObject(obj, port, csf, ssf);
}
 
Example #22
Source File: RMIExporterTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Remote exportObject(Remote obj,
                           int port,
                           RMIClientSocketFactory csf,
                           RMIServerSocketFactory ssf)
    throws RemoteException {
    System.out.println("CustomRMIExporter::exportObject():: " +
                       "Remote = " + obj);
    if (obj.toString().startsWith(
            "javax.management.remote.rmi.RMIJRMPServerImpl"))
        rmiServerExported = true;
    if (obj.toString().startsWith(
            "javax.management.remote.rmi.RMIConnectionImpl"))
        rmiConnectionExported = true;
    return UnicastRemoteObject.exportObject(obj, port, csf, ssf);
}
 
Example #23
Source File: TCPEndpoint.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a custom socket factory endpoint for a specified host and port.
 * This should not be used by external classes to create endpoints
 * for servers in this VM; use getLocalEndpoint instead.
 */
public TCPEndpoint(String host, int port, RMIClientSocketFactory csf,
                   RMIServerSocketFactory ssf)
{
    if (host == null)
        host = "";
    this.host = host;
    this.port = port;
    this.csf = csf;
    this.ssf = ssf;
}
 
Example #24
Source File: SingleEntryRegistry.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
SingleEntryRegistry(int port,
                    RMIClientSocketFactory csf,
                    RMIServerSocketFactory ssf,
                    String name,
                    Remote object)
        throws RemoteException {
    super(port, csf, ssf, SingleEntryRegistry::singleRegistryFilter);
    this.name = name;
    this.object = object;
}
 
Example #25
Source File: RegistryImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a new RegistryImpl on the specified port with the
 * given custom socket factory pair.
 */
public RegistryImpl(int port,
                    RMIClientSocketFactory csf,
                    RMIServerSocketFactory ssf)
    throws RemoteException
{
    this(port, csf, ssf, RegistryImpl::registryFilter);
}
 
Example #26
Source File: UnicastServerRef2.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Unicast server remote reference to be exported
 * on the specified port.
 */
public UnicastServerRef2(int port,
                         RMIClientSocketFactory csf,
                         RMIServerSocketFactory ssf,
                         ObjectInputFilter filter)
{
    super(new LiveRef(port, csf, ssf), filter);
}
 
Example #27
Source File: UnicastServerRef2.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Unicast server remote reference to be exported
 * on the specified port.
 */
public UnicastServerRef2(int port,
                         RMIClientSocketFactory csf,
                         RMIServerSocketFactory ssf)
{
    super(new LiveRef(port, csf, ssf));
}
 
Example #28
Source File: Activation.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
SystemRegistryImpl(int port,
                   RMIClientSocketFactory csf,
                   RMIServerSocketFactory ssf,
                   ActivationSystem systemStub)
    throws RemoteException
{
    super(port, csf, ssf);
    this.systemStub = systemStub;
}
 
Example #29
Source File: RMIConnectorServer.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private static RMIServerImpl newJRMPServer(Map<String, ?> env, int port)
        throws IOException {
    RMIClientSocketFactory csf = (RMIClientSocketFactory)
        env.get(RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE);
    RMIServerSocketFactory ssf = (RMIServerSocketFactory)
        env.get(RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE);
    return new RMIJRMPServerImpl(port, csf, ssf, env);
}
 
Example #30
Source File: UnicastServerRef2.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Unicast server remote reference to be exported
 * on the specified port.
 */
public UnicastServerRef2(int port,
                         RMIClientSocketFactory csf,
                         RMIServerSocketFactory ssf)
{
    super(new LiveRef(port, csf, ssf));
}