Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To make it simpler to use as an end user, we've created a JBI Client API which makes it easy to work with any JBI container and other JBI components.

The JavaDoc is probably self evident for many things, especially if you are aware of the JBI APIs. There is an example test case which shows many of these APIs in action.

Using the JBI interfaces

The following helper methods just provide some helper methods for easier use of the JBI APIs

Sending messages

This example uses a specific service to invoke

Code Block
InOnly exchange = client.createInOnlyExchange();

NormalizedMessage message = exchange.getInMessage();
message.setProperty("name", "James");
message.setContent(new StreamSource(new StringReader("<hello>world</hello>")));

// lets use a specific service to dispatch to
QName service = new QName("http://servicemix.org/cheese/", "receiver");
exchange.setService(service);
client.send(exchange);

In this example, we assume that the JBI container will have setup a default routing connection for our client, so we don't have to worry about specifying the endpoint.

Code Block
InOnly exchange = client.createInOnlyExchange();

NormalizedMessage message = exchange.getInMessage();
message.setProperty("name", "James");
message.setContent(new StreamSource(new StringReader("<hello>world</hello>")));

client.send(exchange);

Invoking services

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();

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.

Sending messages

This example uses a specific service to invoke

Code Block
Map properties = new HashMap();
properties.put("name", "James");

// lets use a specific service to route to
QName service = new QName("http://servicemix.org/cheese/", "receiver");
EndpointResolver resolver = client.createResolverForService(service);
client.send(resolver, null, properties, "<hello>world</hello>");

In this example, we assume that the JBI container will have setup a default routing connection for our client, so we don't have to worry about specifying the endpoint.

Code Block
Map properties = new HashMap();
properties.put("name", "James");

client.send(null, null, properties, "<hello>world</hello>");

Invoking services

Code Block
// optional endpoint resolution
EndpointResolver resolver = client.createResolverForService(service);

Map properties = new HashMap();
properties.put("name", "James");

Object response = client.request(resolver, null, properties, "<hello>world</hello>");

Configuring the ServiceMixClient

We use the Spring XML configuration files to configure the client. You can then use dependency injection to inject the client into your POJOs.

Here's an example of using a basic client...

Wiki Markup
{snippet:id=client|lang=xml|url=http://svn.apache.org/repos/asf/incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/client/example.xml}

Note that the jbi bean reference is the ServiceMix JBI container.

This example creates a client which is hard-wired to default to a specific service when an invocation is performed.

Wiki Markup
{snippet:id=clientroute|lang=xml|url=http://svn.apache.org/repos/asf/incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/client/example.xml}