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);
}
}
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
}
}
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();
}
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();
}
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);
}
}
Aggregations