"Debug" Services on Offline Process Servers (in IBM BPM using Javascript)
The scenario that prompted this approach was that I was trying to reproduce a performance issue with verbose tracing enabled but the traces had such an impact on the system I couldn't generate the necessary load. I needed a focused way to generate load on a particular Service and I didn't want to have to jump through all the hoops necessary to get a Test Harness deployed to the Performance Test Environment.
A more common scenario might be that you're struggling to diagnose what seems to be an environment-specific issue (on an off-line Process Server) and you want to get some visibility into what a specific Service is returning.
Anyway, if you follow these instructions you can call a Service using client-side Javascript...

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
callService = function(service, params, logDetail, snapshot) { | |
var url = "/portal/jsp/callService.do?serviceName=" + service + "&snapshotId=" + snapshot; | |
callServiceImpl(url, params, logDetail); | |
}; | |
function callServiceImpl(url, params, logDetail) { | |
var parameters = "input=" + encodeURIComponent(params); | |
var http_request = null; | |
if (window.XMLHttpRequest) { // Mozilla, Safari,... | |
http_request = new XMLHttpRequest(); | |
if (http_request.overrideMimeType) { | |
http_request.overrideMimeType('text/xml'); | |
} | |
} else if (window.ActiveXObject) { // IE | |
try { | |
http_request = new ActiveXObject("Msxml2.XMLHTTP"); | |
} catch (e) { | |
try { | |
http_request = new ActiveXObject("Microsoft.XMLHTTP"); | |
} catch (e) {} | |
} | |
} | |
if (!http_request) { | |
console.log("Cannot create XMLHTTP instance"); | |
return false; | |
} | |
http_request.onreadystatechange = function() { | |
if (http_request.readyState == 4) { | |
if (http_request.status == 200) { | |
var ret = new Object(); | |
var result = http_request.responseXML.getElementsByTagName("output"); | |
if (window.XMLHttpRequest && window.ActiveXObject) { // necessary for IE7 | |
http_request.responseXML.load(http_request.responseBody); | |
result = http_request.responseXML.getElementsByTagName("output"); | |
} | |
console.log("Service Returned (" + logDetail + ")"); | |
console.log(http_request.responseXML); | |
} else { | |
console.log("Error!"); | |
} | |
} | |
}; | |
http_request.open('POST', url, true); | |
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
http_request.send(parameters); | |
} | |
var serviceName = "Test Service 01"; | |
var serviceInput = "<inputs><variable name ='input'>Test</variable></inputs>"; | |
var snapshotId = "2064.02f083a3-c80e-4147-aa36-afb04fe8c21c"; | |
for (var loop = 0; loop < 2; ++loop) { | |
callService(serviceName, serviceInput, loop, snapshotId); | |
} |
The bulk of the Javascript is a (only slightly) modified copy of an out-the-box function and the last few lines are the ones that specify what Service to call and which Parameters to pass. You'll need to adapt this to suit your requirements...
UPDATE: This "feature" (more of a security flaw really) has been disabled as of Fix Pack 2 for v7.5. It generates a helpful log entry to tell you that you can't call non-Ajax Services via Ajax. I expect it doesn't work in newer (i.e. v8.x) versions either.