On a recent project, I was having trouble figuring out why invoking a SOAP operation kept failing with the vCO SOAP plug-in. The inputs I was providing appeared to be correct and worked just fine with soapUI. This short tutorial will teach you how to use the SOAPInterceptor to display the Header and Body that the SOAP plug-in is sending.

SOAP Operation Auto-Generated Workflow

SOAP_Operation_Auto-Generated_Workflow.png

A typical Invoke Operation workflow looks similar to the above image. This is an example of the workflow generated when you right-click an Operation from the vCO SOAP Inventory and choose the option to Generate workflow.

Default Scripting Code

The auto-generated code looks a lot like this:

 var host = Server.findForType("SOAP:Host", "e88fcfb7-f4ca-4c55-bd6e-c03b4ba4a188");
 if (host == null) throw "Host 'e88fcfb7-f4ca-4c55-bd6e-c03b4ba4a188' not found!";
var operation = host.getOperation("executeWorkflow");
 if (operation == null) throw "Operation 'executeWorkflow' not found!";
System.log("creating request...");
 var request = operation.createSOAPRequest();
request.setInParameter("workflowId", workflowId);
 request.setInParameter("username", username);
 request.setInParameter("password", password);
 request.setInParameter("workflowInputs[0].name", workflowInputs_OB_0_CB__D_name);
 request.setInParameter("workflowInputs[0].type", workflowInputs_OB_0_CB__D_type);
 request.setInParameter("workflowInputs[0].value", workflowInputs_OB_0_CB__D_value);
System.log("invoking '" + operation.name + "' operation...");
var response = operation.invoke(request);
System.log("operation '" + operation.name + "' successfully invoked.");
System.log("processing response...");
 var result = new Properties();
System.log("out headers...");
 outHeaders = System.getModule("com.vmware.library.soap").processOutHeaders(response);
System.log("out parameters...");
 outParameters = System.getModule("com.vmware.library.soap").processOutParameters(response);

As you can see in the code above, the operation has 6 input parameters that get set (Lines 7-12), no special headers, and then the operation is invoked using the .invoke method of the operation object on Line 14.

Update Script for Interceptor

Comment out the line that says:

var response = operation.invoke(request);

And place this code immediately above it:

 var interceptor = new SOAPInterceptor();    
 interceptor.setRequestHeaderInterceptor(requestHeaderHandler);    
 interceptor.setRequestBodyInterceptor(requestBodyHandler);    
 var response = operation.invokeWithInterceptor(request, interceptor);  
 function requestHeaderHandler(content) {    
 System.log("This is the request header: '" + content + "'");    
 // process & return your header here  
 }
function requestBodyHandler(content) {    
 System.log("This is the request body: '" + content + "'");    
 // process & return your header here  
 }
var response = operation.invokeWithInterceptor(request,interceptor);

•    In line 1, we instantiate a SOAPInterceptor object.
•    Then we assign javascript functions as request Handlers that will perform a System.log for the Header and Body in lines 2 and 3.
•    Next Lines 5-12 define the two functions that will be used to handle the content of the Header and Body respectively
•    Finally, we use the .invokeWithInterceptor method, passing in the request object and the newly created SOAPInterceptor object.

The Result

Run your workflow using the vCO Client and check the results of the "Logs" tab
Your results will start off with something like:

[2013-10-07 11:45:33.316] [I] creating request...
[2013-10-07 11:45:33.318] [I] invoking 'executeWorkflow' operation...

Next, the SOAP Interceptor kicks in and processes the Header and Body, displaying their raw content in the log:

<axis2ns5:executeWorkflow xmlns:axis2ns5="http://webservice.vso.dunes.ch">
    <impl:workflowId xmlns:impl="http://webservice.vso.dunes.ch">8bb0eb0c-6724-4fd7-a2fd-77a5408b9c94</impl:workflowId>
    <impl:username xmlns:impl="http://webservice.vso.dunes.ch">joeUser</impl:username>
    <impl:password xmlns:impl="http://webservice.vso.dunes.ch">mySpecialPassword</impl:password>
    <impl:workflowInputs xmlns:impl="http://webservice.vso.dunes.ch">
        <impl:name>host</impl:name>
        <impl:type>VC:HostSystem</impl:type>
        <impl:value>dunes://service.dunes.ch/CustomSDKObject?id='vc55.vcoteam.lab/host-9'&dunesName='VC:HostSystem'</impl:value>
    </impl:workflowInputs>
</axis2ns5:executeWorkflow>

Finally, the actual operation is run and the logging continues...

2013-10-07 11:45:35.516] [I] operation 'executeWorkflow' successfully invoked.
[2013-10-07 11:45:35.516] [I] processing response...
[2013-10-07 11:45:35.516] [I] out headers...
[2013-10-07 11:45:35.529] [I] out parameters...
[2013-10-07 11:45:35.543] [I] out parameters available:
...
...
...