27 Web Services Module

This chapter provides a complete listing and reference for the methods in the OpenScript WSService Class of WebService Module Application Programming Interface (API).

27.1 WSService ENUM Reference

The following section provides an alphabetical listing of the enums in the OpenScript WSService API.

27.1.1 Alphabetical Enum Listing

The following table lists the WSService Enums in alphabetical order.

Table 27-1 List of WSService Enums

Enum Description

AttachmentMechanism

Specifies the attachment Transfer type.


27.2 WSService API Reference

The following section provides an alphabetical listing of the methods in the OpenScript WSService API.

27.2.1 Alphabetical Command Listing

The following table lists the WSService API methods in alphabetical order.

Table 27-2 List of WSService Methods

Method Description

ws.addSecurityAttachments

Add Security Attachment property settings to current URL.

ws.attachment

Convenience method to create a new Attachment.

ws.attachments

Convenience method to create a new Attachment[].

ws.post

Request a web service using an HTTP POST method with requestSoap string, headers, URL encoding, and character sets.

ws.restDelete

Performs a RESTful DELETE operation.

ws.restGet

Performs a RESTful GET operation.

ws.restPatch

Performs a RESTful PATCH operation.

ws.restPost

Performs a RESTful POST operation.

ws.restPut

Performs a RESTful PUT operation.

ws.security

Convenience method to create a new WSSecurity object with a specified timeout value.

ws.solveXpath

Extract values from the browser's last retrieved contents using XPath notation.


The following sections provide detailed reference information for each method and enum in the WSService Class of WebService Module Application Programming Interface.

ws.addSecurityAttachments

Add Security Attachment property settings to current URL.

Format

The ws.addSecurityAttachments method has the following command format(s):

ws.addSecurityAttachments(url, security, attachments);

Command Parameters

url

a String specifying the URL to request.

security

a WSSecurity object specifying the security settings for the specified URL.

attachments

a WSAttachments object specifying the attachment settings for the specified URL.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Add Security Attachments with indicated property settings.

//No username token
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 null, null);
//Username, Password Text
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="), 
   true, false, false), null);
//Username, Password digest
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="), 
   false, false, false), null);
//Username, Password text, Add Created Header
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="), 
   true, true, false), null);
//Username, Password text, Add Timestamp, valid for 10 seconds
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="), 
   true, false, false, 10), null);
//Username, Password text, Add Nonce
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="), 
   true, false, true), null);
//Username, Password text, Add Created Header, 
//Add Timestamp, valid for 10 seconds, Add Nonce
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="), 
   true, true, true, 10), null);
//Username, Password text, Add Created Header, 
//Add Timestamp, valid for 10 seconds, Add Nonce
//With attachments
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="),
   true, true, true, 10), 
 ws.attachments(AttachmentMechanism.DEFAULT, 
   ws.attachment("C:\\MTOMService.xml", "attachmentPart"), 
   ws.attachment("C:\\SecureService.xml","attachmentPart")));

ws.attachment

Convenience method to create a new Attachment.

Format

The ws.attachment method has the following command format(s):

ws.attachment(filename, attachmentPart);

Command Parameters

filename

a String specifying the attachment file name.

attachmentPart

a String specifying the Attachment part.

Returns

a new Attachment

Example

Add Security with indicated attachments.

ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="),
   true, true, true, 10), 
 ws.attachments(AttachmentMechanism.DEFAULT, 
   ws.attachment("C:\\MTOMService.xml", "attachmentPart"), 
   ws.attachment("C:\\SecureService.xml","attachmentPart")));

AttachmentMechanism

The AttachmentMechanism has the following values:

Table 27-3 List of AttachmentMechanism Values

Value Description

DEFAULT

Specifies the default transfer type specified by the Content-Type header.

SWA

Specifies Security SOAP Messages with Attachments.

MTOM

Specifies SOAP Message Transmission Optimization Mechanism.

DIME

Specifies Direct Internet Message Encapsulation.


ws.attachments

Convenience method to create a new Attachment[].

Format

The ws.attachments method has the following command format(s):

ws.attachments(am, attachments);

Command Parameters

am

an AttachmentMechanism enum specifying the attachment transfer type.

attachments

the Attachment objects.

Returns

a new WSAttachments

Example

Add Security with indicated attachments.

ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="),
   true, true, true, 10), 
 ws.attachments(AttachmentMechanism.DEFAULT, 
   ws.attachment("C:\\MTOMService.xml", "attachmentPart"), 
   ws.attachment("C:\\SecureService.xml","attachmentPart")));

ws.post

Request a web service using an HTTP POST method with requestSoap string, headers, URL encoding, and character sets.

Format

The ws.post method has the following command format(s):

ws.post(recid, url, requestSoap, headers, bEncode, reqCharset, respCharset);

Command Parameters

recid

ID of a previously recorded navigation, used for comparison purposes. May be null.

url

URL to request

requestSoap

A string representation of SOAP contents

headers

a Header array specifying the Additional headers to add/remove from the request before submitting it to the server.

bEncode

a boolean specifying the parameter encoding. Set to true to URL-encode the parameters before submitting them to the sever.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

Throws

Exception

if an error occurs Posting to the server.

Example

Specifies a POST navigation with requestSoap string, headers, URL encoding, and character sets.

//Example UI added Post 
ws.post(7, "http://myserver/EmployeeLookup.asmx", 
 "requestSoap string", 
 http.headers(http.header("name1", "value1", Header.HeaderAction.Add), 
  http.header("name2", "value2", Header.HeaderAction.SetIfNotSet), 
  http.header("name3", "value3", Header.HeaderAction.GlobalAdd), 
  http.header("name4", "value4", Header.HeaderAction.GlobalSetIfNotSet)), 
 true, "ASCII", "ASCII");
//Example WSDL Manager added Post with requestSoap string
ws.post(8,"http://myserver/EmployeeLookup.asmx",
 "<soapenv:Envelope " +
  "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
  "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
  "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
  "xmlns:web=\"http://mysite.com/webservices\">\r\n " +
  "<soapenv:Header/>\r\n " +
  "<soapenv:Body>\r\n " +
   "<web:addEmployee " +
     "soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n " +
    "<data xsi:type=\"enc:Employee\" " +
      "xmlns:enc=\"http://mysite.com/webservices/encodedTypes\">\r\n " +
     "<FirstName xsi:type=\"xsd:string\">string</FirstName>\r\n " +
     "<LastName xsi:type=\"xsd:string\">string</LastName>\r\n " +
     "<EmployeeID xsi:type=\"xsd:int\">0</EmployeeID>\r\n " +
     "<Address xsi:type=\"xsd:string\">string</Address>\r\n " +
     "<City xsi:type=\"xsd:string\">string</City>\r\n " +
     "<State xsi:type=\"xsd:string\">string</State>\r\n " +
     "<Zip xsi:type=\"xsd:string\">string</Zip>\r\n " +
     "<Phone xsi:type=\"xsd:int\">0</Phone>\r\n " +
    "</data>\r\n " +
   "</web:addEmployee>\r\n " +
  "</soapenv:Body>\r\n " +
 "</soapenv:Envelope>",
 http.headers(http.header("Content-Type","text/xml;charset=UTF-8",
   Header.HeaderAction.Modify),
  http.header("SOAPAction","\"http://mysite.com/webservices/addEmployee\"", 
   Header.HeaderAction.Modify)),
  true, null, null);

ws.restDelete

Performs a RESTful DELETE operation.

Format

The ws.restDelete method has the following command format(s):

ws.restDelete(recid, url, deleteData, headers, bEncode, reqCharset, respCharset);

Command Parameters

recid

ID of a previously recorded navigation, used for comparison purposes.

url

a String specifying the URL for the request to the server.

deleteData

a String specifying the data to DELETE.

headers

a Header[] object specifying the header data.

bEncode

a boolean specifying if the data is encoded.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

Throws

Exception

on any error.

Example

Performs a RESTful DELETE operation.

ws.restDelete(4, "http://example.com:8151/ouaf/mobility/rest/ouaf/M1-ShfLogon/" 
 "", http.headers(http.header("x-authorization","U1BMTlhBOlNQTE5YQTAx",
  Header.HeaderAction.Modify)),  
 true, "ASCII", "ASCII");

ws.restGet

Performs a RESTful GET operation.

Format

The ws.restGet method has the following command format(s):

ws.restGet(recid, url, headers, bEncode, reqCharset, respCharset);

Command Parameters

recid

ID of a previously recorded navigation, used for comparison purposes.

url

a String specifying the URL for the request to the server.

headers

a Header[] object specifying the header data.

bEncode

a boolean specifying if the data is encoded.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

Throws

Exception

on any error.

Example

Performs a RESTful GET operation.

ws.restGet(4, "http://example.com:7002/IMCMCSREST/rest/v1/describeUsername", 
 "{\"testdata\":\"test\"}", 
 http.headers(http.header("Authorization","Basic YWRtaW46d2VxY29tZTE=",
  Header.HeaderAction.Modify)),  
 true, "ASCII", "ASCII");

ws.restPatch

Performs a RESTful PATCH operation.

Format

The ws.restPatch method has the following command format(s):

ws.restPatch(recid, url, patchData, headers, bEncode, reqCharset, respCharset);

Command Parameters

recid

ID of a previously recorded navigation, used for comparison purposes.

url

a String specifying the URL for the request to the server.

patchData

a String specifying the data to PATCH to the URL's host.

headers

a Header[] object specifying the header data.

bEncode

a boolean specifying if the data is encoded.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

Throws

Exception

on any error.

Example

Performs a RESTful PUT operation.

ws.restPatch(4, "http://example.com:8151/ouaf/mobility/rest/ouaf/M1-ShfLogon/", 
 "", http.headers(http.header("x-authorization","U1BMTlhBOlNQTE5YQTAx",
  Header.HeaderAction.Modify)),  
 true, "ASCII", "ASCII");

ws.restPost

Performs a RESTful POST operation.

Format

The ws.restPost method has the following command format(s):

ws.restPost(recid, url, postData, headers, bEncode, reqCharset, respCharset);

Command Parameters

recid

ID of a previously recorded navigation, used for comparison purposes.

url

a String specifying the URL for the request to the server.

postData

a String specifying the data to POST to the URL's host.

headers

a Header[] object specifying the header data.

bEncode

a boolean specifying if the data is encoded.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

Throws

Exception

on any error.

Example

Performs a RESTful POST operation.

ws.restPost(4, "http://example.com:7002/IMCMCSREST/rest/v1/describeUsername", 
 "{\"testdata\":\"test\"}", 
 http.headers(http.header("Authorization","Basic YWRtaW46d2VxY29tZTE=",
  Header.HeaderAction.Modify)),  
 true, "ASCII", "ASCII");

ws.restPut

Performs a RESTful PUT operation.

Format

The ws.restPut method has the following command format(s):

ws.restPut(recid, url, putData, headers, bEncode, reqCharset, respCharset);

Command Parameters

recid

ID of a previously recorded navigation, used for comparison purposes.

url

a String specifying the URL for the request to the server.

putData

a String specifying the data to PUT to the URL's host.

headers

a Header[] object specifying the header data.

bEncode

a boolean specifying if the data is encoded.

reqCharset

a String specifying the character set to use if URL-encoding any of the request parameters.

respCharset

a String specifying the character set to use when reading the response contents.

Throws

Exception

on any error.

Example

Performs a RESTful PUT operation.

ws.restPut(4, "http://example.com:8151/ouaf/mobility/rest/ouaf/M1-ShfLogon/" 
 "", http.headers(http.header("x-authorization","U1BMTlhBOlNQTE5YQTAx",
  Header.HeaderAction.Modify)),  
 true, "ASCII", "ASCII");

ws.security

Convenience method to create a new WSSecurity object with a specified timeout value.

Format

The ws.security method has the following command format(s):

ws.security(username, password, plaintextPassword, addCreatedHeader, addNonce);

ws.security(username, password, plaintextPassword, addCreatedHeader, addNonce, timeToLive);

Command Parameters

username

a String specifying the username.

password

a String specifying the password.

plaintextPassword

a boolean specifying the password type. true for Password Text, false for Password Digest.

addCreatedHeader

a boolean specifying if a created header is added.

addNonce

a boolean specifying if Nonce is added.

timeToLive

a value specifying the timeout.

Returns

a new WSSecurity object.

Example

Add Security with indicated property settings.

//Username, Password Text
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="), 
   true, false, false), null);
//Username, Password digest
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="), 
   false, false, false), null);
//Username, Password text, Add Created Header
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="), 
   true, true, false), null);
//Username, Password text, Add Timestamp, valid for 10 seconds
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="), 
   true, false, false, 10), null);
//Username, Password text, Add Nonce
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="), 
   true, false, true), null);
//Username, Password text, Add Created Header, 
//Add Timestamp, valid for 10 seconds, Add Nonce
ws.addSecurityAttachments("http://myserver/EmployeeLookup.asmx", 
 ws.security("username", decrypt("sO7ijipCONXoxAURd+8BQw=="), 
   true, true, true, 10), null);

ws.solveXpath

Extract values from the browser's last retrieved contents using XPath notation.

The value will be stored to the given variable.

Format

The ws.solveXpath method has the following command format(s):

ws.solveXpath(varName, xpath, resultIndex);

Command Parameters

varName

a String specifying the variable name where the value will be stored. Must not be null.

xpath

a String specifying the XPath describing which value to parse from the last retrieved contents. Must not be null.

resultIndex

an index value specifying the 0-based index of the specific result to retrieve if the XPath returns multiple results. A null value specifies that all results should be returned.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

SolveException

if the XPath cannot be solved.

XMLServiceException

if happens error when parsing the xpath.

Example

Verifies the Xpath set to the script variable "solvedXPath" can vbe solved.

http.get(13, "http://example.com/stocks/", null,
 null, true, "ASCII", "ASCII");
ws.solveXpath("solvedXPath", ".//FORM[@name='loginform']/@action", 0);
if (getVariables().get("solvedXPath").equals("default.asp"))
 info ("method \"solveXpath()\" is passed.");
else
 warn ("method \"solveXpath()\" is failed.");