How to use the SOAPInterceptor to see the SOAP Header and Body
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
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.
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);
1
2
3
4
5
6
7
8
9
10
11
12
13
varinterceptor=newSOAPInterceptor();
interceptor.setRequestHeaderInterceptor(requestHeaderHandler);
interceptor.setRequestBodyInterceptor(requestBodyHandler);
varresponse=operation.invokeWithInterceptor(request, interceptor);
functionrequestHeaderHandler(content) {
System.log("This is the request header: '"+content+"'");
// process & return your header here
}
functionrequestBodyHandler(content) {
System.log("This is the request body: '"+content+"'");
// process & return your header here
}
varresponse=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
Finally, the actual operation is run and the logging continues…
1
2
3
4
5
6
7
[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:
...
...
Burke has been a technology professional since 1996 and has held certifications from the CNCF, Cisco, Citrix, ITIL, Linux Professional Institute, Microsoft, Novell, and VMware. He joined VMware in 2007 as part of the acquisition of Dunes Technologies from Lausanne, Switzerland where he had begun his work with Orchestrator. Burke is founder and contributor of the vCOTeam.info blog as well as a leading contributor to the VMTN Communities for Orchestrator. He has been recognized by the community as a vExpert since 2010. During his tenure at VMware, Burke co-created the Orchestrator Masters Training program, has trained hundreds of employees on Orchestrator, built many integrations for customers and partners, and has worked various roles in the VMworld Hands On Labs. He has also been a member, and technical lead, of the SDDC Livefire program, building content, labs, and vPods for the program. Publications include contributing author for ‘VMware vCloud Architecture Toolkit (vCAT)’ (VMware Press 2013) and technical resource for ‘VMware vRealize Orchestrator Cookbook - Second Edition’, ‘VMware vRealize Orchestrator Cookbook, and VMware vRealize Orchestrator Essentials (Packt Publishing 2015), Automating vSphere with VMware vCenter Orchestrator (VMware Press 2012), and VMware vSphere for Dummies (For Dummies 2011).