SOAP polling with Mirth

There are some recurrent problems when developing interfaces with Mirth, and one of the trickiest is SOAP polling. From early versions of Mirth there is a SOAP sender connector, but it doesn’t have any direct connector to poll a webservice. As far as I know polling is considered to be a near-antipattern, but under some circunstances you may be forced to use it if the integration counter-part is closed-source.

To read periodically from a WS you need to setup an interface with these connectors:

  • source: JS Reader
  • destination 1: SOAP Sender
  • postprocessor or destination 2: JS Writer (or any other destination-type with a JS Transformer inside)

The JS Reader is essentially a code that will be executed with a custom frequency or at specific hour on a daily basis. The most important point is that the source must return an XML message, otherwise you’ll get parsing errors. Message structure doesn’t matter, it’s used only as a event.

var retval = "";

retval  = "";
retval += "    value";
retval += "";

return retval;

You can build a more complex scheduling if you filter the message after checking things like system date to run every Sun, Mon, Wed, every 1st Sunday of month or every 2 days …

Next step is calling the WS in a SOAP sender (destination 1). If the WS needs some parameters you can prepare them in the transformer or in a previous destination. When a event is thrown by the source connector, Mirth will call the WS configured. In this example I’ll use a public access WS that seems to return the last N photos added to the site. Well, lets examine the SOAP response and do something with it:

	xmlns="(several namespaces)">
		<ListResponse xmlns="(more ns)">
			<Caption>Keeping the Pace</Caption>
			<Description>Cross country runner keeps the pace</Description>

Destination 2 is a channel writer and I use a JS transformer to put the following code because this way I can paste and look the msg structure in the right side panel. You may consider to use the postprocessor script instead of a second destination because if some error happens in the 1st destination execution the 2nd destination will not be executed. But the postprocessor is executed for each message received in the interface.

The WS seems to return a list of the last N photos uploaded to the site, can we take the WS response and iterate over the list?

var response;
var list;

response = new XML(
			responseMap.get('Destination 1').getMessage()

msg = new XML(response..*::ListResult);

for each (photo in msg..*::WebPhoto) {
	photo = new XML(photo);

In this point you can do some error-controlling-stuff if there was an error while calling destination 1 with:

var stat = responseMap.get('Destination 1').getStatus();
if (stat != "SUCCESS" ) {

Now you have a SOAP polling interface, but the drawbacks are:

  • The message stored is the XML returned in the source, unless you overwrite “msg” var with your real message.
  • Searching for a message containing a known string it’s very inneficient.
  • Storing medium-sized XMLs in Mirth’s database may increase you DB size, ensure that pruning is configured!



One Response to “SOAP polling with Mirth”

  1. I’ve been trying to do this, and this is what i needed, but my source is essentially returning HL7, so I’m afraid this won’t work…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: