Previously I have posted about consuming ADF BC based REST Web Service in ADF. Now, this post talks about consuming JSON based REST Web Service using generic data control.
You can also look at previous posts on Web Service for more information.
In this post, I am using a free REST API Web Service to get all countries name. Check below link for detail of Web Service methods.
Let’s see how to implement this in JDeveloper 22.214.171.124
Create a Fusion Web Application with default Model and View Controller projects.
Right click on the View Controller project and Select New–> From Gallery–> Business Tier–> Web Services and select Web Service Data Control SOAP/REST
It opens Web Service Data Control creation wizard, Select REST as Web Service type and provide a meaningful name, Generic Data Control with manually described resources as the type of data control.
Click on the green plus icon to create new ADF Rest Connection, Enter connection name and URL of the web service.
Here URL of web service is http://services.groupkt.com/country/get/all and I am using http://services.groupkt.com/country/get, /all is left here as it’ll be used later. Select authentication type none and test connection.
Click on OK and you can see that REST connection is created. Click on the next button and skip OWSM policies and come to the Resources tab.
Now click on green plus icon and add /all as the resource path, select GET method checkbox and put a name for the method and set JSON as Data Format.
Click on Next button and set method payload, Select Parse from Sample Code and access web service from the browser and paste the code in Response Sample.
For this post click on this link to copy the sample response – http://services.groupkt.com/country/get/all
Click on Next and Test Rest Connection.
On the click of the finish button, a file DataControls.dcx is generated. This is a data control definition file and contains information about data collection nodes and built-in data collection operations.
Now consuming web service part is done and next is to create a page and use WSDL to show a table on that page.
Right click on the view controller and select New–> From Gallery–> Web Tier–> JSF/Facelets and create a new page
Expand Data Controls section of Fusion Web Application and you can see there a get() method and under it the message and result data collection.
Drop get() method as a button and both collections as the table on the page and run application.
Published on Java Code Geeks with permission by Ashish Awasthi, partner at our JCG program. See the original article here: Consuming JSON based REST Web Service in ADF 126.96.36.199
Opinions expressed by Java Code Geeks contributors are their own.