Small steps with big feet
Tutorial: call an EJB in a BPMN 2.0 process using Activiti and Spring
Since its conception, Activiti has always had a great integration with Spring. In this tutorial, I’m going to demonstrate how this integration can be leveraged to call an EJB (the approach works for EJB versions 2 or 3) in a BPMN 2.0 process. Whether you like them or not: the fact is that much business logic has been/is being written in EJB’s, but luckily Activiti makes calling an EJB plain, simple and fun.
The environment for this tutorial is as follows:
- Activiti 5.1
- Spring 3.something
- JBoss 5.1.0
The EJB I’ll use for this tutorial is probably the dullest piece of ‘logic’ you’ve ever seen: it does nothing more than transform the given String parameter to uppercase and return it.
@Stateless
public class ToUpperCaseBean implements ToUpperCaseRemote {
public String toUpperCase(String s) {
return s.toUpperCase();
}
}
This EJB session bean is running on the JBoss server (or any other JEE container).
I’m using the default Activiti-Spring integration, so I’m not going to describe the whole spring config here. Suffice to say I have my ProcessEngine configured as a Spring bean:
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"> <property name="databaseType" value="h2" /> <property name="dataSource" ref="dataSource" /> <property name="transactionManager" ref="transactionManager" /> <property name="databaseSchemaUpdate" value="true" /> <property name="jobExecutorActivate" value="false" /> </bean> <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean"> <property name="processEngineConfiguration" ref="processEngineConfiguration" /> </bean> ...
I’m going to run the BPMN 2.0 example process in standard Java environment, so I need to access the EJB through its remote interface. I’m actually going to let Spring do all the hard work, by defining a Spring bean that’ll wrap all the dirty JNDI stuff for me:
<jee:remote-slsb id="toUpperCaseEjbBean" resource-ref="false" business-interface="be.jorambarrez.ejb.ToUpperCaseRemote" jndi-name="ToUpperCaseBean/remote" />
The BPMN 2.0 process in which I’ll call the EJB is again as simple as possible, to make my point. I’m sure you can imagine more awesome scenario’s for it. Here, the process has a start, a call to the EJB, the output of the call (ie the uppercased String) and that’s it.
In BPMN 2.0 XML, this boils down to the following:
<process id="callEjbExample" name="Call EJB example">
<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="callEjb" />
<serviceTask id="callEjb"
activiti:expression="${toUpperCaseEjbBean.toUpperCase(var)}"
activiti:resultVariableName="var" />
<sequenceFlow id="flow2" sourceRef="callEjb" targetRef="outputResult" />
<scriptTask id="outputResult" scriptFormat="groovy">
<script>
out:println "uppercased version = " + var
</script>
</scriptTask>
<sequenceFlow id="flow3" sourceRef="outputResult" targetRef="theEnd" />
<endEvent id="theEnd" />
</process>
For this tutorial, the serviceTask definition is the most interesting:
<serviceTask id="callEjb"
activiti:expression="${toUpperCaseEjbBean.toUpperCase(var)}"
activiti:resultVariableName="var" />
When process execution arrives at the serviceTask, it will execute the toUpperCaseEjbBean.toUpperCase(var) expression. The toUpperCaseEjbBean is actually our wrapped EJB as a Spring bean (see the Spring config above), on which we here invoke the toUpperCase method. This Activiti-Spring-expression integration is pretty cool, right? On the last line, you can see the result of executing the expression is stored in the var variable.
All that is left to do is execute this process on the Activiti engine:
// setup the Spring container and get the Activiti ProcessEngine bean from it
ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");
ProcessEngine processEngine = context.getBean(ProcessEngine.class);
// Deploy process
processEngine.getRepositoryService().createDeployment()
.addClasspathResource("callEjbExampleProcess.bpmn20.xml")
.deploy();
// Run process
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("var", "Activiti, the rock-solid BPM engine");
processEngine.getRuntimeService().startProcessInstanceByKey("callEjbExample", variables);
Which spits out (of course) following console output:
![]()
And that’s all there is to it! If you want to try it for yourself, here are the sources, packaged as two Maven projects: one for the ejb and one for running the process.
Without Spring?
If you’ve taken a look at the sources, you’ll notice that getting the dependencies right isn’t trivial. Hell, 99% of my time went to figuring out which libraries I needed and why the hell asm was three times on my classpath with different versions.
In the next months, we’ll be adding a ‘native’ way of calling EJB’s in a BPMN 2.0 process, without having to go through Spring. That way, you’ll just need Activiti and we’ll take care of everything behind the scenes. However, the approach in this tutorial can be used for many other use cases: JMS, webservice calls, some legacy system, etc. Conclusion of this story: If you can wrap it in a Spring bean, you can use it in your BPMN 2.0 process.
Adhoc workflow with Activiti: introducing Activiti KickStart
(for those with a limited attention span: there is a screencast at the bottom!)
2010 was awesome. We had the launch and explosive growth of Activiti in ways that none of us were able to forecast when we started the Activiti-adventure. 2011 will continue to amaze, no single doubt about that. To kick of this 2011-amazement-rollercoaster-ride, I’m very proud to introduce the latest addition to the Activiti platform: Activiti KickStart.
What’s this all about?
KickStart grew out of the idea that each and every company has processes that are done in an adhoc way. These are processes that are ‘discovered’ on the fly: some people want to collaborate or a certain document needs to be handled in a specific order by different departements. A BPM platform such as Activiti is a well-suited solution to achieve this, but the threshold and cost to actually model, deploy and execute these kind of processes in the traditional sense is way too high.
Activiti KickStart gives you a simple and intuitive UI that allows you to create such processes in a matter of minutes. No need to model anything, no need to actually know or understand BPMN, no need to do any coding, … KickStart really and seriously lowers the threshold to automate your workflow processes.
The processes created with KickStart are directly deployable to the Activiti repository. They are also immediately usable in Activiti Explorer, and they are fully BPMN 2.0 compliant, which means they can be edited in any modeling tool that understands the BPMN 2.0 file format. And best of all, the workflows can be edited at any time, truly honoring the adhoc nature of these processes.
What can I do with it?
- Adhoc workflow: often, coordination is required between different people or groups in a company. You know how it normally goes: sending an email here, doing a telephone there … which often ends up in a mess of nobody knowing what or when something needs to be done. However, a business process management platform such as Activiti is an excellent way of distributing and follow-up everything, as it is intended to track exactly such things. KickStart allows you to create processes for adhoc work in a matter of minutes, and distribute and coordinate tasks between people easily.
- Prototyping/Proof-of-concept: before diving into complex BPMN 2.0 modeling and thinking about all complex aspects of , it is often wise to get all people involved aligned and work out a prototype that shows the vision of what needs to be done. KickStart allows to do exatcly that: create a business process prototype on the fly, to get your ideas visible for everyone.
- Simple processes: some processes are just simple by nature, and every company has them. Think about an expense process, a holiday leave process, a hiring process, etc… These kind of processes are probably already being done using paper or e-mail. KickStart allows to model these processes quickly and change them whenever it is needed. As such, KickStart really lowers the threshold to automate these business processes.
Obviously, you are not limited to these use cases. As history proves, people always tend to use and enhance these things in ways we can’t image today
.
When can I use it?
Activiti KickStart is available today! It is part of the freshly released 5.1 release, and installed by default if you run the Activiti demo setup. Just visit activiti.org and download the latest release, we’re open source after all
.
Note that KickStart is by no means ‘finished’ (which software product ever is). But in the Activiti and open source way of doing things, we want to show you as early as possible what we’re cooking. Using the feedback, ideas and contributions of you and the rest of the Activiti community, KickStart will grow and mature in a way no commercial vendor can keep up with us.
Screencast
A picture is worth a 1000th words, so a movie will definitely be able to show you the power and ease of Activiti KickStart.
Activiti 5.0 released!
After nine months of hard work, the Activiti team is extremely proud to present Activiti 5.0 GA!
Read all about it on Tom’s blog!
BPMN 2.0 process modeling on the iPad
In the past years, I’ve seen my fair share of meetings where were we needed to draw business processes … ad-hoc or working on existing models. Poster-sized paper, whiteboards, beer coasters, … I’ve used it all. I can tell quite some hilarious stories about those meetings … but that’s probably content for another post. Main thing is: in 2010, this is just not the way anymore the game is played.
The Activiti BPM suite ships out-of-the-box with a cool webbased modeling tool, which allows anybody to collaborate from anywhere on their business processes. This modeling tool is donated to Activiti by our friends at Signavio.
And today, they’ve pushed out iPad support for their process modeling tool. This is just way too cool if you think about it. Discuss, model and collaborate on processes from basically everywhere you are – with decent graphics and all stored on the server. Gone are the ‘quirks’ attached to using ancient ‘technologies’ such as losing the paper, wet beer coaster, unreadable scribbling, etc.
Check it out in this video from the Signavio team itself.
And now I *really* want an iPad….
The curtains are pulled: Alfresco launches Activiti

After some weeks of silence, we can now finally pull the curtains … and reveal Activiti to the world!
Activiti is a super-fast and rock-solid BPM and workflow engine that natively runs BPMN 2.0. It’s completely open-source (Apache licence) and embeddable in any Java environment.
Tom and I joined Alfresco about two months ago, and we’ve kept ourselves quite busy. So together with this announcement, I’m proud to present the first alpha release of Activiti. Go and play with it while it’s hot!
Activiti is all about what made jBPM great, and taking giant leaps from there. Tom nicely summarizes it in his blogpost. A lot more information can be found on the Activiti website.
Official Alfresco press release: click here.
Regards,
Joram


