Exposing an EJB session bean as an EJB on the OSB using the JEJB transport

The JEJB transport allows passing POJOs through the OSB. We can use the JEJB transport on proxy service and expose the proxy service as a remote EJB. For the consumer/client, the proxy service looks like a normal stateless session bean. This will add an additional layer between the client and some existing EJB session beans, which provides additional functionality and agility, such as:

  • Replacing the original EJB by something else, that still provides the same interface to the existing clients
  • Doing some transformations between the EJB client and the EJB session bean implementation
  • Implementing logging
  • Using the capabilities of OSB to monitor SLA's

In this recipe, we will implement the same EJB session bean interface on the OSB and just pass-through the messages:

Exposing an EJB session bean as an EJB on the OSB using the JEJB transport

Getting ready

Make sure that the EJB session bean is deployed to the OSB server as shown in the Introduction section of this chapter.

How to do it...

First we have to create a new OSB project and then register the customer management service interface JAR. To make the JAR available, we will use the Import functionality of Eclipse OEPE. This is an alternative way to the copy-paste approach we have used in the previous recipe. In Eclipse OEPE, perform the following steps:

  1. Create a new OSB project exposing-session-bean-as-ejb and create a jar, business, and proxy folder in this new project.
  2. Select the jar folder and from the File menu select Import.
  3. Expand the General folder, select File System, and click on Next.
  4. Click on Browse next to the From directory field and navigate to the deploy folder in the Model project folder.
  5. Only select the customerManagementInterface.jar and click on Finish:
    How to do it...

    Next, we will create a new business service that will call the customer management EJB session bean:

  6. Within the business folder, create a new business service and name it CustomerManagement.
  7. n the General tab select Transport Typed Service as the Service Type.
  8. Navigate to the Transport tab.
  9. Select jejb for the Protocol drop-down listbox.
  10. Enter jejb::CustomerManagementService#cookbook.model.services.CustomerManagement into the Endpoint URI field and click on Add.
  11. Navigate to the JEJB Transport tab.
  12. Choose 3.0 for the EJB Spec Version.
  13. Click on the Browse button next to the Client Jar field.
  14. In the Select a Java Archive Resource window, expand the wrapping-session-bean-with-jejb-transport project.
  15. Select the customerManagementInterface.jar and click on OK.
  16. Rename the Return name of the findAllCustomers operation to customers.
  17. Change the Parameters name field of the findCustomer method to id.
  18. Rename the Return name of the findCustomer operation to custome:
    How to do it...

    Create a proxy service with a JEJB transport, which calls this business service. In Eclipse OEPE, perform the following stes:

  19. Right-click on the CustomerManagement.biz business service and select Oracle Service Bus | Generate Proxy Service.
  20. Select the proxy folder in the tree and enter CustomerManagement into the File name field.
  21. Navigate to the JEJB Transport tab.
  22. Choose 3.0 for the EJB Spec Version option and make sure that the Pass XMLBeans by value checkbox is enabled.
  23. Click on the Browse button next to the Client Jar field.
  24. In the Select a Java Archive Resource window, expand the wrapping-session-bean-with-jejb-transport project, select the customerManagementInterface.jar, and click on OK.
  25. Rename the Return name of the findAllCustomers operation to customers.
  26. Change the Parameters name field of the findCustomer method to id.
  27. Rename the Return name of the findCustomer operation to customer:
    How to do it...
  28. Navigate to the Message Flow tab.
  29. Navigate to the Properties tab of the Routing action, which has been generated and enable the Use inbound operation for outbound option.
  30. To see the information passed into the proxy service we log the value of the $body variable. Right-click on the Request action and select Insert Into | Reporting | Log to add a Log action.
  31. Click on Expression, enter $body as the expression, and click on the OK button.
  32. Enter $body in Request into the Annotation field and select Warning for the Severity drop-down listbox.
  33. To see the information returned by the EJB session bean, we log the value of the $body variable. Copy the Log action from the Request Action and paste it into the Response Action.
  34. Enter $body in Response into the Annotation feld:
    How to do it...
  35. Save the project and deploy it to the OSB server.

    Now it's time to test the OSB service. In JDeveloper, again open the osbbook_jejb.ws workspace and perform the following steps to change the already used Java test class to no longer invoke the EJB session bean, but invoke the proxy service with the JEJB transport:

  36. Open the osbbook_jejb.jws workspace and expand the client project until reaching the CustomerManagementClient.java class.
  37. Change the JNDI name of the context.lookp code:
    CustomerManagement customerManagement = (CustomerManagement)context.lookup("CustomerManagement#cookbook.model.services.CustomerManagement");
    
    How to do it...
  38. Right-click on the CustomerManagementClient.java file and select Run.
  39. Check that the output in the JDeveloper Log window is the same as before, when testing the EJB session bean directly.
  40. We can check that the proxy service really was executed by checking the output of the two Log actions:
    How to do it...

The value of the request, which on the transport level is a Java bean, is translated into an XML representation with all the properties (id in our case) as elements. We have triggered this behavior by enabling the Pass XMLBeans by value on the JEJB transport configuration of the proxy service. This is of course helpful if we need to trigger some action based on the value of the request message or we need to simply log the request message.

This is not the case with the response. In the response, we only get a reference to the Java object. If we need access to the values, then we have to use a Java Callout action that we will cover in the next recipe, Manipulating, the, response, of, the, JEJB, transport, by, a, Java, Callout, action.

How it works...

The JEJB transport lets us pass POJOs through the OSB. We created a proxy service which implements the same EJB interface as the business service wrapping the EJB session bean on the EJB server. To switch to the EJB implementation on the OSB in the consuming Java class, we only had to change the JNDI alias of the context lookup to point to the EJB interface implemented by the proxy service.

To the Java EE client, the JEJB proxy service looks like an EJB stateless session bean.

The JEBJ transport is always synchronous and the message exchange pattern is always request-response.

..................Content has been hidden....................

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