JDeveloper 12.2.1.4: Exposing Custom Methods from ADFbc ViewObjects to REST API

The new JDeveloper version 12.2.1.4 brought some changes to the ADF business components REST features. One of the features I wondered about is how to expose custom methods built in a view object to the REST API. The release documentation at (https://docs.oracle.com/en/middleware/developer-tools/adf/12.2.1.4/develop/whats-new-this-guide-release-12c-12.2.1.4.0.html#GUID-F0E4CCC6-5419-4FFD-B2F3-E29B40A487DB) says

What does this mean?

The REST part in the documentation still shows some pictures showing the ‘Custom Method’ tab for a REST resource

However. Searching the documentation for ‘custom method’ doesn’t show any result.

Defining a public custom method in the employee’s view and adding it to the client interface (only then methods are visible from the outside)

Looking at the same dialog in JDeveloper 12.2.1.4 does not show the ‘custom method’ tab 😦

So, is the documentation correct?

NO, a hint from @JDeveloper in a tweet gives a hint on this.

Methods are exposed by default!

But how to find them?

Well, let’s try the ‘describe’ operation on the VO using the URL ‘http://127.0.0.1:7101/BlogAdfRestMethod-RESTWebService-context-root/rest/v0/Employees/describe’. This will return plenty of information about the REST API. There we find the information about the Method ‘getVersionInfo’ which I wrote as a custom method in the EmployeesViewObjectImpl class.

To see the method in the REST API, the method must be part of the client interface. This is what the tweet means by ‘updating the metadata’, I guess.

Now, to call the method we use a POST request with the content type set to ‘application/vnd.oracle.adf.action+json’ as noted in the description of the method. The body of the POST request is set to

{
    "name" : "getVersionInfo"
}

Sending the request will give us

I added another method to the EmployeesViewObjImpl method

Named ‘sayHello’. This method I did not expose to the client interface. As we see in the description, this method is not exposed in the REST API. After exposing the method to the client interface too, we get this method in the REST API too.

Now, the description lists

So, the new method can be called via REST too

You can download the sample application from GitHub BlogAdfRestMethod. The sample was built using JDeveloper 12.2.1.4 and uses the HR DB schema.