Search in sources :

Example 21 with RemoteInvocation

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

the class SimpleHttpInvokerServiceExporter method handle.

/**
	 * Reads a remote invocation from the request, executes it,
	 * and writes the remote invocation result to the response.
	 * @see #readRemoteInvocation(com.sun.net.httpserver.HttpExchange)
	 * @see #invokeAndCreateResult(org.springframework.remoting.support.RemoteInvocation, Object)
	 * @see #writeRemoteInvocationResult(com.sun.net.httpserver.HttpExchange, org.springframework.remoting.support.RemoteInvocationResult)
	 */
@Override
public void handle(HttpExchange exchange) throws IOException {
    try {
        RemoteInvocation invocation = readRemoteInvocation(exchange);
        RemoteInvocationResult result = invokeAndCreateResult(invocation, getProxy());
        writeRemoteInvocationResult(exchange, result);
        exchange.close();
    } catch (ClassNotFoundException ex) {
        exchange.sendResponseHeaders(500, -1);
        logger.error("Class not found during deserialization", ex);
    }
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) RemoteInvocationResult(org.springframework.remoting.support.RemoteInvocationResult)

Example 22 with RemoteInvocation

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

the class JmsInvokerServiceExporter method onMessage.

@Override
public void onMessage(Message requestMessage, Session session) throws JMSException {
    RemoteInvocation invocation = readRemoteInvocation(requestMessage);
    if (invocation != null) {
        RemoteInvocationResult result = invokeAndCreateResult(invocation, this.proxy);
        writeRemoteInvocationResult(requestMessage, session, result);
    }
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) RemoteInvocationResult(org.springframework.remoting.support.RemoteInvocationResult)

Example 23 with RemoteInvocation

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

the class HttpInvokerTests method httpInvokerProxyFactoryBeanAndServiceExporterWithInvocationAttributes.

@Test
public void httpInvokerProxyFactoryBeanAndServiceExporterWithInvocationAttributes() throws Exception {
    TestBean target = new TestBean("myname", 99);
    final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
    exporter.setServiceInterface(ITestBean.class);
    exporter.setService(target);
    exporter.setRemoteInvocationExecutor(new DefaultRemoteInvocationExecutor() {

        @Override
        public Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
            assertNotNull(invocation.getAttributes());
            assertEquals(1, invocation.getAttributes().size());
            assertEquals("myValue", invocation.getAttributes().get("myKey"));
            assertEquals("myValue", invocation.getAttribute("myKey"));
            return super.invoke(invocation, targetObject);
        }
    });
    exporter.afterPropertiesSet();
    HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean();
    pfb.setServiceInterface(ITestBean.class);
    pfb.setServiceUrl("http://myurl");
    pfb.setRemoteInvocationFactory(new RemoteInvocationFactory() {

        @Override
        public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {
            RemoteInvocation invocation = new RemoteInvocation(methodInvocation);
            invocation.addAttribute("myKey", "myValue");
            try {
                invocation.addAttribute("myKey", "myValue");
                fail("Should have thrown IllegalStateException");
            } catch (IllegalStateException ex) {
            // expected: already defined
            }
            assertNotNull(invocation.getAttributes());
            assertEquals(1, invocation.getAttributes().size());
            assertEquals("myValue", invocation.getAttributes().get("myKey"));
            assertEquals("myValue", invocation.getAttribute("myKey"));
            return invocation;
        }
    });
    pfb.setHttpInvokerRequestExecutor(new AbstractHttpInvokerRequestExecutor() {

        @Override
        protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws Exception {
            assertEquals("http://myurl", config.getServiceUrl());
            MockHttpServletRequest request = new MockHttpServletRequest();
            MockHttpServletResponse response = new MockHttpServletResponse();
            request.setContent(baos.toByteArray());
            exporter.handleRequest(request, response);
            return readRemoteInvocationResult(new ByteArrayInputStream(response.getContentAsByteArray()), config.getCodebaseUrl());
        }
    });
    pfb.afterPropertiesSet();
    ITestBean proxy = (ITestBean) pfb.getObject();
    assertEquals("myname", proxy.getName());
    assertEquals(99, proxy.getAge());
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) DefaultRemoteInvocationExecutor(org.springframework.remoting.support.DefaultRemoteInvocationExecutor) RemoteInvocationResult(org.springframework.remoting.support.RemoteInvocationResult) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MethodInvocation(org.aopalliance.intercept.MethodInvocation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServletException(javax.servlet.ServletException) RemoteAccessException(org.springframework.remoting.RemoteAccessException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ITestBean(org.springframework.tests.sample.beans.ITestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) ByteArrayInputStream(java.io.ByteArrayInputStream) RemoteInvocationFactory(org.springframework.remoting.support.RemoteInvocationFactory) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 24 with RemoteInvocation

use of org.springframework.remoting.support.RemoteInvocation 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 25 with RemoteInvocation

use of org.springframework.remoting.support.RemoteInvocation in project opennms by OpenNMS.

the class ServiceRegistryHttpInvokerProxyFactoryBean method createRemoteInvocation.

@Override
public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {
    RemoteInvocation retval = super.createRemoteInvocation(methodInvocation);
    // Add the interface that is being used to access this service as an invocation attibute
    retval.addAttribute(ATTRIBUTE_INTERFACE_NAME, this.getServiceInterface().getName());
    return retval;
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation)

Aggregations

RemoteInvocation (org.springframework.remoting.support.RemoteInvocation)39 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)16 Test (org.junit.jupiter.api.Test)16 RemoteInvocationResult (org.springframework.remoting.support.RemoteInvocationResult)14 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)8 Test (org.junit.Test)8 RemoteAccessException (org.springframework.remoting.RemoteAccessException)7 IOException (java.io.IOException)6 MethodInvocation (org.aopalliance.intercept.MethodInvocation)6 ITestBean (org.springframework.tests.sample.beans.ITestBean)5 JobResult (com.thoughtworks.go.domain.JobResult)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 TestBean (org.springframework.tests.sample.beans.TestBean)4 NestedServletException (org.springframework.web.util.NestedServletException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Method (java.lang.reflect.Method)3 ServletException (javax.servlet.ServletException)3 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)3