Wednesday, October 7, 2015

WSO2 ESB EJB Mediator

The 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.

 

 

 

 Syntax


<ejb beanstalk="string" class="string" [sessionId="string"] [remove="true | false"] 
  [method="string"] [target="string | {xpath}"] [jndiName="string"] /> 
    <args> 
      <arg (value="string | {xpath}")/>* 
    </args> 
</ejb>

This is how EJB Mediator will be in proxy

Parameter Name
Description
Add ArgumentCan be used to define the arguments which is required for the particular ejb method to be invoked Expression/Value. 
Beanstalk IDReference to the application server specific connection source information, which is defined at the synapse.properties.
ClassThis required the remote interface definition provided in the EJB 3.0 (EJB service invocation remote/home interface).
JNDI NameThe Java Naming and Directory Interface (JNDI) is an application programming interface (API) for accessing different kinds of naming and directory services. JNDI is not specific to a particular naming or directory service. It can be used to access many different kinds of systems including file systems; distributed objects systems such as CORBA, Java RMI, and EJB; and directory services such as LDAP, Novell NetWare, and NIS+.
RemoveThis parameter specifies whether the Enterprise Entity Manager should remove the EJB context related parameters once the state full/stateless session is invoked.
Session IDWhen the EJB context is invoked in the form state-full bean then the related ejb session status specified will be stored in here. Possible values are as follows.
  • Value: If this is selected, the session ID can be entered as a static value.
  • Expression: If this is selected, an XPath expression can be entered to evaluate the session ID.
TargetIf a particular EJB method returns, then the return object can be saved against the the name provided in the target at the synapse property context.
 

Sample ejb Syntax

    <ejb beanstalk="rajjaz"
              class="org.NewBeanRemote"
              method="sayHello"
              target="response"
              jndiName="ejb:/EJBModule3/NewBean!org.NewBeanRemote">
            <args>
               <arg xmlns:m="http://org" value="{//m:name}"/>
            </args>
         </ejb>

above one is the sample catch the value come as name and pass it to the method sayHello in ejb class JNDI Named as NewBeanRemote then it will catch the output come within response tag.

the values for the JNDI Properties will be set the Synapse.properties

Synapse.properties


synapse.beanstalks=rajjaz
synapse.beanstalks.rajjaz.java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
synapse.beanstalks.rajjaz.cache.warn.limit.stateless=5
synapse.beanstalks.rajjaz.cache.warn.limit.stateful=5
synapse.beanstalks.rajjaz.cache.timeout.stateless=1
synapse.beanstalks.rajjaz.cache.timeout.stateful=1  

lets discuss how to run helloworld sample using WSO2 ESB ejb mediator in next post

Source code

References