1) Run the attached service in integrated weblogic server. Copy the WADL URL.
3) To invoke the operations of the service, start off by creating a HTML page. Let’s call the html page as EmployeePage.html.
4) To use the variables and functions defined in client.js, we need to include it in our HTML page. client.js in turn uses jquery.min.js. Thus, we need to include it as well in our HTML file. Without jquery.min.js, you will end up with the error ‘$ is not defined’ at runtime.
5) To design the HTML page, add a button with an onClick event attached to it. A snippet of the auto-generated client.js file as well as the initial HTML page is shown below. The page also includes the skeletal structure of a table, which we will use to render the data returned from the service.
Snippet of client.js:
Initial HTML Structure:
6) We then create the invokeGETOperation() function within the script tags as shown.
7) That’s it! Run the page.
NOTE: In the browser, change the URL from 127.0.0.1 to localhost. Otherwise, the request will not go through (you may need to use Access-Control-Allow-Origin header when hostnames of service and client are different).
For PUT operation:
Code snippet to invoke Put operation:
//Create new JSON data and populate it with new user data
var newJsonData = new Object();
newJsonData.id = eId; // eId is taken from input text box using document.getElementById("empId").value;
newJsonData.name = ename;
var myJsonObj = EmpClientClient.EmpClient().Project1().putJson(newJsonData); //passing the employee JSON object to the put operation
For Search (GET) operation:
Code snippet to invoke Search operation (Uses PathParam and QueryParam):
var myJsonObj = EmpClientClient.EmpClient().Project1().SearchEmpId(eId).getAsJson(ename);