use of org.springframework.remoting.RemoteLookupFailureException in project spring-framework by spring-projects.
the class JndiRmiClientInterceptor method invoke.
/**
* Fetches an RMI stub and delegates to {@link #doInvoke}.
* If configured to refresh on connect failure, it will call
* {@link #refreshAndRetry} on corresponding RMI exceptions.
* @see #getStub
* @see #doInvoke
* @see #refreshAndRetry
* @see java.rmi.ConnectException
* @see java.rmi.ConnectIOException
* @see java.rmi.NoSuchObjectException
*/
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
Object stub;
try {
stub = getStub();
} catch (NamingException ex) {
throw new RemoteLookupFailureException("JNDI lookup for RMI service [" + getJndiName() + "] failed", ex);
}
Context ctx = (this.exposeAccessContext ? getJndiTemplate().getContext() : null);
try {
return doInvoke(invocation, stub);
} catch (RemoteConnectFailureException ex) {
return handleRemoteConnectFailure(invocation, ex);
} catch (RemoteException ex) {
if (isConnectFailure(ex)) {
return handleRemoteConnectFailure(invocation, ex);
} else {
throw ex;
}
} finally {
getJndiTemplate().releaseContext(ctx);
}
}
use of org.springframework.remoting.RemoteLookupFailureException 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 org.springframework.remoting.RemoteLookupFailureException in project coprhd-controller by CoprHD.
the class RmiInvocationHandler method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
List<Service> services = _client.locateAllServices(_name, _version, _tag, _endpointKey);
if (services == null || services.isEmpty()) {
throw CoordinatorException.fatals.endPointUnavailable();
}
_log.info("Invoking task {}: {} ", method, args);
Throwable lastError = null;
for (int index = 0; index < services.size(); index++) {
Service svc = services.get(index);
URI endpoint = null;
if (_endpointKey != null) {
endpoint = svc.getEndpoint(_endpointKey);
} else {
endpoint = svc.getEndpoint();
}
Object rmiProxy = _proxyMap.get(endpoint);
try {
if (rmiProxy == null) {
rmiProxy = createRmiProxy(endpoint);
}
_log.info("Sending RMI request to {} ", endpoint);
return method.invoke(rmiProxy, args);
} catch (RemoteLookupFailureException e) {
lastError = e;
_log.warn("Unable to lookup registry at {}", endpoint);
continue;
} catch (InvocationTargetException e) {
Throwable target = e.getTargetException();
if (target instanceof RemoteException || target instanceof RemoteLookupFailureException) {
// fail over to next host
lastError = target;
_log.warn("Remote exception trying to reach {}", endpoint, target);
continue;
}
throw target;
}
}
throw CoordinatorException.fatals.unableToConnectToEndpoint(lastError);
}
Aggregations