Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Oracle Service Bus 11g Development Cookbook

You're reading from  Oracle Service Bus 11g Development Cookbook

Product type Book
Published in Jan 2012
Publisher Packt
ISBN-13 9781849684446
Pages 522 pages
Edition 1st Edition
Languages

Table of Contents (19) Chapters

Oracle Service Bus 11g Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Creating a basic OSB service Working Efficiently with OSB Artifacts in Eclipse OEPE Messaging with JMS Transport Using EJB and JEJB transport Using HTTP Transport Using File and Email Transports Communicating with the Database Communicating with SOA Suite Communication, Flow Control, and Message Processing Reliable Communication with the OSB Handling Message-level Security Requirements Handling Transport-level Security Requirements Index

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

Introduction


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.

Getting ready

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.

How to do it...

First, we...

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.

Getting ready

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.

Getting ready

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.

How to do it...

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...

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.

Getting ready

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.

Getting ready

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.

How to do it...

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:

package osbcookbook.util.checksum;

import java.util.zip.CRC32;
import java.util.zip.Checksum;

public class ChecksumUtil {
  public static long calculateChecksum(String data) {
    Checksum checksum = new CRC32();
    checksum.update...

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.

Getting ready

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.

Getting ready

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.

How to do it...

A Split-Join is a separate artifact, which we will create first. In Eclipse OEPE, perform the following steps:

  1. Create an additional folder flow in the project using-dynamic-split-join.

  2. Right-click on flow and select New | Split-Join.

  3. Enter SplitJoin into the File name field and click Next.

  4. Navigate to the operation: StoreCustomer node of the CustomerManagement.wsdl file and click Finish.

  5. 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.

Getting ready

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.

How to do it...

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:

  1. Open the MessageValidation proxy service and navigate to the Message Flow tab.

  2. Insert a new stage into the MessageProcessingPipelinePair and name it MessageValidationStage.

  3. 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.

Getting ready

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:

Getting ready

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.

How to do it...

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:

  1. Create a new proxy service in the proxy folder and name it Tracing.

  2. On the General tab choose Any XML Service for the Service Type option.

  3. On the Transport tab choose local from the protocol drop-down listbox.

  4. Navigate to the Message Flow...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Oracle Service Bus 11g Development Cookbook
Published in: Jan 2012 Publisher: Packt ISBN-13: 9781849684446
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}