In this recipe, we will call an Enterprise Java Bean Session Bean from within a composite. This is useful if we have an existing EJB that we wish to re-use.
Make sure that you have opened the composite to which you will add the EJB reference. There will be one item in the list for each parameter of our function.
Open the composite in JDeveloper and drag the EJB Service from the Component Palette onto the References section of the composite.xml
Design View.
Select a Name for the EJB reference. Select the Type as Reference. Select the Version of an EJB specification that the EJB has implemented. Set the Interface to be Java.
After reviewing your EJB Service settings, you can click on OK to complete the creation of the reference.
If the component is not a Java component, a dialog box will appear telling you that a WSDL file was generated for you based on the EJB interface chosen.
The EJB reference is now ready to be used in the selected component. It can be accessed just like any other reference.
The EJB reference is given the Java Naming and Directory Interface (JNDI) location of an EJB that implements the given Java interface. At runtime, the container will look this JNDI location up to obtain a reference to the EJB. If this reference is of type "Java", it can be used by other Java components without requiring any additional translation. If the reference is of type Java and is consumed by a non-Java component, such as a Mediator or BPEL process, then a mapping from XML to Java is generated to allow consumption of the EJB by the non-Java component. Finally, if the type is "WSDL", the Java interface is translated to XML for all the consumers, and the Java components will access the EJB through a WSDL interface.
The Java-to-XML translation can only be generated if the EJB interface has simple types or Java beans as the input parameters and return value. For example, the schema element for a generic object type cannot be autogenerated. Similarly, all exceptions thrown must only contain simple types and/or Java beans. Java beans must have a public no parameter constructor and only consist of simple types and other Java beans. Finally, the entire object graph must be instantiated in order for the Java object to be converted to XML, so lazy loading is not supported.
EJBs with complex interfaces can be consumed by other Java components, and so one way to provide access to an EJB with complex interfaces is to inject it into a Spring component that provides a wrapper interface to convert the interface into one for which SOA Suite can automatically generate Java/XML conversions. This approach shows the EJB dependency in composite.xml
, but allows us to use complex Java interfaces.
When consuming an EJB with a non-Java component, we can control the way the Java interface parameters are mapped onto an XML schema by use of EXD files.