Java Code Examples for java.rmi.server.RMIServerSocketFactory

The following examples show how to use java.rmi.server.RMIServerSocketFactory. These examples are extracted from open source projects. 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
/**
 * Return new server socket to listen for connections on this endpoint.
 */
ServerSocket newServerSocket() throws IOException {
    if (TCPTransport.tcpLog.isLoggable(Log.VERBOSE)) {
        TCPTransport.tcpLog.log(Log.VERBOSE,
            "creating server socket on " + this);
    }

    RMIServerSocketFactory serverFactory = ssf;
    if (serverFactory == null) {
        serverFactory = chooseFactory();
    }
    ServerSocket server = serverFactory.createServerSocket(listenPort);

    // if we listened on an anonymous port, set the default port
    // (for this socket factory)
    if (listenPort == 0)
        setDefaultPort(server.getLocalPort(), csf, ssf);

    return server;
}
 
Example 2
Source Project: java-technology-stack   Source File: RmiServiceExporter.java    License: 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 3
Source Project: openjdk-8-source   Source File: TCPEndpoint.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return new server socket to listen for connections on this endpoint.
 */
ServerSocket newServerSocket() throws IOException {
    if (TCPTransport.tcpLog.isLoggable(Log.VERBOSE)) {
        TCPTransport.tcpLog.log(Log.VERBOSE,
            "creating server socket on " + this);
    }

    RMIServerSocketFactory serverFactory = ssf;
    if (serverFactory == null) {
        serverFactory = chooseFactory();
    }
    ServerSocket server = serverFactory.createServerSocket(listenPort);

    // if we listened on an anonymous port, set the default port
    // (for this socket factory)
    if (listenPort == 0)
        setDefaultPort(server.getLocalPort(), csf, ssf);

    return server;
}
 
Example 4
/**
 * Creates a default activation group implementation.
 *
 * @param id the group's identifier
 * @param data ignored
 */
public ActivationGroupImpl(ActivationGroupID id, MarshalledObject<?> data)
    throws RemoteException
{
    super(id);
    groupID = id;

    /*
     * Unexport activation group impl and attempt to export it on
     * an unshared anonymous port.  See 4692286.
     */
    unexportObject(this, true);
    RMIServerSocketFactory ssf = new ServerSocketFactoryImpl();
    UnicastRemoteObject.exportObject(this, 0, null, ssf);

    if (System.getSecurityManager() == null) {
        try {
            // Provide a default security manager.
            System.setSecurityManager(new SecurityManager());

        } catch (Exception e) {
            throw new RemoteException("unable to set security manager", e);
        }
    }
}
 
Example 5
Source Project: openjdk-8   Source File: TCPEndpoint.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return new server socket to listen for connections on this endpoint.
 */
ServerSocket newServerSocket() throws IOException {
    if (TCPTransport.tcpLog.isLoggable(Log.VERBOSE)) {
        TCPTransport.tcpLog.log(Log.VERBOSE,
            "creating server socket on " + this);
    }

    RMIServerSocketFactory serverFactory = ssf;
    if (serverFactory == null) {
        serverFactory = chooseFactory();
    }
    ServerSocket server = serverFactory.createServerSocket(listenPort);

    // if we listened on an anonymous port, set the default port
    // (for this socket factory)
    if (listenPort == 0)
        setDefaultPort(server.getLocalPort(), csf, ssf);

    return server;
}
 
Example 6
@Override
protected Registry getRegistry(
        String registryHost,
        int registryPort,
        RMIClientSocketFactory clientSocketFactory,
        RMIServerSocketFactory serverSocketFactory) throws RemoteException
{
    if(enabled)
    {
        return super.getRegistry(registryHost, registryPort, clientSocketFactory, serverSocketFactory);
    }
    else
    {
        throw new RemoteException(ERR_MSG_NOT_ENABLED);
    }
}
 
Example 7
/**
 * Creates a default activation group implementation.
 *
 * @param id the group's identifier
 * @param data ignored
 */
public ActivationGroupImpl(ActivationGroupID id, MarshalledObject<?> data)
    throws RemoteException
{
    super(id);
    groupID = id;

    /*
     * Unexport activation group impl and attempt to export it on
     * an unshared anonymous port.  See 4692286.
     */
    unexportObject(this, true);
    RMIServerSocketFactory ssf = new ServerSocketFactoryImpl();
    UnicastRemoteObject.exportObject(this, 0, null, ssf);

    if (System.getSecurityManager() == null) {
        try {
            // Provide a default security manager.
            System.setSecurityManager(new SecurityManager());

        } catch (Exception e) {
            throw new RemoteException("unable to set security manager", e);
        }
    }
}
 
Example 8
Source Project: hottub   Source File: Activation.java    License: 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 9
Source Project: jdk8u-jdk   Source File: Activation.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Recover activation state from the reliable log and initialize
 * activation services.
 */
private static void startActivation(int port,
                                    RMIServerSocketFactory ssf,
                                    String logName,
                                    String[] childArgs)
    throws Exception
{
    ReliableLog log = new ReliableLog(logName, new ActLogHandler());
    Activation state = (Activation) log.recover();
    state.init(port, ssf, log, childArgs);
}
 
Example 10
Source Project: spring-analysis-note   Source File: RmiServiceExporter.java    License: MIT License 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,
		@Nullable RMIClientSocketFactory clientSocketFactory, @Nullable RMIServerSocketFactory serverSocketFactory)
		throws RemoteException {

	if (clientSocketFactory != null) {
		if (this.alwaysCreateRegistry) {
			logger.debug("Creating new RMI registry");
			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.
				return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory);
			}
		}
	}

	else {
		return getRegistry(registryPort);
	}
}
 
Example 11
Source Project: jdk8u_jdk   Source File: RegistryImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ObjectInputFilter to filter Registry input objects.
 * The list of acceptable classes is limited to classes normally
 * stored in a registry.
 *
 * @param filterInfo access to the class, array length, etc.
 * @return  {@link ObjectInputFilter.Status#ALLOWED} if allowed,
 *          {@link ObjectInputFilter.Status#REJECTED} if rejected,
 *          otherwise {@link ObjectInputFilter.Status#UNDECIDED}
 */
private static ObjectInputFilter.Status registryFilter(ObjectInputFilter.FilterInfo filterInfo) {
    if (registryFilter != null) {
        ObjectInputFilter.Status status = registryFilter.checkInput(filterInfo);
        if (status != ObjectInputFilter.Status.UNDECIDED) {
            // The Registry filter can override the built-in white-list
            return status;
        }
    }

    if (filterInfo.depth() > REGISTRY_MAX_DEPTH) {
        return ObjectInputFilter.Status.REJECTED;
    }
    Class<?> clazz = filterInfo.serialClass();
    if (clazz != null) {
        if (clazz.isArray()) {
            // Arrays are REJECTED only if they exceed the limit
            return (filterInfo.arrayLength() >= 0 && filterInfo.arrayLength() > REGISTRY_MAX_ARRAY_SIZE)
                ? ObjectInputFilter.Status.REJECTED
                : ObjectInputFilter.Status.UNDECIDED;
        }
        if (String.class == clazz
                || java.lang.Number.class.isAssignableFrom(clazz)
                || Remote.class.isAssignableFrom(clazz)
                || java.lang.reflect.Proxy.class.isAssignableFrom(clazz)
                || UnicastRef.class.isAssignableFrom(clazz)
                || RMIClientSocketFactory.class.isAssignableFrom(clazz)
                || RMIServerSocketFactory.class.isAssignableFrom(clazz)
                || java.rmi.activation.ActivationID.class.isAssignableFrom(clazz)
                || java.rmi.server.UID.class.isAssignableFrom(clazz)) {
            return ObjectInputFilter.Status.ALLOWED;
        } else {
            return ObjectInputFilter.Status.REJECTED;
        }
    }
    return ObjectInputFilter.Status.UNDECIDED;
}
 
Example 12
Source Project: openAGV   Source File: SecureSocketFactoryProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RMIServerSocketFactory getServerSocketFactory() {
  SSLContext context = secureSslContextFactory.createServerContext();
  SSLParameters param = context.getSupportedSSLParameters();
  return new SslRMIServerSocketFactory(context,
                                       param.getCipherSuites(),
                                       param.getProtocols(),
                                       param.getWantClientAuth());
}
 
Example 13
SingleEntryRegistry(int port,
                    RMIClientSocketFactory csf,
                    RMIServerSocketFactory ssf,
                    String name,
                    Remote object)
        throws RemoteException {
    super(port, csf, ssf);
    this.name = name;
    this.object = object;
}
 
Example 14
Source Project: jdk8u60   Source File: SingleEntryRegistry.java    License: 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);
    this.name = name;
    this.object = object;
}
 
Example 15
Source Project: hottub   Source File: TCPEndpoint.java    License: 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 16
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 17
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 18
Source Project: gemfirexd-oss   Source File: AdminDUnitTestCase.java    License: 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 Project: dragonwell8_jdk   Source File: Activation.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Recover activation state from the reliable log and initialize
 * activation services.
 */
private static void startActivation(int port,
                                    RMIServerSocketFactory ssf,
                                    String logName,
                                    String[] childArgs)
    throws Exception
{
    ReliableLog log = new ReliableLog(logName, new ActLogHandler());
    Activation state = (Activation) log.recover();
    state.init(port, ssf, log, childArgs);
}
 
Example 20
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 21
ActivationSystemImpl(int port, RMIServerSocketFactory ssf)
    throws RemoteException
{
    /* Server ref must be created and assigned before remote object
     * 'this' can be exported.
     */
    LiveRef lref = new LiveRef(new ObjID(4), port, null, ssf);
    UnicastServerRef uref = new SameHostOnlyServerRef(lref,
            "ActivationSystem.nonLocalAccess");
    ref = uref;
    uref.exportObject(this, null);
}
 
Example 22
Source Project: JDKSourceCode1.8   Source File: RMIJRMPServerImpl.java    License: MIT License 5 votes vote down vote up
/**
 * <p>Creates a new {@link RMIServer} object that will be exported
 * on the given port using the given socket factories.</p>
 *
 * @param port the port on which this object and the {@link
 * RMIConnectionImpl} objects it creates will be exported.  Can be
 * zero, to indicate any available port.
 *
 * @param csf the client socket factory for the created RMI
 * objects.  Can be null.
 *
 * @param ssf the server socket factory for the created RMI
 * objects.  Can be null.
 *
 * @param env the environment map.  Can be null.
 *
 * @exception IOException if the {@link RMIServer} object
 * cannot be created.
 *
 * @exception IllegalArgumentException if <code>port</code> is
 * negative.
 */
public RMIJRMPServerImpl(int port,
                         RMIClientSocketFactory csf,
                         RMIServerSocketFactory ssf,
                         Map<String,?> env)
        throws IOException {

    super(env);

    if (port < 0)
        throw new IllegalArgumentException("Negative port: " + port);

    this.port = port;
    this.csf = csf;
    this.ssf = ssf;
    this.env = (env == null) ? Collections.<String, Object>emptyMap() : env;

    String[] credentialsTypes
            = (String[]) this.env.get(EnvHelp.CREDENTIAL_TYPES);
    List<String> types = null;
    if (credentialsTypes != null) {
        types = new ArrayList<>();
        for (String type : credentialsTypes) {
            if (type == null) {
                throw new IllegalArgumentException("A credential type is null.");
            }
            ReflectUtil.checkPackageAccess(type);
            types.add(type);
        }
    }
    exportedWrapper = types != null ?
            new ExportedWrapper(this, types) :
            null;
}
 
Example 23
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 24
Source Project: jdk8u_jdk   Source File: UnicastServerRef2.java    License: 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 25
Source Project: jdk8u60   Source File: RMIExporterTest.java    License: 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 26
Source Project: jdk8u-jdk   Source File: Activation.java    License: GNU General Public License v2.0 5 votes vote down vote up
ActivationSystemImpl(int port, RMIServerSocketFactory ssf)
    throws RemoteException
{
    /* Server ref must be created and assigned before remote object
     * 'this' can be exported.
     */
    LiveRef lref = new LiveRef(new ObjID(4), port, null, ssf);
    UnicastServerRef uref = new UnicastServerRef(lref);
    ref = uref;
    uref.exportObject(this, null);
}
 
Example 27
Source Project: jdk8u_jdk   Source File: TCPEndpoint.java    License: 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 28
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 29
Source Project: jdk8u60   Source File: Activation.java    License: GNU General Public License v2.0 5 votes vote down vote up
ActivationSystemImpl(int port, RMIServerSocketFactory ssf)
    throws RemoteException
{
    /* Server ref must be created and assigned before remote object
     * 'this' can be exported.
     */
    LiveRef lref = new LiveRef(new ObjID(4), port, null, ssf);
    UnicastServerRef uref = new UnicastServerRef(lref);
    ref = uref;
    uref.exportObject(this, null);
}
 
Example 30
Source Project: jdk8u-jdk   Source File: Activation.java    License: 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;
}