Search in sources :

Example 1 with RemoteLookupFailureException

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);
    }
}
Also used : Context(javax.naming.Context) RemoteConnectFailureException(org.springframework.remoting.RemoteConnectFailureException) NamingException(javax.naming.NamingException) RemoteLookupFailureException(org.springframework.remoting.RemoteLookupFailureException) RemoteException(java.rmi.RemoteException)

Example 2 with RemoteLookupFailureException

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);
    }
}
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 3 with RemoteLookupFailureException

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);
}
Also used : Service(com.emc.storageos.coordinator.common.Service) RemoteLookupFailureException(org.springframework.remoting.RemoteLookupFailureException) RemoteException(java.rmi.RemoteException) URI(java.net.URI) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

RemoteException (java.rmi.RemoteException)3 RemoteLookupFailureException (org.springframework.remoting.RemoteLookupFailureException)3 Service (com.emc.storageos.coordinator.common.Service)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URL (java.net.URL)1 NotBoundException (java.rmi.NotBoundException)1 Remote (java.rmi.Remote)1 LocateRegistry (java.rmi.registry.LocateRegistry)1 Registry (java.rmi.registry.Registry)1 Context (javax.naming.Context)1 NamingException (javax.naming.NamingException)1 RemoteConnectFailureException (org.springframework.remoting.RemoteConnectFailureException)1