Use the ESBREQUEST parameter to enrich and filter Routing Services in Oracle ESB

Every developer must have those moments when you feel you are completely stuck with some problem. You feel like you are never going to solve the issue at hand. The attempt is doomed, you have failed. Well, let’s get a good night’s sleep, who knows what will happen. And the next day, that glorious moment when all of a sudden you see the light, you get going again and you resolve the issue. It may very well be that those moment define what really is so great about programming. Getting unstuck.

The other night, I was working with the Oracle Enterprise Service Bus, building a Domain Service that is called with the name of a specific domain of allowable values, reads data synchronously from a file that contains a great number of domains, filters the results from the file read and returns the filtered results, enriched with the name of the domain as originally requested. But I could not figure out how to filter the results from the File Adapter based on information from the Service Request. I really got stuck.

Sometimes a single remark in some article or an off-hand comment in a tutorial or a bit of information Googled up from the internet can force that breakthrough. The exact right piece of information at the exact right time. My precious piece of knowledge to get unstuck came from a Discussion Thread on the OTN Forum on Oracle Enterprise Service Bus:

Data enrichment in Oracle ESB started by Allan from Glasgow. I have to thank Allan for asking my questions for me and Alistair from Vancouver and Dave Berry from Oracle for providing the bits and pieces I was in need of. Thanks guys!

So what that incredible clue I got from this OTN thread? It is called ESBREQUEST. It is a parameter you can add (or have added) to the XSLT document used to map the reply from the service invoked by one of the Routing Rules in the Routing Service. The parameter makes the content of the Request that went into the Routing Service available during the transformation of the results. This data from the original request can be added to the results (enrichment) or used to filter the results. I will show a simple example of using the ESBREQUEST parameter.

I have created the DomainValuesService, a very simple service that is called with a request defined as follows:

It requires the name of a domain and can also handle a language, a search/match pattern and a maximum number of elements to return. The reply returned by this Synchronous service is defined through the next XSD complexType:

This specifies a reply that can hold the allowable values for a single domain – a child element DomainValue within the root element.

The domain values are being maintained in an XML file that lives on the file system. The ESB Service needs to receive the request for the values in a specific domain, read the file with all the domain, filter the results read from the file to only contain values from the domain requested, return the results in the format specified in the DomainServiceResponseType.

First of all, I create a File Adapter Service that synchronously reads the file that holds the domains. This file is specified through and XSD:

This is a special File Adapter Service: it reads a file yet it is considered outbound. It does not poll for files, it does not write a file. It reads one particular file – as if it were a database table!

After having set up the File Adapter Service, I create a Routing Service: it receives the Service invocation, calls the File Adapter Service to read the file and then has to transform and filter the results from the file read into the reply to be returned to the caller.

Press OK and go define the Service(s) to be invoked:

I have indicated that I want to invoke the SynchRead operation on the ReadFileDomains File Adapter Service. This service call will return the XML document with all the domains. Now I want to filter that document in order to only reply from this Routing Service with the requested domain. I need to set up the proper Transformation Map to that end:

If you check the check box Include Request in the Reply Payload you will have an extra parameter ESBREQUEST to retrieve data from during the transformation! When you look at the source of the XSLT Mapper document, it is specified as follows:

<xsl:param name="ESBREQUEST"/>

Note that the $ESBREQUEST parameter starts at the root-element of the Request element that was sent into the Routing Service. in this example, that means that the $ESBREQUEST parameter is an XML fragment starting with a domainServiceCall element.

The esbsvc file created for the Routing Service is where the check Include Request in the Reply Payload check box reemerges:

If the attachRequestPayload attribute of the transformation element is not set to true (and by default it is set to false), there will be no ESBREQUEST parameter available during the transformation. There does not seem to be a way to include the request into the payload later on: if you miss the checkbox during initial creation of the mapper file, you cannot get it back through the GUI. It seems that the best you can do is close all files in JDeveloper (even better, close the project) edit the esbsvc file for the Router Service through a text editor on the file system, refresh the files in JDeveloper (or reopen the project) and edit the mapper XSL file.

Making use of the ESBREQUEST parameter in the transformation

The importance of the ESBREQUEST parameter of course lies in what we can do with it. As it contains all information that we received in the request into the Routing Service, we can use that information for filtering or other transformation purposes. In my domains example, I want to create a Reply that only contains the requested domain. Furthermore, I want the name of the domain as requested to also appear in the reply (basically copying that value from the ESBREQUEST parameter into the reply).

Using this transformation map with the filter on domains using the XPath expression [Name=$ESBREQUEST//out1:name] fueled by data from the request, I can quickly extract the domain that is requested.

In general the ESBREQUEST parameter allows me to manipulate the reply from any synchronous RouterService using the content from the request into the service. I can add information from the request to the reply as well as use the data from the request to perform filtering and other manipulation. That is really useful!

Related Posts

1 Comment

is it also possible to write into the ESBREQUEST parameter. E.g. I send data into the routing service, lets imagine this data are email and attachment data. Inside the routing service I call a webservice to archive the attachment(s) into an archive system. This webservice sends me the unique document id back in the reply message, where I also include the ESB Request Information. Now I would like, to store this received document id into the originanl routing service request –> ESBRequest paramenter.

After this I would hope that the routing service request is also able to use in a further routing rule, where I call another webservice to store the enriched payload into a message queue for further processing.

Please tell me if this is possible as also how I could call the same webservice several times (in case of more than one attachment).

Best regards, Peter

Lucas Jellema

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director for Fusion Middleware. Consultant, trainer and instructor on diverse areas including Oracle Database (SQL & PL/SQL), Service Oriented Architecture, BPM, ADF, JavaScript, Java in various shapes and forms and many other things. Author of the Oracle Press books: Oracle SOA Suite 11g Handbook and Oracle SOA Suite 12c Handbook. Frequent presenter on conferences such as JavaOne and Oracle OpenWorld. Presenter for Oracle University Celebrity specials.

Follow us on Twitter

meta

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 323 other subscribers

Email Address

About

AMIS is internationally recognized for its deep technological insight in Oracle technology. This knowledge is reflected in the presentations we deliver at international conferences such as Oracle OpenWorld, Hotsos and many user conferences around the world. Our AMIS Technology Blog, the most referred Oracle technology knowledge base outside the oracle.com domain. However you arrived here, we appreciate your interest in AMIS. Link to our Google+ Profile AMIS