Wednesday, December 28, 2016

Using REST Adapter in 12c Service Bus with nXSD's XML as Input

In continuation to the previous post here, in this demo we will see how an XML fragment can be passed as input to the REST adapter in Service Bus instead of building query parameters and populate them in the $outbound variable.


Please follow everything in previous post until you create the REST adapter.
Now we will see what needs to be configure within the REST adapter.


1. Right click on the overview canvas and add REST service. Make sure that you have checked the check box down below the Type drop down. With this setting we can now call the REST adapter/service as a webservice. After completing the configuration, we can see WSDL file generated along with the WADL file corresponding to the REST adapter.

The main difference between previous demo and the present demo is this check box selection.


2.   In this step, we need to provide the URL, resource and operation details similar to the previous demo. Create a  new operation in Operation Bindings section of the window.
                                

3. In the new Operation window add a proper name to the operation and select the HTTP method as GET. In the Request parameter section, we need to specify the input which is now in XML format. To specify that we need to build the XML schema corresponding to the input XML. Now, click on the gear symbol next to the Schema URL text box.



4.  Native Format Builder wizard will pop up to build the schema, as below. Click Next


5.  Give a proper name to your schema. Click Next.


6. Based on the sample that we provide, a schema will be generated. Select XML Sample option and click Next.

7.  Provide a sample XML with required XML structure. And click Next.


8. The nXSD schema which is going to be generated will shown to you. Click Next. Once the REST adapter configuration is finished, you can see a new nXSD created for the input XML which will be input the REST adapter's business service.


9.  Now we have completed the schema. Click on Finish.



10.  Once the schema is built, the Operation Bindings window will look as below. In below screen shot, in parameter section, you can see Address and Key as the parameters. But GeoCode expects query parameters as lower case address and key. Please edit the parameters as lower case address and key.



11. In Response tab, select JSON and XML as the response format.

                   

12.  In previous demo we have created on nXSD for the response that is coming from GeoCode API. I am using the same nXSD here. Browse the nXSD in the search option just next to the Schema URL text box.


13. Once the schema is browsed, the Response tab looks as below. Since we have give the nXSD in the response section, the JSON response that is given by GeoCode will automatically be converted to XML.



 14. Finally the REST adapter window looks as below and click Finish.


15.  Now we need to invoke the REST adapter's business service from the pipeline. Create a pipeline. Inside the pipeline, add pipeline pair, stage and a service callout. In the service callout browse the Business Service corresponding to the REST adapter for GeoCode API.


16.  Now add an assign action inside the service callout's request action flow. With this assign action we will  populate $varInput variable. This input will be given to the GeoCode REST business service.



 For the elements AddressValue and KeyValue, the text value comes from the input payload of the pipeline.

17. Populate the output from REST adapter (from GeoCode API) in $body variable. This $body will be the output of the pipeline.



We have developed the pipeline. Deploy the code on integrated server in Jdev 12.2.1.0.
Test the pipeline from the test console.


Once you test the service, you can see that the service callout will call the REST business service. In the response of the service callout you can see that the JSON response from GeoCode API is already converted to XML since we have already provided required nXSD in the Response section of the REST adapter.




In both of these Demos what we try to achieve from GeoCode API is to validate the accuracy of an address. Once we give an address as input, GeoCode API, it will echo the same address along with the Geographical co-ordinates (this will confirm if the given address is existing one or not).

No comments:

Post a Comment