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