List of usage examples for org.springframework.remoting.httpinvoker SimpleHttpInvokerRequestExecutor SimpleHttpInvokerRequestExecutor
SimpleHttpInvokerRequestExecutor
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);/* w w w. ja va 2 s. c o m*/ // 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); }