Hi All
I spent the last week working on a method to submit SOAP envelopes to TEWS using RHINO
My use case was very simple:
- Using a kettle script, obtain all failed events from the CAIM TP (task finished with status 2),
- Write the task session to a staging table.
- Try to resubmit the task using VST TEWS call
Now, although there is a built in http post component in kettle, it doesn’t work where SM is protecting the TEWS interface
And yes I could have used Java but what is the fun with that
The attach RHINO code can, with some adaptation, can be used in CAIM screens as well
Please let me know if you have more questions
// Tews Client using RHINO in Kettle Script
// Itamar Budin - itamar.budin@ca.com
// 2015 CA Technologies
// Note: Tested in Kettle 5.3.0 only!!!!
/* Part 1: Create SOAP XML message - In this Example resubmit task
Sample XML Message:
<xml version="1.0" encoding="utf-8">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://tews6/wsdl">
<soapenv:Header/>
<soapenv:Body>
<wsdl:ViewSubmittedTasksQuery>
<wsdl:ViewSubmittedTasksSubmittedTasksTab>
<wsdl:TaskDetails>
<wsdl:TaskId>19213a34-030d4c79-f1a99481-1a0118</wsdl:TaskId>
<wsdl:ResubmitTask>true</wsdl:ResubmitTask>
</wsdl:TaskDetails>
</wsdl:ViewSubmittedTasksSubmittedTasksTab>
</wsdl:ViewSubmittedTasksQuery>
</soapenv:Body>
</soapenv:Envelope>*/
var SOAPMsg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope' xmlns:wsdl='http://tews6/wsdl'>" +
"<soapenv:Header/>" +
"<soapenv:Body>" +
"<wsdl:ViewSubmittedTasksQuery>" +
"<wsdl:ViewSubmittedTasksSubmittedTasksTab>" +
"<wsdl:TaskDetails>" +
"<wsdl:TaskId>" + TASKSESSIONID + "</wsdl:TaskId>" + // TASKSESSIONID is a variable retrieved from the CAIM object Store
"<wsdl:ResubmitTask>true</wsdl:ResubmitTask>" +
"</wsdl:TaskDetails>" +
"</wsdl:ViewSubmittedTasksSubmittedTasksTab>" +
"</wsdl:ViewSubmittedTasksQuery>" +
"</soapenv:Body>" +
"</soapenv:Envelope>";
// Part 2: Authentication Variables Declaration
// Note 1: We use literal java.lang.string() to create attributes to avoid conversion issues
// Note 2: This example was used on an environment where SM is protecting the TEWS interface
var message = new java.lang.String(); // Will hold the user and password for basic authentication
message = "<username:password>";
var bytes = [];
for (var i=0;i<message.length;++i) // Converting the message sting to byte using string array (no Byte data element in Rhino)
{
bytes.push(message.charCodeAt(i));
}
var base64 = new org.apache.commons.codec.binary.Base64();
var encoding = base64.encodeAsString(bytes); // Encoding the username and password to base64 (Basic authentication requirement)
var cookie = new java.lang.String(); // Will hold the cookie value to make SM challenge the connection to avoid 401/403 erros
cookie = "SMCHALLENGE=YES";
// Part 3: establishing connection
var url = new java.net.URL("<TEWS Address"); // Enter the TEWS URL without the ?WSDL
var connection = java.net.URLConnection(url.openConnection()); //Open Connection
connection.setAllowUserInteraction(false);
connection.setRequestProperty("Cookie", cookie); // Adding the cookie
connection.setRequestProperty("Authorization", "Basic " + encoding); // Set authentication method to basic and passing the base64 encoded username and password
connection.setRequestProperty("Cache-Control", "no-cache"); // No cache
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type","application/soap+xml; charset=utf-8");
// Part 4: Passing the SOAP XML envelope
var out = new java.io.OutputStreamWriter(connection.getOutputStream());
out.write(SOAPMsg); // Submit
out.flush();
var returnCode = connection.getResponseCode(); // Get Return Code from the call
// Part 5: Read input stream from the call
var br = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
var response = "";
var line = br.readLine();
while(line != null){
response = response + line;
line = br.readLine();
}
// Part 6: Close the connection
out.close();