...
Code Block |
---|
InOut exchange = client.createInOutExchange(); NormalizedMessage inMessage = exchange.getInMessage(); inMessage.setProperty("name", "James"); inMessage.setContent(new StreamSource(new StringReader("<hello>world</hello>"))); // optionally specify the endpoint exchange.setService(service); client.sendSync(exchange); NormalizedMessage outMessage = exchange.getOutMessage(); |
Working with URIs and Destinations
ServiceMix has integrated support for URIs to simplify the accessing of endpoints within the NMR. The ServiceMixClient (from 3.0-M3 or later) allows you to work with URIs easily via a Destination interface. This interface acts as a factory of MessageExchange objects which are pre-wired to specific endpoints specified via a URI.
The following shows how to work with InOnly for one way messaging
Wiki Markup |
---|
{snippet:id=inOnly|lang=java|url=http://svn.apache.org/repos/asf/incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ClientDestinationTest.java} |
Or using InPOut for request-response
Wiki Markup |
---|
{snippet:id=inOut|lang=java|url=http://svn.apache.org/repos/asf/incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ClientDestinationTest.java} |
Simpler one-way messaging with Destinations
For one-way messaging its sometimes simpler to just work with a Message instance (you can always refer to the MessageExchange via the getExchange() method if need be). For example
Wiki Markup |
---|
{snippet:id=message|lang=java|url=http://svn.apache.org/repos/asf/incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ClientDestinationTest.java} |
Using the POJO methods
We provide a few helper POJO based methods to allow you to use JBI using regular POJOs to hide some of the XML marshaling detail. Then you can use a plugable Marshaler to map your POJOs to JAXP Sources.
...