Search in sources :

Example 6 with RemoteAccessException

use of org.springframework.remoting.RemoteAccessException in project spring-framework by spring-projects.

the class HttpInvokerClientInterceptor method invoke.

@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
    if (AopUtils.isToStringMethod(methodInvocation.getMethod())) {
        return "HTTP invoker proxy for service URL [" + getServiceUrl() + "]";
    }
    RemoteInvocation invocation = createRemoteInvocation(methodInvocation);
    RemoteInvocationResult result;
    try {
        result = executeRequest(invocation, methodInvocation);
    } catch (Throwable ex) {
        RemoteAccessException rae = convertHttpInvokerAccessException(ex);
        throw (rae != null ? rae : ex);
    }
    try {
        return recreateRemoteInvocationResult(result);
    } catch (Throwable ex) {
        if (result.hasInvocationTargetException()) {
            throw ex;
        } else {
            throw new RemoteInvocationFailureException("Invocation of method [" + methodInvocation.getMethod() + "] failed in HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
        }
    }
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) RemoteInvocationResult(org.springframework.remoting.support.RemoteInvocationResult) RemoteAccessException(org.springframework.remoting.RemoteAccessException) RemoteInvocationFailureException(org.springframework.remoting.RemoteInvocationFailureException)

Example 7 with RemoteAccessException

use of org.springframework.remoting.RemoteAccessException in project spring-framework by spring-projects.

the class SimpleRemoteStatelessSessionProxyFactoryBeanTests method testCreateExceptionWithLocalBusinessInterface.

@Test
public void testCreateExceptionWithLocalBusinessInterface() 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(MyLocalBusinessMethods.class);
    assertEquals(fb.getBusinessInterface(), MyLocalBusinessMethods.class);
    fb.setJndiTemplate(jt);
    // Need lifecycle methods
    fb.afterPropertiesSet();
    MyLocalBusinessMethods mbm = (MyLocalBusinessMethods) fb.getObject();
    assertTrue(Proxy.isProxyClass(mbm.getClass()));
    try {
        mbm.getValue();
        fail("Should have failed to create EJB");
    } catch (RemoteAccessException ex) {
        assertTrue(ex.getCause() == cex);
    }
}
Also used : JndiTemplate(org.springframework.jndi.JndiTemplate) RemoteAccessException(org.springframework.remoting.RemoteAccessException) CreateException(javax.ejb.CreateException) Test(org.junit.Test)

Example 8 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 9 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