| By Robert Davies, James Strachan | Article Rating: |
|
| August 10, 2005 10:00 AM EDT | Reads: |
49,761 |
This allows you to use a plugable Marshaler to map your POJOs to JAXP Sources.
Sending Messages
This example uses a specific service to make an invocation call:
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 the next example, we assume that the JBI container will have set up a default routing connection for our client, so there is no requirement to specify the endpoint.
Map properties = new HashMap();
properties.put("name", "James");
client.send(null, null, properties, "<hello>world</hello>");
Invoking Services with InOut
// 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>");
Example Using JMS and XSLT
Here's a quick example to show you some of the Service-Mix integration capabilities in action. We consume messages using JCA, then transform them with XSLT and send them
to a new destination using JMS.
Let's set up a JBI component to consume from JCA using JMS:
<component id="myJmsReceiver" service="foo:myJmsReceiver"
class="org.servicemix.components.jms.JmsInUsingJCABinding"
destinationService="foo:transformer">
<property name="jcaContainer" ref="activeJcaContainer"/>
<property name="activationSpec">
<bean class="org.activemq.ra.ActiveMQActivationSpec">
<property name="destination" value="test.org.servicemix.example.jca/>
<property name="destinationType" value ="javax.jms.Topic"/>
</bean>
</property>
</component>
Let's transform the message
<component id="transformer" service="foo:trans
former" class="org.servicemix.components.xslt.XsltComponent"
destinationService="foo:transformedSender">
<property name="xsltResource" value="classpath:org/servicemix/
components/xslt/transform.xsl"/>
</component>
Now let's send the message using the Spring JmsTemplate
<component id="myJmsSender" service="foo:myJmsSender" class="org.
servicemix.components.jms.JmsSenderComponent">
<property name="template">
<bean class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref local="jmsFactory"/>
</property>
<property name="defaultDestinationName" value="test.org.
servicemix.components.xslt.source"/>
<property name="pubSubDomain" value="true"/>
</bean>
</property>
</component>
Scripting Support
ServiceMix also supports scripting languages through JSR 223 - Scripting for Java. Here are some examples using Groovy:
Before we go into detail of how you can work with JBI and Groovy in ServiceMix, lets show a simple hello world kinda example.
<component id="myServiceUsingXMLText" service="foo:myServiceUsingXMLText"
endpoint="myServiceUsingXMLText"
class="org.servicemix.components.groovy.GroovyComponent">
<property name="scriptText">
<value>
<![CDATA[
// lets output some message properties
outMessage.properties = [foo:"hello", someList:[1, 2, 3]]
// lets output some non-xml body
outMessage.bodyText = """
<hello>
<world person="$inMessage.properties.name" location="London"/>
</hello>
"""
]]>
</value>
</property>
</component>
As you can see the component is configured with a piece of Groovy to execute when the service is invoked.
Now we'll go through the various options which are available when working with JBI and Groovy in ServiceMix.
Maintaining State Across Requests
It's often handy to keep track of state across requests. There is a variable called 'bindings' which you can use to maintain state; here's the groovy...
if (bindings.counter == null) {
bindings.counter = 1
}
else {
++bindings.counter
}
def date = new Date()
outMessage.bodyText = "<response counter='$bindings.counter'
date='$date'></response>"
Published August 10, 2005 Reads 49,761
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Robert Davies
Rob Davies, director of open source development at IONA, has more than 20 years of experience developing high-performance distributed enterprise systems and products for telecom and finance corporations. He is responsible for leading the development of IONA's FUSE family of open source products, which are based on leading projects at the Apache Software Foundation. Rob is a founder of the Apache ActiveMQ, Apache ServiceMix and Apache Camel projects. Prior to joining IONA, Rob served as the founder and vice president of product development at LogicBlaze, which was acquired by IONA in 2007. Previously, Rob served as founder and CTO of integration software developer SpiritSoft.
More Stories By James Strachan
James Strachan, technical director at IONA, is responsible for helping the Company provide open source offerings for organizations requiring secure, high-performance distributed systems and integration solutions. He is heavily involved in the open source community, and has co-founded several Apache projects, including ActiveMQ, Camel, Geronimo and ServiceMix. He also created the "Groovy" scripting language and additional open source projects such as dom4j, jaxen and Jelly. Prior to joining IONA, James spent more than 20 years in enterprise software development. Previously, James co-founded LogicBlaze, Inc., an enterprise open source company acquired by IONA. Prior to that, he founded SpiritSoft, Inc., a company providing enterprise Java middleware services.
- The Top 150 Players in Cloud Computing
- Commercial vs Federal Cloud Computing
- Why IBM’s Server Chief Got Busted
- Industry Experts Discuss the State of Cloud Computing
- Cloud Expo New York Call for Papers Now Open
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- US Federal Government is Major Cloud Computing Innovator
- Google Wave
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Adaptivity & Cloud Computing: Exclusive Q&A with CEO Tony Bishop
- 4th International Cloud Expo: Photo Album
- The Top 150 Players in Cloud Computing
- SYS-CON.TV: Cloud Computing Expo Power Panel
- Commercial vs Federal Cloud Computing
- Why IBM’s Server Chief Got Busted
- 1st Annual GovIT Expo: Letter from the Technical Chair
- Industry Experts Discuss the State of Cloud Computing
- Deputy CIO of the CIA to Keynote 1st Annual GovIT Expo
- SOA World Power Panel on SYS-CON.TV
- CIA was Headed to an Enterprise Cloud All Along: Jill Tummler Singer
- Cloud Expo New York Call for Papers Now Open
- 1st Annual Government IT Conference & Expo: Themes & Topics
- Stock in Focus: Dragon Capital
- The i-Technology Right Stuff
- Who Are The All-Time Heroes of i-Technology?
- Get the Message
- Where Are RIA Technologies Headed in 2008?
- i-Technology Viewpoint: Is Web 2.0 the Global SOA?
- i-Technology Viewpoint: Thinking Outside the VC Box
- ESB Myth Busters: 10 Enterprise Service Bus Myths Debunked
- i-Technology Viewpoint: When to Leave Your First IT Job
- SOA Web Services Edge Conference Coverage on SYS-CON.TV
- Five Reasons Why Web 2.0 Matters
- SYS-CON.TV's "SOA Web Services" and "Enterprise Open Source" Programs To Air in December
- SOA World Conference & Expo SYS-CON.TV Power Panel Live From Times Square









Cloud computing is a game changer. The cloud ...























