We have created a Java class, packaged it as a JAR and invoked it from the OSB proxy service through a Java Callout action. Only static methods can be invoked through the Java Callout action; other, non-static methods will not be shown when browsing the classes/methods.

The JAR is deployed with the OSB project to the OSB server and it will always run inside the OSB server.



We will show how we can use a Java Callout action to invoke Java code, which might already exist. This is an easy way to extend the standard functionality of the service bus.

We will use the Java Callout action to call a Java method which returns the Checksum of the message passed as the parameter. The functionality of calculating a checksum is not available as an XPath/XQuery function and adding it through a Java Callout action is of course much simpler and more efficient than using a real web service.

We will first create the Java project with the Java class holding the checksum calculation functionality. In Eclipse OEPE, perform the following steps:

1. Right-click on the Project Explorer and select New | Project.

2. Enter java into the Wizards field, select Java Project and click Next.

3. Enter osb-checksum-util into the Project name field.

4. Click Finish and confirm the pop-up window with Yes to switch to the Java perspective.

5. Right-click on the osb-checksum-util project and select New | Class.

6. Enter osbcookbook.util.checksum into the Package field.

7. Enter ChecksumUtil into the Name field and click Finish.

8. Implement the following static method inside the ChecksumUtil class:

public static long calculateChecksum(String data) {
Checksum checksum = new CRC32();
checksum.update(data.getBytes(), 0,
data.getBytes().length);
return checksum.getValue();
}
9. Right-click on the source and select Source | Organize Imports.

By doing that, the checksum functionality is ready to be used. In order to invoke it through a Java Callout, it needs to be packaged into a Java Archive (JAR) file and copied into the OSB project. In Eclipse OEPE, perform the following steps:

10. Right-click on the osb-checksum-util project and select Export.

11. Enter java into Select an export destination and select JAR file.

12. Click Next.

13. In the Select the resources to export tree, select the osb-checksum-util project.

14. Click Browse right to the JAR file drop-down listbox.

15. Navigate to the jar folder inside the using-java-callout-to-invoke-java OSB project, enter osb-checksum-util.jar into the File name field and click Save.

16. Click Next and then Finish.

Now, let's switch to the OSB project and implement the proxy service calling our new Java calls through a Java Callout. In Eclipse OEPE, perform the following steps:

17. Switch to the Oracle Service Bus perspective.

18. Refresh the jar folder inside the using-java-callout-to-invoke-java project by pressing F5 and check that the JAR file created previously is located inside the jar folder.

19. Create a new proxy service inside the proxy folder and name it Checksum.

20. On the General tab, select Messaging Service for the Service Type option.

21. Navigate to the Messaging tab and select Text for both the Request Message Type and Response Message Type option.

22. Navigate to the Message Flow tab.

23. Insert a Pipeline Pair node and name it CalculateChecksumPipelinePair.

24. Insert a Stage into the Request Pipeline and name it CalculateChecksumStage.

25. Insert a Java Callout action into the stage.

26. On the Properties tab of the Java Callout action, click Browse to select the method to call.

27. Navigate to osb-checksum-util.jar in the jar folder of the project and click OK.

28. Select the public static long calculateChecksum(java.lang.String) method and click OK.

29. Click <Expression> and enter $body/text() into the Expression field and click OK.

30. Enter checksumValue into the Result Value field.


We have added the Java Callout action to invoke our Java method and after that the checksum value is available in the checksumValue variable. Let's add a Replace action to return the checksum in the body variable. In Eclipse OEPE, perform the following steps.

31. Insert a Replace action after the Java Callout action.

32. Enter $checksumValue into the Expression field.

33. Enter body into the In Variable field.

34. Deploy the project to the OSB server.

Now let's test the proxy service by performing the following steps in the Service Bus console:

35. In the Project Explorer navigate to proxy folder inside the using-java-callout-toinvoke-java project.

36. Click on the Launch Test Console icon of the Checksum proxy service.

37. Enter some text to calculate the checksum on into the Payload field and click on Execute.

38. The output of the Java Callout action and the checksum calculation will be shown in the Response Document section.




Leave a Reply

Subscribe to Posts | Subscribe to Comments

About This Site

Howdy! My name is Suersh Rohan and I am the developer and maintainer of this blog. It mainly consists of my thoughts and opinions on the technologies I learn,use and develop with.
Powered by Blogger.

- Copyright © My Code Snapshots -Metrominimalist- Powered by Blogger - Designed by Suresh Rohan -