Example usage for org.springframework.remoting.support DefaultRemoteInvocationExecutor DefaultRemoteInvocationExecutor

List of usage examples for org.springframework.remoting.support DefaultRemoteInvocationExecutor DefaultRemoteInvocationExecutor

Introduction

In this page you can find the example usage for org.springframework.remoting.support DefaultRemoteInvocationExecutor DefaultRemoteInvocationExecutor.

Prototype

DefaultRemoteInvocationExecutor

Source Link

Usage

From source file:org.apache.servicemix.http.endpoints.SerializedMarshalerTest.java

public void testUsingSpringHttpRemoting() throws Exception {
    final Person person = new PersonImpl("Hunter", "Thompson", 67);

    // Create a consumer endpoint
    HttpConsumerEndpoint ep = new HttpConsumerEndpoint();
    ep.setService(new QName("urn:HttpConsumer", "HttpConsumer"));
    ep.setEndpoint("HttpConsumer");
    ep.setLocationURI("http://localhost:8192/service/");
    ep.setTargetService(new QName("urn:HttpInvoker", "Endpoint"));

    // Configure the SerializedMarshaler and specifiy it on the endpoint
    SerializedMarshaler marshaler = new SerializedMarshaler();
    marshaler.setDefaultMep(MessageExchangeSupport.IN_OUT);
    ep.setMarshaler(marshaler);/*from  w  w  w.j  av a  2s .c  om*/

    // Add the endpoint to the component and activate it
    HttpComponent component = new HttpComponent();
    component.setEndpoints(new HttpEndpointType[] { ep });
    container.activateComponent(component, "HttpConsumer");

    // Dummy up a component as a receiver and route it to urn:HttpInvoker/Endpoint
    TransformComponentSupport rmiComponent = new TransformComponentSupport() {
        protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out)
                throws MessagingException {
            try {
                // Deserialize rmi invocation
                XStream xstream = new XStream(new DomDriver());
                SourceTransformer st = new SourceTransformer();
                Object rmi = xstream.fromXML(st.toString(in.getContent()));

                DefaultRemoteInvocationExecutor executor = new DefaultRemoteInvocationExecutor();
                Object result = executor.invoke((RemoteInvocation) rmi, person);

                // Convert result to an rmi invocation
                RemoteInvocationResult rmiResult = new RemoteInvocationResult(result);
                out.setContent(new StringSource(xstream.toXML(rmiResult)));
            } catch (Exception e) {
                throw new MessagingException(e);
            }

            return true;
        }
    };
    ActivationSpec asReceiver = new ActivationSpec("rmiComponent", rmiComponent);
    asReceiver.setService(new QName("urn:HttpInvoker", "Endpoint"));
    container.activateComponent(asReceiver);

    // Start the JBI container
    container.start();

    // Set up the Spring bean to call into the URL specified for the consumer endpoint
    HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean();
    pfb.setServiceInterface(Person.class);
    pfb.setServiceUrl("http://localhost:8192/service/");
    pfb.setHttpInvokerRequestExecutor(new SimpleHttpInvokerRequestExecutor());
    pfb.afterPropertiesSet();

    // Grab the object via the proxy factory bean
    Person test = (Person) pfb.getObject();

    // Test getters
    assertEquals("Hunter", test.getGivenName());
    assertEquals("Thompson", test.getSurName());
    assertEquals(67, test.getAge());

    // Test setters
    test.setGivenName("John");
    test.setSurName("Doe");
    test.setAge(34);

    assertEquals(person.getGivenName(), "John");
    assertEquals(person.getSurName(), "Doe");
    assertEquals(person.getAge(), 34);
}

From source file:org.logicblaze.lingo.jms.JmsRemotingTest.java

public void testJmsProxyFactoryBeanAndServiceExporterWithInvocationAttributes() throws Exception {
    TestBean target = new TestBean("myname", 99);
    final JmsServiceExporter exporter = new JmsServiceExporter();
    exporter.setServiceInterface(ITestBean.class);
    exporter.setService(target);/*from w  w w.  j av  a 2  s . co m*/
    exporter.setRemoteInvocationExecutor(new DefaultRemoteInvocationExecutor() {
        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);
        }
    });
    configure(exporter);
    subscribeToQueue(exporter, getDestinationName());

    JmsProxyFactoryBean pfb = new JmsProxyFactoryBean();
    pfb.setServiceInterface(ITestBean.class);
    pfb.setServiceUrl("http://myurl");
    pfb.setRequestor(createRequestor(getDestinationName()));
    pfb.setRemoteInvocationFactory(new LingoRemoteInvocationFactory(strategy) {
        public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {
            RemoteInvocation invocation = super.createRemoteInvocation(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;
        }
    });
    configure(pfb);

    ITestBean proxy = (ITestBean) pfb.getObject();
    assertEquals("myname", proxy.getName());
    assertEquals(99, proxy.getAge());
}

From source file:org.logicblaze.lingo.jms.JmsRemotingTest.java

public void testJmsProxyFactoryBeanAndServiceExporterWithCustomInvocationObject() throws Exception {
    TestBean target = new TestBean("myname", 99);
    final JmsServiceExporter exporter = new JmsServiceExporter();
    exporter.setServiceInterface(ITestBean.class);
    exporter.setService(target);/*  ww  w  .ja  va 2  s  . com*/
    exporter.setRemoteInvocationExecutor(new DefaultRemoteInvocationExecutor() {
        public Object invoke(RemoteInvocation invocation, Object targetObject)
                throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
            assertNull(invocation.getAttributes());
            assertNull(invocation.getAttribute("myKey"));
            return super.invoke(invocation, targetObject);
        }
    });
    configure(exporter);
    subscribeToQueue(exporter, getDestinationName());

    JmsProxyFactoryBean pfb = new JmsProxyFactoryBean();
    pfb.setServiceInterface(ITestBean.class);
    pfb.setServiceUrl("http://myurl");
    pfb.setRequestor(createRequestor(getDestinationName()));
    pfb.setRemoteInvocationFactory(new LingoRemoteInvocationFactory(strategy) {
        public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {
            RemoteInvocation invocation = super.createRemoteInvocation(methodInvocation);
            assertNull(invocation.getAttributes());
            assertNull(invocation.getAttribute("myKey"));
            return invocation;
        }
    });
    configure(pfb);

    ITestBean proxy = (ITestBean) pfb.getObject();
    assertEquals("myname", proxy.getName());
    assertEquals(99, proxy.getAge());
}