Search in sources :

Example 41 with Registry

use of java.rmi.registry.Registry in project spring-framework by spring-projects.

the class RmiClientInterceptor method lookupStub.

/**
	 * Create the RMI stub, typically by looking it up.
	 * <p>Called on interceptor initialization if "cacheStub" is "true";
	 * else called for each invocation by {@link #getStub()}.
	 * <p>The default implementation looks up the service URL via
	 * {@code java.rmi.Naming}. This can be overridden in subclasses.
	 * @return the RMI stub to store in this interceptor
	 * @throws RemoteLookupFailureException if RMI stub creation failed
	 * @see #setCacheStub
	 * @see java.rmi.Naming#lookup
	 */
protected Remote lookupStub() throws RemoteLookupFailureException {
    try {
        Remote stub = null;
        if (this.registryClientSocketFactory != null) {
            // RMIClientSocketFactory specified for registry access.
            // Unfortunately, due to RMI API limitations, this means
            // that we need to parse the RMI URL ourselves and perform
            // straight LocateRegistry.getRegistry/Registry.lookup calls.
            URL url = new URL(null, getServiceUrl(), new DummyURLStreamHandler());
            String protocol = url.getProtocol();
            if (protocol != null && !"rmi".equals(protocol)) {
                throw new MalformedURLException("Invalid URL scheme '" + protocol + "'");
            }
            String host = url.getHost();
            int port = url.getPort();
            String name = url.getPath();
            if (name != null && name.startsWith("/")) {
                name = name.substring(1);
            }
            Registry registry = LocateRegistry.getRegistry(host, port, this.registryClientSocketFactory);
            stub = registry.lookup(name);
        } else {
            // Can proceed with standard RMI lookup API...
            stub = Naming.lookup(getServiceUrl());
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Located RMI stub with URL [" + getServiceUrl() + "]");
        }
        return stub;
    } catch (MalformedURLException ex) {
        throw new RemoteLookupFailureException("Service URL [" + getServiceUrl() + "] is invalid", ex);
    } catch (NotBoundException ex) {
        throw new RemoteLookupFailureException("Could not find RMI service [" + getServiceUrl() + "] in RMI registry", ex);
    } catch (RemoteException ex) {
        throw new RemoteLookupFailureException("Lookup of RMI stub failed", ex);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) NotBoundException(java.rmi.NotBoundException) Remote(java.rmi.Remote) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) RemoteLookupFailureException(org.springframework.remoting.RemoteLookupFailureException) RemoteException(java.rmi.RemoteException) URL(java.net.URL)

Example 42 with Registry

use of java.rmi.registry.Registry in project spring-framework by spring-projects.

the class RmiRegistryFactoryBean method getRegistry.

/**
	 * 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);
    }
}
Also used : LocateRegistry(java.rmi.registry.LocateRegistry) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) RemoteException(java.rmi.RemoteException)

Example 43 with Registry

use of java.rmi.registry.Registry in project spring-framework by spring-projects.

the class RmiServiceExporter method getRegistry.

/**
	 * Locate or create the RMI registry for this exporter.
	 * @param registryPort the registry port to use
	 * @return the RMI registry
	 * @throws RemoteException if the registry couldn't be located or created
	 */
protected Registry getRegistry(int registryPort) throws RemoteException {
    if (this.alwaysCreateRegistry) {
        logger.info("Creating new RMI registry");
        return LocateRegistry.createRegistry(registryPort);
    }
    if (logger.isInfoEnabled()) {
        logger.info("Looking for RMI registry at port '" + registryPort + "'");
    }
    synchronized (LocateRegistry.class) {
        try {
            // Retrieve existing registry.
            Registry reg = LocateRegistry.getRegistry(registryPort);
            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);
        }
    }
}
Also used : LocateRegistry(java.rmi.registry.LocateRegistry) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) RemoteException(java.rmi.RemoteException)

Example 44 with Registry

use of java.rmi.registry.Registry in project spring-framework by spring-projects.

the class RmiServiceExporter method getRegistry.

/**
	 * 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, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException {
    if (registryHost != null) {
        // Host explicitly specified: only lookup possible.
        if (logger.isInfoEnabled()) {
            logger.info("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);
    }
}
Also used : LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry)

Example 45 with Registry

use of java.rmi.registry.Registry in project spring-framework by spring-projects.

the class RmiServiceExporter method getRegistry.

/**
	 * 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);
    }
}
Also used : LocateRegistry(java.rmi.registry.LocateRegistry) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) RemoteException(java.rmi.RemoteException)

Aggregations

Registry (java.rmi.registry.Registry)77 LocateRegistry (java.rmi.registry.LocateRegistry)71 RemoteException (java.rmi.RemoteException)35 Remote (java.rmi.Remote)12 HashMap (java.util.HashMap)9 JMXServiceURL (javax.management.remote.JMXServiceURL)9 IOException (java.io.IOException)8 JMXConnector (javax.management.remote.JMXConnector)8 UnknownHostException (java.net.UnknownHostException)7 MBeanServer (javax.management.MBeanServer)7 MBeanServerConnection (javax.management.MBeanServerConnection)7 JMXConnectorServer (javax.management.remote.JMXConnectorServer)7 ObjectName (javax.management.ObjectName)6 JMXPluggableAuthenticator (com.sun.jmx.remote.security.JMXPluggableAuthenticator)5 InetAddress (java.net.InetAddress)5 MalformedURLException (java.net.MalformedURLException)5 AlreadyBoundException (java.rmi.AlreadyBoundException)5 Properties (java.util.Properties)5 Attribute (javax.management.Attribute)5 Notification (javax.management.Notification)5