Chapter 9. Communication, Flow Control, and Message Processing
In this chapter, we will cover:
Using the Service Callout action to invoke a service
Using the Publish action to asynchronously invoke a service
Using the Java Callout action to invoke Java code
Using the Java Callout action with XMLBeans
Using custom XPath functions
Using the For Each action to process a collection
Using dynamic Split-Join to perform work in parallel
Using the Validate action to perform message validation
Enabling/disabling a Validate action dynamically
Creating private proxy service
In this chapter, we will show how to use different actions from the Communication, Flow Control, and Message Processing section of the OSB Design Palette.
We will show the various options to invoke other logic, such as Service Callout, Publish, and the Java Callout action as well as the ability to create custom XPath functions. Another topic covered is the processing of collections either through a loop sequentially or by a Split-Join in parallel. The validation of messages and the creation of private proxy services are also covered in this chapter.
Using Service Callout action to invoke a service
In this recipe, we will use a Service Callout action to call another service from a proxy service message flow.
We will use the sample setup from the first chapter of this book and add an additional service call to another service Credit Card Info Service, which returns the credit card information. The service call will be done using the Service Callout action. Both the information from the Credit Card Info Service and from the Customer Service will then be merged by the XQuery transformation into one single response returned by the proxy service.
You can import the OSB project containing the base setup for this recipe into Eclipse OEPE from \chapter-9\getting-ready\using-service-callout
.
Start the soapUI mock services simulating the two external services on the CRM system by double-clicking on start-CreditCardInfoServiceCRM.cmd
and start-CustomerServiceCRM.cmd
in the \chapter-9\getting-ready\misc
folder.
Using the Publish action to asynchronously invoke a service
In this recipe, we will use the Publish action to asynchronously invoke a service from the proxy service message flow, without having to wait for the calling service to finish its processing.
For this recipe, we have an external Processing Service, available as a soapUI mock service which takes quite some time to do its processing. The interface in the Processing Service WSDL is defined synchronous. We have a business service Processing which allows us to invoke the external service from a proxy service.
Instead of directly invoking the business service from the Publish proxy service, an additional proxy service Processing is added, which only exposes a one-way interface. By doing that, the Publish proxy service can use a Publish action to invoke the Processing proxy service without having to wait for external service to complete.
You can import the OSB project containing the base setup for this recipe, with the Processing...
Using the Java Callout action to invoke Java code
In this recipe, 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.
You can import the OSB project containing the base setup for this recipe into Eclipse OEPE from \chapter-9\getting-ready\using-java-callout-to-invoke-java
.
We will first create the Java project with the Java class holding the checksum calculation functionality. In Eclipse OEPE, perform the following steps:
Right-click on the Project Explorer and select New | Project.
Enter java
into the Wizards field...
Using the Java Callout action with XMLBeans
In this recipe, we will show how to use a Java Callout action to invoke a Java method, which will return XML messages. We have already seen that a Java method can return Java primitives or String values in the Using the Java Callout action to invoke Java code recipe. But the Java Callout action can also work with Apache XMLBeans, which allows us to directly pass XML message from a Java method to an OSB proxy service and vice versa, without having them serialized from String to XML. The Oracle Service Bus natively works with these XMLBean objects.
We will implement a proxy service which invokes a Java class inside a JAR using the Java Callout action, as shown in the following screenshot:
The Java class will format an XML message using Apache XMLBeans and return it to the proxy service. The message is then returned to the caller of the proxy service.
You can import the OSB project containing the base setup for this recipe into Eclipse OEPE...
Using custom XPath functions
In this recipe, we will show how to implement custom XPath functions, which extends the collection of XPath functions available with the OSB platform. We will use the same functionality that we used in the Using the Java Callout action to invoke Java code recipe, but now make the calculate checksum functionality available as an XPath function.
You can import the OSB project containing the base setup for this recipe into Eclipse OEPE from \chapter-9\getting-ready\using-custom-xpath-function
.
First we have to create the Java functionality we like to expose as a custom XPath function. We will reuse the same Java class we used in the Using the Java Callout action to invoke Java code recipe which is shown here:
Using the For Each action to process a collection
This recipe will show we can loop over a collection of information by using the For Each action. We will implement a proxy service accepting a Customer element through a one-way interface. The proxy service will use the For Each action in its message flow to loop over the single addresses inside the addresses collection.
Each address will then be sent to an Address Checking Service which would check the address for correctness. In our case, this service is a mock service implemented in soapUI. To better see the sequential nature of the processing, the Address Checking Service is written so that it takes four seconds to respond.
You can import the OSB project containing the base setup for this recipe into Eclipse OEPE from \chapter-9\getting-ready\using-foreach-to-process-collection
.
Start the soapUI mock service simulating the Address Checking Service by double-clicking on start-AddressCheckingService.cmd
in the \chapter-9\getting...
Using dynamic Split-Join to perform work in parallel
In this recipe, we will use the Split-Join functionality of the Oracle Service Bus to handle outgoing service callouts in parallel instead of the usually used sequential method.
You can import the OSB project containing the base setup for this recipe into Eclipse OEPE from \chapter-9\getting-ready\using-dynamic-split-join
.
Start the soapUI mock service simulating the Address Checking Service by double-clicking on start-AddressCheckingService.cmd
in the \chapter-9\getting-ready\misc
folder.
A Split-Join is a separate artifact, which we will create first. In Eclipse OEPE, perform the following steps:
Create an additional folder flow
in the project using-dynamic-split-join.
Right-click on flow and select New | Split-Join.
Enter SplitJoin
into the File name field and click Next.
Navigate to the operation: StoreCustomer node of the CustomerManagement.wsdl
file and click Finish.
The SplitJoin flow artifact will be shown in...
Using the Validate action to perform message validation
In this recipe, we will show how to use the Validate action to perform message validation. We will use the same proxy service setup we have used in the Using the For Each action to process a collection recipe, with a proxy service with a Messaging Service type interface accepting a customer element. We will use the Validate action in the proxy service to make sure that the messae passed in is a valid customer.
You can import the OSB project containing the base setup for this recipe into Eclipse OEPE from \chapter-9\getting-ready\using-validate-to-do-message-validation
.
Let's add the Validate action to the proxy service we imported previously in the Getting, ready section. In Eclipse OEPE, perform the following steps:
Open the MessageValidation proxy service and navigate to the Message Flow tab.
Insert a new stage into the MessageProcessingPipelinePair and name it
MessageValidationStage
.
Insert a Validate action...
Enabling/disabling a Validate action dynamically
In the previous recipe, we have seen how to use a Validate action for performing message validation. The problem of using message validation is that it can involve quite some overhead and often it's no longer necessary after some period of testing. Instead of removing it from the code, it would be nice to keep it in the code, so that it can be enabled dynamically if needed. This recipe will show how this can be achieved with a Java Callout and an If Else action.
The Java Callout action will invoke a Java method which accesses a bean configured by the Spring framework application context. This bean holds the condition of whether the validation should be performed or not. Spring makes it easy to expose a bean through JMX, which we will use to dynamically enable/disable the message validation.
You can import the OSB project containing the solution of the previous recipe into Eclipse OEPE from \chapter-9\getting-ready\enabling-validate...
Creating private proxy service
In this recipe, we will create a proxy service which can be reused and which is only available for other proxy services within the same OSB configuration, therefore we call it private proxy service in this recipe. The setup of the recipe is shown in the following screenshot:
Make sure to have the latest state of the basic-osb-service
project from the first chapter available in Eclipse OEPE. We will use it for this recipe. If necessary, it can be imported from here: \chapter-1\solution\with-transformation-proxy-service-created
.
First, we will create a new proxy service which will provide the internal functionality that can be reused by other proxy services. In Eclipse OEPE, perform the following steps:
Create a new proxy service in the proxy
folder and name it Tracing
.
On the General tab choose Any XML Service for the Service Type option.
On the Transport tab choose local from the protocol drop-down listbox.
Navigate to the Message Flow...