use of java.rmi.ConnectException in project spring-framework by spring-projects.
the class ThrowsAdviceInterceptorTests method testCorrectHandlerUsedForSubclass.
@Test
public void testCorrectHandlerUsedForSubclass() throws Throwable {
MyThrowsHandler th = new MyThrowsHandler();
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 (Exception caught) {
assertEquals(ex, caught);
}
assertEquals(1, th.getCalls());
assertEquals(1, th.getCalls("remoteException"));
}
use of java.rmi.ConnectException in project jdk8u_jdk by JetBrains.
the class HandshakeFailure method main.
public static void main(String[] args) throws Exception {
/*
* Listen on port...
*/
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();
/*
* ...accept one connection from port and send non-JRMP data.
*/
Socket socket = serverSocket.accept();
socket.getOutputStream().write("Wrong way".getBytes());
socket.close();
/*
* Wait for call attempt to finish, 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);
}
}
}
}
Aggregations