Manipulating the response of the JEJB transport by a Java Callout action

In this recipe, we show how to change the response and enrich the message by a value for the rating attribute. For that, we have to create a Java class that we will call from the message flow of the proxy service through a Java Callout action:

Manipulating the response of the JEJB transport by a Java Callout action

We have created a simple Java class as shown in the following screenshot:

Manipulating the response of the JEJB transport by a Java Callout action

As we can see, this Java class has one method, which enriches the value of the rating attribute of a customer object based on the value of the first name attribute. The method accepts a parameter of type Object and cast this to a Customer type.

To make it available to OSB, we have to package the Java classes into a JAR. This JAR is available as enrichment.jar in the ejb-jdev-workspaceejbdeploy folder.

Getting ready

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

Import the base OSB project containing the necessary schemas and the right folder structure into Eclipse from chapter-4getting-readychange-response-of-jejb-transport.

How to do it...

Let's make the Java class available in the OSB project. In Eclipse OEPE, perform the following steps:

  1. Copy the JAR file enrichment.jar from the ejb-jdev-workspaceejbdeploy folder and paste it into the jar folder.
  2. To add the Java Callout action, open the CustomerManagement proxy service and navigate to the Message Flow tab
  3. In the Response Action, insert a Java Callout action after the Log action. Right-click on the Log action inside the Response Action and select Insert After | Message Processing | Java Callout.
  4. On the Properties tab of the Java Callout action, click on Browse.
  5. Expand the tree and navigate to the enrichmentByCallout.jar file.
  6. Click on OK.
  7. Expand the CustomerResponse node and select the static enrichCustomerResponseByRating method:
    How to do it...
  8. Click on OK.
  9. On the Properties tab of the Java Callout action, click on Expression in the Action cell.
  10. Enter $body/open:findCustomerResponse/open:customer/ctx:java-content into the Expression field.
  11. Click on OK.
  12. Back on the Properties tab of the Java Callout action enter changedResponse into the Result Value field:
    How to do it...
  13. Right-click on the Java Callout action and select Insert After | Message Processing | Replace.
  14. On the Properties tab of the Replace action enter body into the In Variable field.
  15. Click on XPath and enter /open:findCustomerResponse/open:customer/ctx:java-content.
  16. Click on Expression and enter $changedResponse, which holds the reference to the POJO returned from the Java Callout action.
  17. Enable the Replace entire node option:
    How to do it...
  18. The message flow should now look as shown in the following screenshot:
    How to do it...
  19. Save the project and deploy it to the OSB server.

Retest the implementation by using the same Java test class. The rating should no longer be null:

How to do it...

How it works...

When we examine the log output, we can see that the response from the EJB session bean contained in the body has the following content:

<soap:Body xmlns:soap="...">
  <ns:findCustomerResponse xmlns:ns="http://www.openuri.org/">
    <ns:customer>
      <con:java-content ref="jcid:-6bfa91a1:132950119a5:-7f3a" xmlns:con="http://www.bea.com/wli/sb/context"/>
    </ns:customer>
  </ns:findCustomerResponse>
</soap:Body>

The value of the con:java-content element, holds the reference to the POJO being passed back by the EJB session bean method. By passing that value of con:java-content to the Java Callout, we can then access the POJO in our enricher Java class.

The object returned from the enricher Java Callout is also in the form of con:java-content, which is used in the Replace action to overwrite the con:java-content part of the body variable.

There's more...

Be careful when using the Variable Structures tree to specify an expression into the java-content part (step 10 in the recipe).

If the argument names of the methods have been renamed, that is, from return to customer in our case, then the drag-and-drop feature implemented in Eclipse OEPE will not be aware of it.

If we drag the java-content element as shown in the following screenshot into the Expression field, then we manually have to replace return by customer, to get the correct expression $body/open:findCustomerResponse/open:customer/ctx:java-content:

There's more...
..................Content has been hidden....................

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