Search in sources :

Example 1 with ConnectException

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

Example 2 with ConnectException

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();
}
Also used : Context(javax.naming.Context) ConnectException(java.rmi.ConnectException)

Example 3 with ConnectException

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

Example 4 with ConnectException

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;
}
Also used : Debugger(org.intellij.plugins.xsltDebugger.rt.engine.Debugger) NotBoundException(java.rmi.NotBoundException) RemoteDebuggerClient(org.intellij.plugins.xsltDebugger.rt.engine.remote.RemoteDebuggerClient) IOException(java.io.IOException) ConnectException(java.rmi.ConnectException) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ConnectException

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);
        }
    });
}
Also used : Observable(rx.Observable) SocketTimeoutException(java.net.SocketTimeoutException) Subscriber(rx.Subscriber) Func1(rx.functions.Func1) 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