In my previous post I showed the steps you have to take to create your first ADF REST resource. You can find it here: First steps with REST services on ADF Business Components. I will continue my exploration in the world of ADF REST.
We are now going to configure the URL and test the new service.
After you run your application, you will see the endpoint in your JDeveloper log:
The first thing you will probably notice is the structure of the URL and there is little chance you will like it. Let’s change that first. There are two parts of the URL that can be configured, the Context Root (EMP-RESTWebService-context-root) and the URL pattern (/rest/).
The Context Root can be set in the Project Properties of the RESTWebService project. Open the properties and go to the Java EE Application tab. It shows an input field for the Java EE Web Context Root and you will recognize the name from your service URL. Choose a relevant and general name. It will be used for all your services.
The URL pattern is configurable in your web.xml file. This file is part of the RESTWebService project. Open it and go to the Servlets tab. Select the only Servlet in the list and open the sub tab Servlet Mappings. Here you can choose your own URL pattern. If you don’t want any pattern, you can enter: ‘/*’.
While you configure your URL, keep in mind the full structure of the endpoint:
<IP-adress><port><ContextRoot><URL pattern><version><Resource name>
With the URL fully configured to your liking we can start testing the service.
When the application is running you can directly call your service from JDeveloper. You can press the URL that is shown in the log and the HTTP Analyzer will open. You can also open the HTTP Analyzer from the Tools menu. The HTTP Analyzer is a nice tool in JDeveloper to test web services and it will save a history of all your requests in the current session, so you can easily compare results.
When you call your service without a version or a resource name, ADF will give you a response with all available versions and their respective links. In the response you can click on the links to immediately set up a new request you can test.
As you can see in the last response, you have the option to call a describe on a version. This will show all available resources in that version. In addition you will get full information for all resources. This includes properties and data types. It will also give all available actions for the resource. To have a more concise response, it is of course also possible to call a describe on one resource.
Calling a describe request on your latest version can be a quick manual check to make sure all resources are deployed. To test if a resource is also returning data, call it directly without the describe action. The response can be checked in the HTTP Analyzer the same way. You can see your service is working correctly and returns data from the database. The same way you can test all different actions (POST, PATCH) directly in JDeveloper.
The next step will be to experiment with different kinds of querying we can do on the ADF REST service. But we will save that for a later installment.