LUTION GmbH
Alfred-Escher-Strasse 11, 8002 Zürich | +41 44 461 16 15
This article is about to show how powerful and efficient SOAP webservices can be designed within HPSM (HP Service Manager). The same is possible via REST webservices as well but REST webservices will be tackled in a future article.
Author:
Alan Gross
CEO & Senior Consultant at LUTION
We would like to offer the following data via webservices to a external application:
It's quite easy to setup a webservice within HP ServiceManager for specific tables. It's just about to create a so called "External Access (extaccess) record for the corresponding dbdict.
After defining the extaccess record a WSDL is automatically generated by HPSM and it will automatically support to retrieve either single records or list of records from the corresponding table. It's furthermore easy to specify which fields shall be exposed as XML attributes and how those fields shall be labeld.
It's also simple to specify custom actions such as "add", "update", "close". Each action will become a webservice within the WSDL. HPSM will identify the logic to be executed by scanning the so called State record for the corresponding action name and execute the related Process record.
When planning a webservice interface the counterparts normally start first to define the "contracts".
The goal should be to design the webservices as efficient as possible and limit the number of webservice calls required. Each webservice request and response means overhead and takes time to be processed. Therefore a webservice should whenever possible and meaningful return all the data required by the consumer in one webservice request. Sounds normal since XML is powerful and can hold more ore less any data structure.
The problem is that HP ServiceManager is not having a relational data base. Each webservice is dependent on one table and can therefore only expose the fields of the corresponding table.
Looking at the use case it would mean to setup multiple webservices as follows:
The developer responsible to code the webservice consumer part will be probably having questions and stating: Can't we define one webservice for that? I always need all the data anyways and I don't understand why we can't include all information at once? Maybe he would propose a XML structure as follows:
It's indeed possible to achieve this in HPSM. Find below an example solution.
1. Define a dbdict e.g. xxWsGetUserData
2. Create a extaction record as follows
3. Create a extaccess record for the dbdict xxWsGetUserData
4. Create the Dispatcher JavaScript Library "xxWsDispatcher"
This script library is containing 2 functions.
The function "doAction" is the function which is invoked by the extaction.
Within this "doAction" function I check which webservice and action has been requested and depending on the action another JS function is invoked processing the webservice request (in this case "getUserData()" which is the second function in the library).
The way I designed it, the dispatcher could be used for many different webservices (maybe a suite of webservices). Based on Webservice & Action the dispatcher is redirecting to corresponding java script functions.
The example code below is populating the webservice response with some hard coded values.
It's only about to illustrate that we could now select any data from any table in HPSM and use this data to populate any attribute within the webservice response.
Further more it's possible to validate any attribute populated within the webservice request and react upon missing attributes or attributes containing invalid values with custom error messages.
vars.$L_exit="normal";
function doAction() {
var objName = vars.$L_object;
var actionName = vars.$L_extaccess_file.action_names[vars.$L_2lower_index - 1];
var wsAction=actionName +"-"+ objName;
switch (wsAction) {
case "Get-UserData":
getUserData();
break;
default:
print("webservice action was not found");
vars.$L_exit="badval";
}
}
function getUserData(){
if (vars.$L_file.paramUserId==null){
vars.$L_exit="badval";
print("Error - Parameter \"paramUserId\" is mandatory.");
return;
}
// Here all the data would need to be selected based on user id passed in (paramUserId)
// To simplify I hardcode the reponse
vars.$L_file.userId="john.smith";
vars.$L_file.userName="John Smith";
vars.$L_file.userPhone="555-123-123";
vars.$L_file.userEmail="john.smith@somedomain.com";
vars.$L_file.lastLoginHpsm=system.functions.tod();
vars.$L_file.userComputers[0].computerName="pcJohnSmit01";
vars.$L_file.userComputers[0].operatingSystem="Windows 7";
vars.$L_file.userComputers[0].bitRate="32 bit";
vars.$L_file.userComputers[1].computerName="pcJohnSmit02";
vars.$L_file.userComputers[1].operatingSystem="Windows 8";
vars.$L_file.userComputers[1].bitRate="64 bit";
vars.$L_file.userGroups[0].groupName="group01";
vars.$L_file.userGroups[0].groupManager="max.manager";
vars.$L_file.userGroups[0].groupManagerDeputy="peter.deputy";
vars.$L_file.userGroups[1].groupName="group02";
vars.$L_file.userGroups[1].groupManager="thomas.boss";
vars.$L_file.userGroups[1].groupManagerDeputy="rudi.blabla";
vars.$L_file.userGroups[2].groupName="group03";
vars.$L_file.userGroups[2].groupManager="chris.chef";
vars.$L_file.userGroups[2].groupManagerDeputy="somone.else";
}
Example with missing parameter (validation failed response):
Example with Success response:
Write a comment
Jani Whitsett (Thursday, 02 February 2017 07:10)
It's awesome in favor of me to have a website, which is helpful for my knowledge. thanks admin
Providencia Dahle (Saturday, 04 February 2017 20:09)
I've been exploring for a bit for any high-quality articles or blog posts on this kind of area . Exploring in Yahoo I ultimately stumbled upon this web site. Reading this information So i am glad to express that I have an incredibly good uncanny feeling I found out just what I needed. I so much certainly will make certain to do not disregard this site and provides it a glance regularly.
Madhuri (Tuesday, 22 August 2017 19:25)
So much informative blog. I have a question on the response, Can the web service response be customized? I wanted to know if there is a possibility to restrict few fields in the response XML and send only limited fields. Can this be done?