The article “Quickly creating, deploying and testing a WebService interface for ADF Business Components” (http://technology.amis.nl/blog/9726/quickly-creating-reploying-and-testing-a-webservice-interface-for-adf-business-components) that I recently published describes a way of very rapidly creating the HRService Web Service – an ADF BC driven WebService on top of the EmployeesView ViewObject that exposes the EMPLOYEES table in the HR schema through the Employee EntityObject. However, that article’s true purpose is to show how to create the deployment profile and deploy and test this service, either on the integrated WLS or on a standalone WebLogic Server, in the easiest way possible. This article is an extension of the previous one: it demonstrates how to extend the Service Interface with a custom method (or an operation in terms of WebServices).
As it happens, I required an operation for updating just the salary of an Employee. I will show how I create a custom method in the Application Module’s implementation class, how I added this method to the Client Interface of the Application Module and subsequently to the Service Interface. After redeploying – using the same deployment profile that was created previously – we can test the updateSalary method as a new operation in the WebService.
Open the Application Module editor. Go to the Java tab and click on the edit (pencil) icon. Check the checkbox to Generate Application Module Class HRServiceImpl.
Then press OK.
Click on the hyperlink for HRServiceImpl. The java editor opens for class HRServiceImpl.
Implement method updateSalary. The method takes two integers – the employee identifier and the newly awarded salary – and returns a String as result.
The code will first leverage the EmployeesView1 ViewObject to get hold of the employee’s Row for the employeeId (the primary key for this ViewObject). When found, the Salary attribute is updated, and the result string is composed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public String updateSalary(Integer employeeId, Integer newSalary) {
String result="";
Row[] rows =
getEmployeesView1().findByKey(new Key(new Object[] { employeeId }),
1);
if (rows != null && rows.length > 0) {
Row row = rows[0];
row.setAttribute("Salary", newSalary);
result =
"Updated Salary for " + row.getAttribute("FirstName") +
" " + row.getAttribute("LastName") + " to " +
newSalary;
}
return result;
}
|
With the method now available in the ApplicationModuleImpl class, we can add it to the Client Interface.
Back in the Java tab for the Application Module, click on the edit (pencil) icon to edit the Client Interface:L
In the Client Interface editor, select the new method updateSalary to add to the Client Interface.
Click on OK.
With the Client Interface appropriately extended, we can now edit the Service Interface likewise.
Go to the Service Interface tab for the Application Module. Click on the icon to edit the Custom Methods for the Service interface.
Select the updateSalary method. Then press OK.
The definition of the Service Interface for Application Module HRService is now extended with the updateSalary salary, that will be exposed as Operation updateSalary in the Web Service.
Redeploy the application using the application deployment profile discussed in the prequel to this article.
Then open your browser to test the web service, in my case at: http://localhost:8001/HRDataServices/HRService.
Select operation updateSalary that is now available for the first time. Specify employee identifier and new salary. Then press the Invoke button.
The response from the WebService appears:
When we check the database, we will find that the salary has indeed been updated:
Through Custom Methods, it becomes very easy to provide dedicated, fine grained operations (or composite, very coarse grained operations) Â in the WebServices published for our Application Modules.