Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
Hi,
I want to call external web service from integrity trigger. I could't find any documentation on site for doing this through trigger.
My team have used integrity web-services API but while creating in report. in report recipe, but I want to call external web-services in trigger.
Is it possible ? How can I do that?
Thanks,
Solved! Go to Solution.
It's actually relatively easy to do from a trigger. I use a generic function that makes the SOAP calls for me and accepts the URL to post to, as well as a string that holds the XML to send. Once the call is complete, the return XML is passed back to the caller.
To generate the SOAP call (the body), I simply use SOAPUI to connect to the web service and generate a template XML stream. I then paste that into the trigger script as text, and reformat it so that it's a string. Along the way, inser the text from the item that fired the trigger (which I'm assuming you would want), and the call the function to post it.
Here's the function that I use to POST the request:
function PostSOAPRequest(strURL, strBody) { var result = new java.lang.String(""); var client = new Packages.org.apache.commons.httpclient.HttpClient(); var hostConfig = client.getHostConfiguration(); hostConfig.setHost(new Packages.org.apache.commons.httpclient.URI(strURL)); var objPost = new Packages.org.apache.commons.httpclient.methods.PostMethod(strURL); objPost.setRequestHeader("Content-type", "text/xml; charset=utf-8"); objPost.setRequestHeader("Content-Length", ""+strBody.length()); objPost.setRequestBody(strBody); if (gvTrace) Log("Posting SOAP request to " + strURL); var responseCode = client.executeMethod(objPost); var inputStream = objPost.getResponseBodyAsStream(); var bufReader = new java.io.BufferedReader(new java.io.InputStreamReader(inputStream)); var line = new java.lang.String(""); while (null != (line=bufReader.readLine())) result += line; objPost.releaseConnection(); if (gvTrace) Log("Received SOAP response: " + result); return result; }
I use this extensively in our shop. I use this to do some of the heavy lifting that some people would typically put into a trigger. By using the SOAP approach, the workload can be sent to another server and free up a thread in Integrity. And yes, from that external web service, you can call back into Integrity again.
One of the key uses of this for me is that I create in-item dashboards with charts. When an item changes, or on a schedule, I'll make a web service call to generate a graph based on item data. When the graph is complete, I update the item with the resulting image file. Everything is done on another server dedicated to creating these charts and graphs. And none of the creation of these things weighs down the Integrity server at all. This is my go-to approach for anything that can run outside of Integrity.
Hi Chinmay,
You may want to post an Integrity "product idea", for this, to have it supported and working with the correct SOAP classes out of the box. I am sure others will vote for this idea.
It's actually relatively easy to do from a trigger. I use a generic function that makes the SOAP calls for me and accepts the URL to post to, as well as a string that holds the XML to send. Once the call is complete, the return XML is passed back to the caller.
To generate the SOAP call (the body), I simply use SOAPUI to connect to the web service and generate a template XML stream. I then paste that into the trigger script as text, and reformat it so that it's a string. Along the way, inser the text from the item that fired the trigger (which I'm assuming you would want), and the call the function to post it.
Here's the function that I use to POST the request:
function PostSOAPRequest(strURL, strBody) { var result = new java.lang.String(""); var client = new Packages.org.apache.commons.httpclient.HttpClient(); var hostConfig = client.getHostConfiguration(); hostConfig.setHost(new Packages.org.apache.commons.httpclient.URI(strURL)); var objPost = new Packages.org.apache.commons.httpclient.methods.PostMethod(strURL); objPost.setRequestHeader("Content-type", "text/xml; charset=utf-8"); objPost.setRequestHeader("Content-Length", ""+strBody.length()); objPost.setRequestBody(strBody); if (gvTrace) Log("Posting SOAP request to " + strURL); var responseCode = client.executeMethod(objPost); var inputStream = objPost.getResponseBodyAsStream(); var bufReader = new java.io.BufferedReader(new java.io.InputStreamReader(inputStream)); var line = new java.lang.String(""); while (null != (line=bufReader.readLine())) result += line; objPost.releaseConnection(); if (gvTrace) Log("Received SOAP response: " + result); return result; }
I use this extensively in our shop. I use this to do some of the heavy lifting that some people would typically put into a trigger. By using the SOAP approach, the workload can be sent to another server and free up a thread in Integrity. And yes, from that external web service, you can call back into Integrity again.
One of the key uses of this for me is that I create in-item dashboards with charts. When an item changes, or on a schedule, I'll make a web service call to generate a graph based on item data. When the graph is complete, I update the item with the resulting image file. Everything is done on another server dedicated to creating these charts and graphs. And none of the creation of these things weighs down the Integrity server at all. This is my go-to approach for anything that can run outside of Integrity.