Thursday, June 7, 2012

EJB Mediator WSO2 ESB 4.5.0

WSO2 ESB ( EJB Mediator)

This article will basically provide the attention on how to configure WSO2 ESB to work with EJB services, with ESB 4.5.0 you will be able to invoke ejb 3.0 services host in remote Application server, so In order to achieve this we have introduced 2 new implementations which is known as EJB and Bean Mediators

Applies To

WSO2 ESB 4.5.0

The configuration Language of new mediators

Bean mediator - Bean mediator can manipulate a JavaBean that is bound to the Synapse message context as a property. This mediator can be used to create a new bean (CREATE action), remove an existing bean (REMOVE action), set a property of an existing JavaBean (SET_PROPERTY action) or to retrieve a property of an existing JavaBean (GET_PROPERTY action). Classes of objects manipulated by this mediator must follow the JavaBeans specification.

EJB Mediator - EJB mediator calls an external Enterprise JavaBean(EJB) and stores the result in the message payload or in a message context property. Currently, this mediator supports EJB3 Stateless Session Beans and Stateful Session Beans.


In the context of EJB the the implementation is focused on statefull and stateless session beans, so later when dicussing the sample scenarios and will dig in to the details on how to configure those with the WSO2 Ejb mediator
So let us now focus now on configuring EJB service invocation with WSO2 ESB
Probably the WSO2 ESB 4.5.0 onwards the EJB features are included with GUI features as well so you may find it easy to config them without any issues
  • Please download Jboss 7(jboss-as-7.1.1.Final Latest)  we do have test this with different application servers but for this demonstration we will be using Jboss 7 there you need to  copy jboss-client.jar to ESB_HOME/repository/components/lib
  • Please find the EJBDemo.jar (Ejb service) you will be find the EJBDemo jar attached with this article (will discuss what this demo service and its implementation seperately) please copy the EJBDemo.jar file to  JBOSS_HOME/standalone/deployments/  and  ESB_HOME/repository/components/lib
  • As next step you may have to configure AS connection properties and the you will be able define them in (ESB_HOME/repository/conf ) it has following properties which is required to communicate with the AS,depending on the application server which you may use the configuration parameteres might get change, the following is required when you need to connect EJB services hosted in Jboss AS 7
  • Start ESB and Jboss AS
Synapse. properties configuration
In case if you use Jboss 5 you may have to use the connection properties as follows

Configure Ejb Mediator with stateless bean

Idea of this demo such as when requests closest location he has to pass latitude and longitude (x,y coordination), in this scenario when the requests comes first we need to invoke the getClosestStore method which is exposed as EJB service, and to invoke the method it requires Location information then by processing in coming x,y assigning them to the location variables using Bean mediator we will call Ejb Mediator and the return resutl will be assign to the synapse property context and using the return value call getStoreById there it will return the store object ( a complex object) and using enrich mediator we can transform the incoming request as requires by the source, let see how this can be configured in ESB level


  • Create instance of Location object loc using bean mediator assign latitude and longitude values to the variable of loc instance
  • Call getClosestStore passing location instance as argument parameter using EJB mediator and the return variable will be assgined to loc_id
  • Call getStoreById using EJB mediator pass the loc_id returns form the earlier EJB invocation assign the return value the synapse property context with “store”
  • Do the enrich process assign the the store object return information and pass them back to the back end
Request and Response Sample
Stateless Session Beans



253, Kandy Road, Kadawatha

Configure EJB Mediator with State-full Session Bean

In the above diagram we will simulate the shopping cart operation, there user is sending multiple items which he has selected, when message reaches to the ESB engine EJB Mediator mediator context is assigning unique ejb session id for the particular request and keep that in the synapse the memory , ejb session id will be use later to invoke other total amount calculated for the cart items, so the process is then goes on by iterating the each items to the ejb service and populate the cart element, and later when iteration on completes it just invoke the getTotal by requesting the ejb session context generated earlier

Request and Response Sample
Stateful Session Beans



Resources :