Monday, March 17, 2008

Using an EJB3 Interceptor in Seam

For one of the demos for the NEJUG presentation we integrated the JPetStore (Spring based) and the DVDStore (Seam based) with JBossESB. The idea is that when orders are placed in either store the orders are processed in some ESB based Order Processing Service, using jBPM for the Orchestration. Here I want to show what you need to do to intercept a the order when the user hits the 'confirm' button in the Seam based DVD Store. For this we use an EJB3 interceptor. The beauty of this solution is that no code changes are needed in the DVD Store itself.

1. Modify the ejb-jar.xml
First we need to add some configuration to the ejb-jar.xml, as shown in Figure 1.

Figure 1. Add the interceptor to the ejb-jar.xml

So first we define the interceptor class by referencing
, next we need to specify when this class should be called, which is done by adding the second piece of xml which specifies the bean name for which the interceptor should fire. Here we want it to fire when the
is called.

2. Add the interceptor class

The interceptor class itself looks like

package com.jboss.dvd.seam;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

public class CheckoutInterceptor {

public Object sendOrderToESB(InvocationContext ctx) throws Exception {

System.out.println("*** Entering CheckoutInterceptor");
Object target = ctx.getTarget();
//Just making sure
if (target instanceof CheckoutAction) {
if (ctx.getMethod().getName().equals("submitOrder")) {
.println("We will send the following completedOrder object to ESB");
Order completedOrder = ((CheckoutAction) target).currentOrder;
Customer customer = ((CheckoutAction) target).customer;
System.out.println("Completed Order= " + completedOrder);
try {
return ctx.proceed();
} finally {
System.out.println("*** Exiting CheckoutInterceptor");

Figure 2. The CheckoutInterceptor Code

And that is all there is to it. In the interceptor we check which method is called, and if it is the
method we print out the order. In the demo we added code to serialize the order to XML, and then dropped in onto a gateway Queue, on its way to the ESB.

NEJUG on SOA - The SOA-P Store: Bed, Bath and Beyond (II)

I'm happy to say that the presentation went over well. We got some great questions and in general I think people really got it. Tom Cunningham compiled a list of the questions we got:

Is the registry different than UDDI?
Is there portability across ESB implementations (Mule / Service Mix / JBoss)?
Is there portability across different BPEL providers?
When you are talking about components for ESB, are you talking about adapters?
How gunshy should I be using JBoss ESB (are people using it in production)?
What strategies can I use for portability between ESB providers?
Is there any inherent security in the content based routing? Are there plans on adding something in this area (ACEGI/Spring Security in particular)?
What would you typically see in an actions block?
Would an example of an action be something execuing a rule?
When do you use a J2EE Servlet Filter approach and when would you use ESB?
How would you roll back a transaction?
How do you integrate with RESTful services?
How tightly couple is the rules engine with the ESB?
What monitoring tools exist to see what is going on inside the ESB?
Is there a way inside the ESB to log payload in and out of the ESB?
Is the ESB's state recoverable? Will it maintain state?
How do you track long transactions?
What's the connection between Rules and the ESB?
Will hot deploy consume all current requests before redeploying?
Is load balancing simple round robin?
Does JBPM compete with BPEL?
Is there interactive debugging so that you can step through the JPDL flow?
Are the enterprise design patterns (wiretap, splitter, aggregatore) available inside of a visual designer in JBDS?
Is the JBPM plugin going to be available for NetBeans?
Who is the jbpm-console intended for?
What's the difference between SOA and ESB?
How do you migrate to ESB?

The most humorous question had to be the last one, where someone wanted to know if content based routing could be used as a method of escaping hardware licenses.

Sorry, you had to be there for the answers, but maybe it can be a start for a JBossESB FAQ page.

Monday, March 10, 2008

WhichJar Utility

Where oh where is that class? Setting up your classpath in Java is half the battle. And finding in which jar the class you are looking for lives can be a tedious task. Measured in software years it was ions ago that my friend Toby introduced me to a little shell script he wrote called whichJar. I think I have been using it on a daily basis ever since. It may have changed a little over the years, but not too much, so here it goes:

# nasty script to find a string in the contents of a jar file.
# probably a better way to do this, but then again...

if [ "$1foo" = "foo" ] ; then
echo "$0 usage: `basename $0` string"
echo "where string is the string to look for in the jar's contents"
exit 1

for i in `find . -name \*.jar`
do className=`(jar tvf $i | grep $1)`;
if [ "$className" != "" ]; then
echo -e "$i\t$className";

To use it save the above code of to a file called 'whichJar' in your bin directory, and make it executable
chmod a+x whichJar

Then, for example to find the class 'javax.jms.Topic' in any of the jars in the current directory, or any of its subdirectories, simply type
whichJar javax.jms.Topic

Thank you Toby.

NEJUG on SOA - The SOA-P Store: Bed, Bath and Beyond

This Thursday (March 13th) Burr Sutter and I will speak at the NEJUG on SOA "The SOA-P Store: Bed, Bath and Beyond".

This will be a dynamic session focused on the demonstration of the customary capabilities and best practices associated with an Enterprise Service Bus for SOA-focused deployment.

We will get people involved and empowered with real boots-on-the-ground knowledge of how to do SOA and not just pontificate on abstract theory and marketing-speak. The live demonstrations will illustrate how typical Struts+Spring+Hibernate web applications can be liberated as services and enter the world of ESB & SOA.

See you there.

JBoss SOA Platform (SOA-P) Documentation

The SOA-P team incorporates a team of technical writers who take the project specific documentation and turn it into documentation for the SOA Platform, which is the supported 'RHEL' version of JBossESB (where JBossESB would be Fedora). In the true spirit of Open Source, this documentation is available for free, under the support/documentation tab of the Red Hat homepage, or you can go directly to the SOA-P 4.2 docs. I was quite impressed with what they did to some of the docs I wrote! Thanks guys.

Service Orchestration using jBPM

I recently wrote up am entry in the JBossESB blog. This code is now available in the SOA Platform as well as on the trunk of the JBossESB project. For the full documentation in pdf format see the jBPMIntegrationGuide.

Figure 1. Service Integration using jBPM.