I recently needed to know the IP address of the MID Server that would be connecting to a third-party service provider for one of my integrations. The MID Server is in a data center that I don’t have access to, and I didn’t know how to easily find out the IP Address that external systems would see when it makes its FTP or other connections to the service. Yes, I could have called the operations people, but that would take the fun out of the exercise. I also wanted a chance to learn more about MID Server Script Includes, which I ended up using in this exercise.
For this solution, I decided I would reuse the script that I created for determining the connectivity information on a Service-now.com Instance.
After doing a little code-digging, I found that a MID Server Script include works very much like a typical script include for Service-now. However, if you make a change to your script, you have to restart the MID Server service so that it knows to re-cache the script in it’s system.
In order for me to execute my MID Server Script Include, I found that I needed to utilize the “JavascriptProbe”. I also found out that I could return the script output via a “paramater” to the Javascript Probe. The code for this is: “probe.setParameter({param_name}, {param_value});”
The modified connectivity script that has been placed into my MID Server Script Include looks like this:
Name: GetSourceConnectionInfo
Script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | var GetSourceConnectionInfo = Class.create(); GetSourceConnectionInfo.prototype = { initialize: function() { var url = new Packages.java.net.URL("https://john-james-andersen.com/tools/connection.php"); var isr = new Packages.java.io.InputStreamReader(url.openStream()); var inp = new Packages.java.io.BufferedReader(isr); var inputLine = ""; var result = ""; while (inputLine = inp.readLine()) { ms.log(inputLine); result += inputLine; } inp.close(); probe.setParameter("Output", result); return result; } } |
Now to get the MID Server to run this code, you need to create a new record on the ECC Queue. Here is what my record looks like:
Agent: mid.server.my_mid_server
Topic: JavascriptProbe
Name: GetSourceConnectionInfo
Queue: output
State: ready
Payload:
1 2 3 4 5 | <?xml version="1.0" encoding="UTF-8"?> <parameters> <parameter name="script" value="var req = new GetSourceConnectionInfo();"> </parameter> </parameters> |
When I submit that output record on the ECC Queue, I get a response that looks somewhat like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?xml version="1.0" encoding="UTF-8"?> <results probe_time="844"> <result> <output>org.mozilla.javascript.Undefined@aa3518</output> </result> <parameters> <parameter name="topic" value="JavascriptProbe"/> <parameter name="queue" value="output"/> <parameter name="sys_id" value="37311074c0a8016b00a83d033e819674"/> <parameter name="state" value="ready"/> <parameter name="Output" value="<BR><H1>Source Connectivity Checker</H1><i><center>John-James-Andersen.com sees your connection information as: </center></i><br><B>UNIQUE_ID</B>: TNrtvUPNN98AADN4RCsAAAAF<BR><B>SCRIPT_URI</B>: https://john-james-andersen.com/tools/connection.php<BR><B>HTTP_USER_AGENT</B>: Java/1.6.0_14<BR><B>HTTP_CONNECTION</B>: close<BR><B>REMOTE_ADDR</B>: 215.185.69.123<BR><B>REMOTE_PORT</B>: 1613<BR><B>REQUEST_METHOD</B>: GET<BR><B>QUERY_STRING</B>: <BR><B>REQUEST_TIME</B>: 1289416125<BR>"/> <parameter name="script" value="var req = new GetSourceConnectionInfo();"/> <parameter name="agent" value="mid.server.RadRoadTrips.com"/> <parameter name="ecc_queue" value="37311074c0a8016b00a83d033e819674"/> <parameter name="sequence" value="12c373110940000001"/> <parameter name="name" value="GetSourceConnectionInfo"/> <parameter name="table_name" value="ecc_queue"/> </parameters> </results> |
You’ll notice that my parameter named, “Output” holds the HTML response (escaped) that it returned from the URL that I had it reach. If I wanted to do something fancy I could create a business rule to watch for that message and have it unescape and parse the HTML response to give me the information that I need.
Nicely done! You need to end the story with “happily ever after” though!
It is a tear-jerker, isn’t it! 😉