Search in sources :

Example 21 with RemoteException

use of java.rmi.RemoteException in project otter by alibaba.

the class JmxConnectorServerFactoryBean method getRegistry.

private 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 + "'");
    }
    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) Registry(java.rmi.registry.Registry) RemoteException(java.rmi.RemoteException)

Example 22 with RemoteException

use of java.rmi.RemoteException in project camel by apache.

the class RmiConsumer method invoke.

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (!isStarted()) {
        throw new IllegalStateException("The endpoint is not active: " + getEndpoint().getEndpointUri());
    }
    BeanInvocation invocation = new BeanInvocation(method, args);
    Exchange exchange = getEndpoint().createExchange();
    exchange.getIn().setBody(invocation);
    try {
        log.debug("Invoking {} with args {}", method, args);
        getProcessor().process(exchange);
    } catch (Exception e) {
        exchange.setException(e);
    }
    // is there a matching exception from the signature, then throw that
    // or fallback and ensure the exception is thrown as a RemoteException
    Throwable fault = exchange.getException();
    if (fault != null) {
        Object match = null;
        for (Class<?> type : method.getExceptionTypes()) {
            Object found = exchange.getException(type);
            if (found != null) {
                match = found;
                break;
            }
        }
        if (match != null && match instanceof Throwable) {
            // we have a match
            throw (Throwable) match;
        } else {
            throw new RemoteException("Error invoking " + method, fault);
        }
    }
    return exchange.getOut().getBody();
}
Also used : Exchange(org.apache.camel.Exchange) BeanInvocation(org.apache.camel.component.bean.BeanInvocation) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) RemoteException(java.rmi.RemoteException) RemoteException(java.rmi.RemoteException)

Example 23 with RemoteException

use of java.rmi.RemoteException in project guice by google.

the class ThrowingProviderTest method testProviderMethodWithManyExceptions.

public void testProviderMethodWithManyExceptions() {
    try {
        Guice.createInjector(new AbstractModule() {

            @Override
            protected void configure() {
                install(ThrowingProviderBinder.forModule(this));
            }

            @SuppressWarnings("unused")
            @CheckedProvides(RemoteProvider.class)
            String foo() throws InterruptedException, RuntimeException, RemoteException, AccessException, TooManyListenersException {
                return null;
            }
        });
        fail();
    } catch (CreationException ce) {
        // The only two that should fail are Interrupted & TooManyListeners.. the rest are OK.
        List<Message> errors = ImmutableList.copyOf(ce.getErrorMessages());
        assertEquals(InterruptedException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", errors.get(0).getMessage());
        assertEquals(TooManyListenersException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", errors.get(1).getMessage());
        assertEquals(2, errors.size());
    }
}
Also used : CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule) TooManyListenersException(java.util.TooManyListenersException) AccessException(java.rmi.AccessException) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) RemoteException(java.rmi.RemoteException)

Example 24 with RemoteException

use of java.rmi.RemoteException in project guice by google.

the class CheckedProviderTest method tExceptionsNotScopedWhenNotExceptionScoping.

private void tExceptionsNotScopedWhenNotExceptionScoping(Injector injector) throws Exception {
    RemoteProvider<Foo> remoteProvider = injector.getInstance(Key.get(remoteProviderOfFoo, NotExceptionScoping.class));
    mockRemoteProvider.throwOnNextGet(new RemoteException("A"));
    MockFoo.nextToThrow = new RemoteException("A");
    try {
        remoteProvider.get();
        fail();
    } catch (RemoteException expected) {
        assertEquals("A", expected.getMessage());
    }
    mockRemoteProvider.throwOnNextGet(new RemoteException("B"));
    MockFoo.nextToThrow = new RemoteException("B");
    try {
        remoteProvider.get();
        fail();
    } catch (RemoteException expected) {
        assertEquals("B", expected.getMessage());
    }
}
Also used : RemoteException(java.rmi.RemoteException)

Example 25 with RemoteException

use of java.rmi.RemoteException in project guice by google.

the class CheckedProviderTest method tExceptionsScoped.

private void tExceptionsScoped(Injector injector) throws Exception {
    RemoteProvider<Foo> remoteProvider = injector.getInstance(Key.get(remoteProviderOfFoo));
    mockRemoteProvider.throwOnNextGet(new RemoteException("A"));
    MockFoo.nextToThrow = new RemoteException("A");
    try {
        remoteProvider.get();
        fail();
    } catch (RemoteException expected) {
        assertEquals("A", expected.getMessage());
    }
    mockRemoteProvider.throwOnNextGet(new RemoteException("B"));
    MockFoo.nextToThrow = new RemoteException("B");
    try {
        remoteProvider.get();
        fail();
    } catch (RemoteException expected) {
        assertEquals("A", expected.getMessage());
    }
}
Also used : RemoteException(java.rmi.RemoteException)

Aggregations

RemoteException (java.rmi.RemoteException)368 IOException (java.io.IOException)54 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)38 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)34 SSOException (com.iplanet.sso.SSOException)32 AMException (com.iplanet.am.sdk.AMException)31 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)29 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)29 AMEventManagerException (com.iplanet.am.sdk.AMEventManagerException)29 LocateRegistry (java.rmi.registry.LocateRegistry)29 Registry (java.rmi.registry.Registry)29 UnsupportedEncodingException (java.io.UnsupportedEncodingException)27 EJBException (javax.ejb.EJBException)25 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)24 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)24 ArrayList (java.util.ArrayList)22 InvocationTargetException (java.lang.reflect.InvocationTargetException)21 ConnectException (java.net.ConnectException)20 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)18 ExecutionException (com.cloud.utils.exception.ExecutionException)18