This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Configuring EJB2 Connector Operations

Overview

The following operations allow you to work with the EJB2 connector. Click an operation name to see details on how to use it.

For a sample proxy service that illustrates how to work with the file connector, see Sample configuration.

EJB2 Connector

EJB2 Connector used to create a client Dynamically from the esb Configuration and if method is not a void method then it will add the return value into messagecontext property. it’s have two methods called Stateless bean and Stateful bean. and EJB2 Connector will support with multiple Servers and its tested with Jboss 5.1 and GlasFish 4. before start the ESB copy the client libraries and service jar inside the component->Lib folder.

Operation details

This section provides further details on the operations related to theEJB2 connector.

Init Operation

init method will contain JNDI Naming Property and in order identify correct property we need to set key value and property value name should be start with that key name. these values are depend on the backend server we are using above one is example for glassfish 4

Init
<ejbconnector.init>
	<key>raj</key>
	<raj.java.naming.factory.initial>com.sun.enterprise.naming.SerialInitContextFactory</raj.java.naming.factory.initial>
	<raj.org.omg.CORBA.ORBInitialHost>localhost</raj.org.omg.CORBA.ORBInitialHost>
	<raj.org.omg.CORBA.ORBInitialPort>3700</raj.org.omg.CORBA.ORBInitialPort>
</ejbconnector.init>
  • key: unique identifier for each context
  • key.{name}: this depend on server properties and configuration(property value name)
  • key.{name}.Value:value of the key.{name}(property value)

Stateless Bean

A stateless session bean is a session bean with no conversational state. All instances of a particular stateless session bean class are identical.

A stateless session bean and its client do not share state or identity between method invocations. A stateless session bean is strictly a single invocation bean. It is employed for reusable business services that are not connected to any specific client, such as generic currency calculations, mortgage rate calculations, and so on. Stateless session beans may contain client-independent, read-only state across a call. Subsequent calls are handled by other stateless session beans in the pool. The information is used only for the single invocation.
OC4J maintains a pool of these stateless beans to service multiple clients. An instance is taken out of the pool when a client sends a request. There is no need to initialize the bean with any information.

Stateless Bean
<ejbconnector.stateless>
	<jndiName>HelloBean</jndiName>
	<method>sayHello</method>
	<param.arg1>Rajjaz</param.arg1>
</ejbconnector.stateless>
<ejbconnector.stateless>
	<jndiName>HelloBean</jndiName>
	<method>sayHello</method>
	<return>out</return>
</ejbconnector.stateless>
  • method: name of the method.
  • param.arg{X}:this will be name of the arguments and it want to be in a flow like param.arh1,param,arg2..
  • jndiName: Java API for a directory service.

Stateful Bean

A stateful session bean is a session bean that maintains conversational state.

Stateful session beans are useful for conversational sessions, in which it is necessary to maintain state, such as instance variable values or transactional state, between method invocations. These session beans are mapped to a single client for the life of that client.

A stateful session bean maintains its state between method calls. Thus, there is one instance of a stateful session bean created for each client. Each stateful session bean contains an identity and a one-to-one mapping with an individual client.

When the container determines that it must remove a stateful session bean from memory (in order to release resources), the container maintains the bean's state by passivation (serializing the bean to disk). This is why the state that you passivate must be serializable. However, this information does not survive system failures. When the bean instance is requested again by its client, the container activates the previously passivated bean instance.

The type of state that is saved does not include resources. The container invokes the ejbPassivate method within the bean to provide the bean with a chance to clean up its resources, such as sockets held, database connections, and hash tables with static information. All these resources can be reallocated and re-created during the ejbActivate method.

If the bean instance fails, the state can be lost, unless you take action within your bean to continually save state. However, if you must make sure that state is persistently saved in the case of failovers, you may want to use an entity bean for your implementation. Alternatively, you could also use the SessionSynchronization interface to persist the state transactionally.

Stateful Bean
<ejbconnector.stateful>
	<jndiName>HelloStateful</jndiName>
	<method>setName</method>
	<param.arg1>Rajjaz</param.arg1>
</ejbconnector.stateful>
<ejbconnector.stateful>
	<jndiName>HelloStateful</jndiName>
	<method>getName</method>
	<return>out</return>
</ejbconnector.stateful>
  • method: name of the method
  • param.arg{X}:this will be name of the arguments and it want to be in a flow like param.arh1,param,arg2..
  • jndiName:Java API for a directory service.


Sample configuration

Sample Proxy
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="ejb2Stateless"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <property name="argument1" expression="json-eval($.argument1)"/>
         <property name="argument2" expression="json-eval($.argument2)"/>
         <property name="method" expression="json-eval($.method)"/>
         <property name="jndiName" expression="json-eval($.jndiName)"/>
         <property name="return" expression="json-eval($.return)"/>
			<ejb2.init>
				<key>raj</key>
    			<raj.java.naming.factory.initial>org.jnp.interfaces.NamingContextFactory</raj.java.naming.factory.initial>
   				<raj.java.naming.factory.url.pkgs>org.jboss.naming:org.jnp.interfaces</raj.java.naming.factory.url.pkgs>
			    <raj.java.naming.provider.url>localhost</raj.java.naming.provider.url>
			</ejb2.init>
			<ejb2.stateless>
    			<jndiName>{$ctx:jndiName}</jndiName>
    			<method>{$ctx:method}</method>
    			<param.arg1>{$ctx:argument1}</param.arg1>
    			<param.arg2>{$ctx:argument2}</param.arg2>
    			<return>{$ctx:return}</return>
			</ejb2.stateless>
			<property name="out" expression="get-property('Result')"/>
			<payloadFactory media-type="json">
   				 <format>{ "Result": $ctx:out}</format>
   				 <args/>
			</payloadFactory>
			<respond/>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>

 



358
363
365
367
514
28
30

 

31

 

58
60
67

 

11

 

24
37
66