Search in sources :

Example 6 with ConnectException

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"));
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ConnectException(java.rmi.ConnectException) RemoteException(java.rmi.RemoteException) ConnectException(java.rmi.ConnectException) Test(org.junit.Test)

Example 7 with ConnectException

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);
            }
        }
    }
}
Also used : MarshalException(java.rmi.MarshalException) ConnectIOException(java.rmi.ConnectIOException) ServerSocket(java.net.ServerSocket) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ConnectException(java.rmi.ConnectException)

Aggregations

ConnectException (java.rmi.ConnectException)7 IOException (java.io.IOException)2 ServerSocket (java.net.ServerSocket)2 ConnectIOException (java.rmi.ConnectIOException)2 MarshalException (java.rmi.MarshalException)2 RemoteException (java.rmi.RemoteException)2 LocateRegistry (java.rmi.registry.LocateRegistry)2 Registry (java.rmi.registry.Registry)2 MethodInvocation (org.aopalliance.intercept.MethodInvocation)2 Test (org.junit.Test)2 FileNotFoundException (java.io.FileNotFoundException)1 Socket (java.net.Socket)1 SocketTimeoutException (java.net.SocketTimeoutException)1 NotBoundException (java.rmi.NotBoundException)1 Context (javax.naming.Context)1 Debugger (org.intellij.plugins.xsltDebugger.rt.engine.Debugger)1 RemoteDebuggerClient (org.intellij.plugins.xsltDebugger.rt.engine.remote.RemoteDebuggerClient)1 Nullable (org.jetbrains.annotations.Nullable)1 Observable (rx.Observable)1 Subscriber (rx.Subscriber)1