Search in sources :

Example 16 with RemoteException

use of java.rmi.RemoteException in project spring-framework by spring-projects.

the class JndiRmiClientInterceptor method invoke.

/**
	 * Fetches an RMI stub and delegates to {@link #doInvoke}.
	 * If configured to refresh on connect failure, it will call
	 * {@link #refreshAndRetry} on corresponding RMI exceptions.
	 * @see #getStub
	 * @see #doInvoke
	 * @see #refreshAndRetry
	 * @see java.rmi.ConnectException
	 * @see java.rmi.ConnectIOException
	 * @see java.rmi.NoSuchObjectException
	 */
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    Object stub;
    try {
        stub = getStub();
    } catch (NamingException ex) {
        throw new RemoteLookupFailureException("JNDI lookup for RMI service [" + getJndiName() + "] failed", ex);
    }
    Context ctx = (this.exposeAccessContext ? getJndiTemplate().getContext() : null);
    try {
        return doInvoke(invocation, stub);
    } catch (RemoteConnectFailureException ex) {
        return handleRemoteConnectFailure(invocation, ex);
    } catch (RemoteException ex) {
        if (isConnectFailure(ex)) {
            return handleRemoteConnectFailure(invocation, ex);
        } else {
            throw ex;
        }
    } finally {
        getJndiTemplate().releaseContext(ctx);
    }
}
Also used : Context(javax.naming.Context) RemoteConnectFailureException(org.springframework.remoting.RemoteConnectFailureException) NamingException(javax.naming.NamingException) RemoteLookupFailureException(org.springframework.remoting.RemoteLookupFailureException) RemoteException(java.rmi.RemoteException)

Example 17 with RemoteException

use of java.rmi.RemoteException in project spring-framework by spring-projects.

the class SimpleRemoteStatelessSessionProxyFactoryBeanTests method testCreateException.

@Test
public void testCreateException() throws Exception {
    final String jndiName = "foo";
    final CreateException cex = new CreateException();
    final MyHome home = mock(MyHome.class);
    given(home.create()).willThrow(cex);
    JndiTemplate jt = new JndiTemplate() {

        @Override
        public Object lookup(String name) {
            // parameterize
            assertTrue(name.equals(jndiName));
            return home;
        }
    };
    SimpleRemoteStatelessSessionProxyFactoryBean fb = new SimpleRemoteStatelessSessionProxyFactoryBean();
    fb.setJndiName(jndiName);
    // rely on default setting of resourceRef=false, no auto addition of java:/comp/env prefix
    fb.setBusinessInterface(MyBusinessMethods.class);
    assertEquals(fb.getBusinessInterface(), MyBusinessMethods.class);
    fb.setJndiTemplate(jt);
    // Need lifecycle methods
    fb.afterPropertiesSet();
    MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
    assertTrue(Proxy.isProxyClass(mbm.getClass()));
    try {
        mbm.getValue();
        fail("Should have failed to create EJB");
    } catch (RemoteException ex) {
    // expected
    }
}
Also used : JndiTemplate(org.springframework.jndi.JndiTemplate) RemoteException(java.rmi.RemoteException) CreateException(javax.ejb.CreateException) Test(org.junit.Test)

Example 18 with RemoteException

use of java.rmi.RemoteException in project spring-framework by spring-projects.

the class SimpleRemoteStatelessSessionProxyFactoryBeanTests method testRemoteException.

@Override
@Test
public void testRemoteException() throws Exception {
    final RemoteException rex = new RemoteException();
    final String jndiName = "foo";
    MyEjb myEjb = mock(MyEjb.class);
    given(myEjb.getValue()).willThrow(rex);
    // TODO might want to control this behaviour...
    // Do we really want to call remove after a remote exception?
    final MyHome home = mock(MyHome.class);
    given(home.create()).willReturn(myEjb);
    JndiTemplate jt = new JndiTemplate() {

        @Override
        public Object lookup(String name) {
            // parameterize
            assertTrue(name.equals("java:comp/env/" + jndiName));
            return home;
        }
    };
    SimpleRemoteStatelessSessionProxyFactoryBean fb = new SimpleRemoteStatelessSessionProxyFactoryBean();
    fb.setJndiName(jndiName);
    fb.setResourceRef(true);
    fb.setBusinessInterface(MyBusinessMethods.class);
    fb.setJndiTemplate(jt);
    // Need lifecycle methods
    fb.afterPropertiesSet();
    MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
    assertTrue(Proxy.isProxyClass(mbm.getClass()));
    try {
        mbm.getValue();
        fail("Should've thrown remote exception");
    } catch (RemoteException ex) {
        assertSame("Threw expected RemoteException", rex, ex);
    }
    verify(myEjb).remove();
}
Also used : JndiTemplate(org.springframework.jndi.JndiTemplate) RemoteException(java.rmi.RemoteException) Test(org.junit.Test)

Example 19 with RemoteException

use of java.rmi.RemoteException in project spring-framework by spring-projects.

the class SimpleRemoteSlsbInvokerInterceptorTests method testInvokesMethodOnEjbInstanceWithBusinessInterfaceWithRemoteException.

@Test
public void testInvokesMethodOnEjbInstanceWithBusinessInterfaceWithRemoteException() throws Exception {
    final RemoteInterface ejb = mock(RemoteInterface.class);
    given(ejb.targetMethod()).willThrow(new RemoteException());
    final String jndiName = "foobar";
    Context mockContext = mockContext(jndiName, ejb);
    SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
    BusinessInterface target = (BusinessInterface) configuredProxy(si, BusinessInterface.class);
    try {
        target.targetMethod();
        fail("Should have thrown RemoteAccessException");
    } catch (RemoteAccessException ex) {
    // expected
    }
    verify(mockContext).close();
    verify(ejb).remove();
}
Also used : Context(javax.naming.Context) RemoteAccessException(org.springframework.remoting.RemoteAccessException) RemoteException(java.rmi.RemoteException) Test(org.junit.Test)

Example 20 with RemoteException

use of java.rmi.RemoteException in project otter by alibaba.

the class RmiCommunicationEndpoint method initial.

public void initial() {
    export = new RmiServiceExporter();
    export.setServiceName("endpoint");
    // 暴露自己
    export.setService(this);
    export.setServiceInterface(CommunicationEndpoint.class);
    export.setRegistryHost(host);
    export.setRegistryPort(port);
    // 强制创建一个
    export.setAlwaysCreateRegistry(alwaysCreateRegistry);
    try {
        export.afterPropertiesSet();
    } catch (RemoteException e) {
        throw new CommunicationException("Rmi_Create_Error", e);
    }
}
Also used : CommunicationException(com.alibaba.otter.shared.communication.core.exception.CommunicationException) RmiServiceExporter(org.springframework.remoting.rmi.RmiServiceExporter) RemoteException(java.rmi.RemoteException)

Aggregations

RemoteException (java.rmi.RemoteException)368 IOException (java.io.IOException)54 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)38 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)34 SSOException (com.iplanet.sso.SSOException)32 AMException (com.iplanet.am.sdk.AMException)31 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)29 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)29 AMEventManagerException (com.iplanet.am.sdk.AMEventManagerException)29 LocateRegistry (java.rmi.registry.LocateRegistry)29 Registry (java.rmi.registry.Registry)29 UnsupportedEncodingException (java.io.UnsupportedEncodingException)27 EJBException (javax.ejb.EJBException)25 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)24 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)24 ArrayList (java.util.ArrayList)22 InvocationTargetException (java.lang.reflect.InvocationTargetException)21 ConnectException (java.net.ConnectException)20 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)18 ExecutionException (com.cloud.utils.exception.ExecutionException)18