Search in sources :

Example 1 with RemoteAccessException

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();
}
Also used : Context(javax.naming.Context) RemoteAccessException(org.springframework.remoting.RemoteAccessException) RemoteException(java.rmi.RemoteException) Test(org.junit.Test)

Example 2 with RemoteAccessException

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);
    }
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) ITestBean(org.springframework.tests.sample.beans.ITestBean) RemoteInvocationResult(org.springframework.remoting.support.RemoteInvocationResult) RemoteAccessException(org.springframework.remoting.RemoteAccessException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with RemoteAccessException

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;
    }
}
Also used : RemoteAccessException(org.springframework.remoting.RemoteAccessException) MonitorStatus(org.opennms.netmgt.model.OnmsLocationMonitor.MonitorStatus)

Example 4 with RemoteAccessException

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);
    }
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) ITestBean(org.springframework.tests.sample.beans.ITestBean) RemoteInvocationResult(org.springframework.remoting.support.RemoteInvocationResult) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) RemoteAccessException(org.springframework.remoting.RemoteAccessException) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with RemoteAccessException

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();
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) BeanCreationException(org.springframework.beans.factory.BeanCreationException) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) WebServiceException(javax.xml.ws.WebServiceException) RemoteAccessException(org.springframework.remoting.RemoteAccessException) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BindingProvider(javax.xml.ws.BindingProvider)

Aggregations

RemoteAccessException (org.springframework.remoting.RemoteAccessException)9 Test (org.junit.Test)4 RemoteInvocation (org.springframework.remoting.support.RemoteInvocation)3 RemoteInvocationResult (org.springframework.remoting.support.RemoteInvocationResult)3 IOException (java.io.IOException)2 PollerConfiguration (org.opennms.netmgt.poller.remote.PollerConfiguration)2 ITestBean (org.springframework.tests.sample.beans.ITestBean)2 RemoteException (java.rmi.RemoteException)1 CreateException (javax.ejb.CreateException)1 Context (javax.naming.Context)1 BindingProvider (javax.xml.ws.BindingProvider)1 WebServiceException (javax.xml.ws.WebServiceException)1 MonitorStatus (org.opennms.netmgt.model.OnmsLocationMonitor.MonitorStatus)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 JndiTemplate (org.springframework.jndi.JndiTemplate)1 RemoteInvocationFailureException (org.springframework.remoting.RemoteInvocationFailureException)1 TestBean (org.springframework.tests.sample.beans.TestBean)1