Create ADF REST Services

This article provides a step-by-step guide for the beginners to create their first Rest Web Service using Oracle ADF as well as operate the resources.

Create an ADF REST Web Application

File - New - Application, choose ADF REST Web Application.

Step 1 - Give the application name.

Step 2 - We can see the release name and internal name are created automatically.

Step 3 - Choose ADF Business Components Rest Services.

Step 4 - Click Finish.

After that, we can see the application is created with RESTModel and RESTWebService included.

Create Business Components from Tables

Right click on RESTModel project  - New - choose Business Components from Tables.

Click on + to add a connection.

Give the connection name, username/password, hostname, port and SID.

Click OK to finish connecting to DB.

Input the table name (resource) you want to use in Name Filter field and click Query. The table will show in Available area. 

Step 1 - Create Entity Object

Shuttle the table right side to create an Entity Object. You can change the Entity name to make it more understandable.

Step 2 - Create Entity-based VO

Shuttle the EO to the right side to create an Entity-based VO.

Step 3 - Create Query-based VO

You can create EO-based VO or query-based VO according to your application requirements.

In this sample case, we just create both of the VOs.

Step 4 - Skipped.

Step 5 - Shuttle the VO you want to use to the right side.

Step 6 - We can see the attributes in the VO (corresponding to the columns in the table).

Step 7 - Finish. 

Create Rest Webservice

Double click on AppModule, it will open AppModule.xml file.

Navigate to Web Service tab - REST, we can see the two web services have been created.

Click on + to create another rest resource, give the resource name and choose on View instance. Click OK.

Back to AppModule.xml and click the web service created just now. We can see the information about application module, VO, resource name, available operations etc.

Run the Web Service Project

Right click on RESTWebService project and click Run.

It will automatically deploy the application to integrated WebLogic server. Once completed, the target URL will be provided, through which we can access the resources.

Click on the target URL and one new tab will open. Click on Send Request we will see the response in JSON format.

We should add /<version>/<resource name> to the URL to get the resources.

For example http://127.0.0.1:7101/Lib-RESTWebService-context-root/rest/v0/books.

Basic Operations

Here we use Advanced Rest Client to sent Restful request to test the rest web service.

Advanced Rest Client is a strong Chrome plugin for API testing. No complicated forms and scripts. Easy to use yet very powerful. It is the only REST client that makes connection directly on socket giving you full control over the connection and request/response headers.

We can install Advanced Rest Client from Chrome, and once completed, we can launch this app from chrome://apps/.

QuickStart:

We can choose the method GET/POST/ etc from method drop-down list. Provide the request URL and click SEND. The response will show as below.


GET - Select

We can add the ID and get the specific resource we want.

Once successful, the response status will be 200 OK.

POST - Insert

Note: we should add the headers as below:

content-type: application/vnd.oracle.adf.resourceitem+json

Then provide the record to be inserted to DB in Body area.

Once successful, the response status will be 201 created.

PUT - Update

In this case, we update the ID from 9 to 8 of the record created just now.

DELETE - Delete

In this case, we delete the record with ID equals to 8.

Once successful, the response status will be 204 No Content.

猜你喜欢

转载自blog.csdn.net/bettyHHUC/article/details/89884410