use of org.springframework.remoting.RemoteAccessException 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 org.springframework.remoting.RemoteAccessException in project spring-framework by spring-projects.
the class HttpInvokerTests method httpInvokerWithSpecialLocalMethods.
@Test
public void httpInvokerWithSpecialLocalMethods() throws Exception {
String serviceUrl = "http://myurl";
HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean();
pfb.setServiceInterface(ITestBean.class);
pfb.setServiceUrl(serviceUrl);
pfb.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() {
@Override
public RemoteInvocationResult executeRequest(HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws IOException {
throw new IOException("argh");
}
});
pfb.afterPropertiesSet();
ITestBean proxy = (ITestBean) pfb.getObject();
// shouldn't go through to remote service
assertTrue(proxy.toString().indexOf("HTTP invoker") != -1);
assertTrue(proxy.toString().indexOf(serviceUrl) != -1);
assertEquals(proxy.hashCode(), proxy.hashCode());
assertTrue(proxy.equals(proxy));
// should go through
try {
proxy.setAge(50);
fail("Should have thrown RemoteAccessException");
} catch (RemoteAccessException ex) {
// expected
assertTrue(ex.getCause() instanceof IOException);
}
}
use of org.springframework.remoting.RemoteAccessException in project opennms by OpenNMS.
the class ServerUnreachableAdaptor method pollerCheckingIn.
/** {@inheritDoc} */
@Override
public MonitorStatus pollerCheckingIn(final String locationMonitorId, final Date currentConfigurationVersion) {
// if we check in and get a remote exception then we switch to the EmptyConfiguration
try {
final MonitorStatus result = m_remoteBackEnd.pollerCheckingIn(locationMonitorId, currentConfigurationVersion);
m_serverUnresponsive = false;
return result;
} catch (final RemoteAccessException e) {
// we have failed to check in properly with the server
m_serverUnresponsive = true;
LOG.warn("Server is unable to respond due to the following exception.", e);
return MonitorStatus.DISCONNECTED;
}
}
use of org.springframework.remoting.RemoteAccessException in project spring-framework by spring-projects.
the class HttpInvokerTests method httpInvokerProxyFactoryBeanAndServiceExporterWithIOException.
@Test
public void httpInvokerProxyFactoryBeanAndServiceExporterWithIOException() throws Exception {
TestBean target = new TestBean("myname", 99);
final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
exporter.setServiceInterface(ITestBean.class);
exporter.setService(target);
exporter.afterPropertiesSet();
HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean();
pfb.setServiceInterface(ITestBean.class);
pfb.setServiceUrl("http://myurl");
pfb.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() {
@Override
public RemoteInvocationResult executeRequest(HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws IOException {
throw new IOException("argh");
}
});
pfb.afterPropertiesSet();
ITestBean proxy = (ITestBean) pfb.getObject();
try {
proxy.setAge(50);
fail("Should have thrown RemoteAccessException");
} catch (RemoteAccessException ex) {
// expected
assertTrue(ex.getCause() instanceof IOException);
}
}
use of org.springframework.remoting.RemoteAccessException in project spring-framework by spring-projects.
the class JaxWsSupportTests method doTestJaxWsPortAccess.
private void doTestJaxWsPortAccess(WebServiceFeature... features) throws Exception {
GenericApplicationContext ac = new GenericApplicationContext();
GenericBeanDefinition serviceDef = new GenericBeanDefinition();
serviceDef.setBeanClass(OrderServiceImpl.class);
ac.registerBeanDefinition("service", serviceDef);
GenericBeanDefinition exporterDef = new GenericBeanDefinition();
exporterDef.setBeanClass(SimpleJaxWsServiceExporter.class);
exporterDef.getPropertyValues().add("baseAddress", "http://localhost:9999/");
ac.registerBeanDefinition("exporter", exporterDef);
GenericBeanDefinition clientDef = new GenericBeanDefinition();
clientDef.setBeanClass(JaxWsPortProxyFactoryBean.class);
clientDef.getPropertyValues().add("wsdlDocumentUrl", "http://localhost:9999/OrderService?wsdl");
clientDef.getPropertyValues().add("namespaceUri", "http://jaxws.remoting.springframework.org/");
clientDef.getPropertyValues().add("username", "juergen");
clientDef.getPropertyValues().add("password", "hoeller");
clientDef.getPropertyValues().add("serviceName", "OrderService");
clientDef.getPropertyValues().add("serviceInterface", OrderService.class);
clientDef.getPropertyValues().add("lookupServiceOnStartup", Boolean.FALSE);
if (features != null) {
clientDef.getPropertyValues().add("portFeatures", features);
}
ac.registerBeanDefinition("client", clientDef);
GenericBeanDefinition serviceFactoryDef = new GenericBeanDefinition();
serviceFactoryDef.setBeanClass(LocalJaxWsServiceFactoryBean.class);
serviceFactoryDef.getPropertyValues().add("wsdlDocumentUrl", "http://localhost:9999/OrderService?wsdl");
serviceFactoryDef.getPropertyValues().add("namespaceUri", "http://jaxws.remoting.springframework.org/");
serviceFactoryDef.getPropertyValues().add("serviceName", "OrderService");
ac.registerBeanDefinition("orderService", serviceFactoryDef);
ac.registerBeanDefinition("accessor", new RootBeanDefinition(ServiceAccessor.class));
AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
try {
ac.refresh();
OrderService orderService = ac.getBean("client", OrderService.class);
assertTrue(orderService instanceof BindingProvider);
((BindingProvider) orderService).getRequestContext();
String order = orderService.getOrder(1000);
assertEquals("order 1000", order);
try {
orderService.getOrder(0);
fail("Should have thrown OrderNotFoundException");
} catch (OrderNotFoundException ex) {
// expected
} catch (RemoteAccessException ex) {
// ignore - probably setup issue with JAX-WS provider vs JAXB
}
ServiceAccessor serviceAccessor = ac.getBean("accessor", ServiceAccessor.class);
order = serviceAccessor.orderService.getOrder(1000);
assertEquals("order 1000", order);
try {
serviceAccessor.orderService.getOrder(0);
fail("Should have thrown OrderNotFoundException");
} catch (OrderNotFoundException ex) {
// expected
} catch (WebServiceException ex) {
// ignore - probably setup issue with JAX-WS provider vs JAXB
}
} catch (BeanCreationException ex) {
if ("exporter".equals(ex.getBeanName()) && ex.getRootCause() instanceof ClassNotFoundException) {
// ignore - probably running on JDK without the JAX-WS impl present
} else {
throw ex;
}
} finally {
ac.close();
}
}
Aggregations