OpenESB and ServiceMix aren't the only two JBI based ESBs. From ObjectWeb we've also got Petals, and they've recently released Petals 2.0.
About a month ago I tried getting Petals' components to work with ServiceMix, but ran into some strange problems where it was missing some property in it's configuration. I didn't look into that at that time, and moved on to playing around some more with openESB.
So now with a new version of Petals out I decided to try it's components again. I downloaded the latest release, dropped the pojo service engine inside the deploy directory and everything seemed to be working. So I made a simple SU deployed it, and ran into a problem where it couldn't find the method to send the message exchange to. I couldn't find the sources of the service engine, so I got the latest SVN versions and tried from there.
Although there are some bugs in the latest version from SVN, they changed some package and namespaces, after some trivial fixes everything was working nicely.
To get the POJO service engine working in ServiceMix from the petals SVN you roughly have to follow the following steps:
1. Fix the JBI descriptor for the pojo-se component
Change the bootstrap class name from:
org.objectweb.petals.component.framework.DefaultBootstrap
to:
org.ow2.petals.component.framework.DefaultBootstrap
And also change the petal namespace definition to:
xmlns:petals="http://petals.ow2.org/extensions"
2. Deploy the JBI component
Just drop this altered pojo-se component in the servicemix deploy directory and you'll see some log messages coming by showing you that the component is successfully installed.
3. Create the pojo to deploy to this component
I think there is a bug here, the component now forces you to use the org.ow2.petals.component.framework.util.Exchange in your pojo instead of a normal jbi messageexchange. In previous versions the onMessageExchange message needed to accept the interface class, not the petals specific implementation. But that's what you get for using code fresh from SVN.
package opensource.esb.servicemix.chapter6.petals;
import javax.jbi.component.ComponentContext;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.MessageExchange;
import org.ow2.petals.component.framework.util.Exchange;
public class PetalsPojo {
private DeliveryChannel channel;
private ComponentContext ctx;
public void setChannel(DeliveryChannel channel) {
System.out.println("Channel set:" + channel);
this.channel = channel;
}
public void setCtx(ComponentContext ctx) {
System.out.println("ComponentContext set:" + ctx);
this.ctx = ctx;
}
public boolean onExchange(Exchange exchange) throws Exception {
System.out.println("MessageExchange received:" + exchange);
return false;
}
public void init() {
System.out.println("Initializing: " + this);
}
public void start() {
System.out.println("Starting:" + this );
}
public void stop() {
System.out.println("Stopping:" + this);
}
}
4. Create a configuration file
This part isn't that well documented on the site, perhaps again because they seem to are in the process of switching namespaces, packaging and the manner of configuration. However looking through the code, and the schemas, I came to the following jbi.xml which works.
<jbi version="1.0" xmlns='http://java.sun.com/xml/ns/jbi'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:petals="http://petals.ow2.org/extensions">
<services binding-component="false">
<provides interface-name= "petals:SamplePojoInterface"
service-name = "petals:SamplePojoService"
endpoint-name = "SamplePojoEndpoint">
<petals:wsdl/>
<petals:su-interceptors/>
<petals:params>
<petals:param name="class-name">opensource.esb.servicemix.chapter6.petals.PetalsPojo</petals:param>
</petals:params>
</provides>
</services>
</jbi>
This registers an endpoint and service. Once an exchange is received on this component, the onMessageExchange method of the previous mentioned pojo is invoked.
5. pack everything up and deploy
The last step is to archive and deploy everything. Create the following SU:
-META-INF/jbi.xml (the previous example)
-classes.jar (the jar file which contains the pojo and related classes)
Now create a Service Assembly that can deploy this to the petals-pojo component and you're done.
I think this is one of the big advantages of JBI; interoperability of the components. When I started with JBI I didn't really have much hope that components where truly interchangeable between JBI containers. But, even though there are some small issues, getting a component from one implementation to work on the other is very easy.
The main difference is the way you need to configure the components. ServiceMix choose an XBean approach, openESB a WSDL approach and petals extends the jbi.xml file. Personally I like the ServiceMix and Petals approach the most. They make it very easy to configure components without having to depend on an editor/support like openESB.