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);
}
}
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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
Aggregations