use of java.rmi.ConnectException in project spring-framework by spring-projects.
the class ThrowsAdviceInterceptorTests method testHandlerMethodThrowsException.
@Test
public void testHandlerMethodThrowsException() throws Throwable {
final Throwable t = new Throwable();
@SuppressWarnings("serial") MyThrowsHandler th = new MyThrowsHandler() {
@Override
public void afterThrowing(RemoteException ex) throws Throwable {
super.afterThrowing(ex);
throw t;
}
};
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
// Extends RemoteException
ConnectException ex = new ConnectException("");
MethodInvocation mi = mock(MethodInvocation.class);
given(mi.proceed()).willThrow(ex);
try {
ti.invoke(mi);
fail();
} catch (Throwable caught) {
assertEquals(t, caught);
}
assertEquals(1, th.getCalls());
assertEquals(1, th.getCalls("remoteException"));
}
use of java.rmi.ConnectException in project spring-framework by spring-projects.
the class SimpleRemoteSlsbInvokerInterceptorTests method doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh.
private void doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh(boolean lookupHomeOnStartup, boolean cacheHome) throws Exception {
final RemoteInterface ejb = mock(RemoteInterface.class);
given(ejb.targetMethod()).willThrow(new ConnectException(""));
int lookupCount = 2;
if (!cacheHome) {
lookupCount++;
if (lookupHomeOnStartup) {
lookupCount++;
}
}
final String jndiName = "foobar";
Context mockContext = mockContext(jndiName, ejb);
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
si.setRefreshHomeOnConnectFailure(true);
si.setLookupHomeOnStartup(lookupHomeOnStartup);
si.setCacheHome(cacheHome);
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
try {
target.targetMethod();
fail("Should have thrown RemoteException");
} catch (ConnectException ex) {
// expected
}
verify(mockContext, times(lookupCount)).close();
verify(ejb, times(2)).remove();
}
use of java.rmi.ConnectException in project jdk8u_jdk by JetBrains.
the class HandshakeTimeout method main.
public static void main(String[] args) throws Exception {
System.setProperty("sun.rmi.transport.tcp.handshakeTimeout", String.valueOf(TIMEOUT / 2));
/*
* Listen on port, but never process connections made to it.
*/
ServerSocket serverSocket = new ServerSocket(PORT);
/*
* Attempt RMI call to port in separate thread.
*/
Registry registry = LocateRegistry.getRegistry(PORT);
Connector connector = new Connector(registry);
Thread t = new Thread(connector);
t.setDaemon(true);
t.start();
/*
* Wait for call attempt to finished, and analyze result.
*/
t.join(TIMEOUT);
synchronized (connector) {
if (connector.success) {
throw new RuntimeException("TEST FAILED: remote call succeeded??");
}
if (connector.exception == null) {
throw new RuntimeException("TEST FAILED: remote call did not time out");
} else {
System.err.println("remote call failed with exception:");
connector.exception.printStackTrace();
System.err.println();
if (connector.exception instanceof MarshalException) {
System.err.println("TEST FAILED: MarshalException thrown, expecting " + "java.rmi.ConnectException or ConnectIOException");
} else if (connector.exception instanceof ConnectException || connector.exception instanceof ConnectIOException) {
System.err.println("TEST PASSED: java.rmi.ConnectException or " + "ConnectIOException thrown");
} else {
throw new RuntimeException("TEST FAILED: unexpected Exception thrown", connector.exception);
}
}
}
}
use of java.rmi.ConnectException in project intellij-community by JetBrains.
the class DebuggerConnector method connect.
@Nullable
private Debugger connect() {
Throwable lastException = null;
for (int i = 0; i < 10; i++) {
if (myProcess.isProcessTerminated())
return null;
try {
final Debugger realClient = EDTGuard.create(new RemoteDebuggerClient(myPort), myProcess);
myProcess.notifyTextAvailable("Connected to XSLT debugger on port " + myPort + "\n", ProcessOutputTypes.SYSTEM);
return realClient;
} catch (ConnectException e) {
lastException = e;
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
break;
}
} catch (NotBoundException e) {
lastException = e;
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
break;
}
} catch (IOException e) {
lastException = e;
break;
}
}
if (lastException != null) {
Logger.getInstance(getClass().getName()).info("Could not connect to debugger", lastException);
if (lastException.getMessage() != null) {
myProcess.notifyTextAvailable("Connection error: " + lastException.getMessage() + "\n", ProcessOutputTypes.SYSTEM);
}
}
return null;
}
use of java.rmi.ConnectException in project Gradle-demo by Arisono.
the class Rxjava1 method retryWhen.
private static void retryWhen() {
Observable.create(new Observable.OnSubscribe<Integer>() {
@Override
public void call(Subscriber<? super Integer> t) {
OkhttpUtils.println("执行任务");
t.onNext(12);
OkhttpUtils.println("遇到错误....");
// t.onError(new RuntimeException("系统错误"));
// t.onError(new ConnectException("服务器拒绝连接"));
t.onError(new SocketTimeoutException("服务器连接超时"));
}
}).retryWhen(new Func1<Observable<? extends Throwable>, Observable<?>>() {
@Override
public Observable<?> call(Observable<? extends Throwable> t) {
return t.flatMap(new Func1<Throwable, Observable<?>>() {
private int count = 0;
@Override
public Observable<?> call(Throwable t) {
if (t instanceof SocketTimeoutException) {
OkhttpUtils.println("错误类型:服务器请求超时!!!");
}
if (t instanceof ConnectException) {
OkhttpUtils.println("错误类型:服务器拒绝连接!!!");
}
if (t instanceof RuntimeException) {
OkhttpUtils.println("错误类型:错误类型:运行时发生异常!!!");
}
if (++count <= 5) {
OkhttpUtils.println("网络请求重新连接" + count);
return Observable.timer(3000, TimeUnit.MILLISECONDS);
}
return Observable.error(t);
}
});
}
}).observeOn(RxjavaUtils.getNamedScheduler("线程1")).subscribe(new Subscriber<Integer>() {
@Override
public void onCompleted() {
OkhttpUtils.println("onCompleted()");
}
@Override
public void onError(Throwable e) {
OkhttpUtils.println(e.getMessage());
}
@Override
public void onNext(Integer t) {
OkhttpUtils.println("" + t);
}
});
}
Aggregations