Calling an EJB from an SOA composite

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.

Getting ready

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.

How to do it...

  1. Add an EJB reference.

    Open the composite in JDeveloper and drag the EJB Service from the Component Palette onto the References section of the composite.xml Design View.

    How to do it...
  2. Start configuring EJB.

    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.

    How to do it...
  3. Select the EJB JAR file. Click on the magnifying glass How to do it... and use the SOA Resource Browser to find your EJB JAR file. After selecting your file and clicking on OK, you will be asked if you want to copy the file into your project. Click on Yes to copy the file into your project.
    How to do it...
  4. Select the Java interface that you want to use. Click on the magnifying glass How to do it... and use Class Browser to find your EJB's interface in the class Hierarchy. Select the interface you want and click on OK.
    How to do it...
  5. Complete the EJB reference creation.

    After reviewing your EJB Service settings, you can click on OK to complete the creation of the reference.

    How to do it...
  6. Wire the EJB reference to a component. Wire an EJB reference to a component by selecting the inbound service arrow How to do it... on the EJB reference in the External References section of the Design view, and drag it onto a component in the Components section. The outbound reference arrow will automatically appear as you move close to a component.
    How to do it...

    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.

    How to do it...

The EJB reference is now ready to be used in the selected component. It can be accessed just like any other reference.

How it works...

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.

Note

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.

There's more...

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.

See also

  • The Customizing the XML mapping of an EJB recipe in this chapter
  • The Using an EJB reference in a Spring component recipe in this chapter
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.202.203