August 1, 2014

Testing SOAP Outbound Messages without failures

As suggested by Salesforce docs, one can use services like requestb.in or inspectb.in to test outbound messages. But these services are pretty generic so they just return 200 / OK response for any inbound request. For an outbound message to be considered delivered successful by salesforce, it needs an SOAP XML response with "Ack = true" in following format:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<notificationsResponse xmlns="http://soap.sforce.com/2005/09/outbound">
<Ack>true</Ack>
</notificationsResponse>
</soapenv:Body>
</soapenv:Envelope>



Without above XML response, outbound messages fail for following error
"org.xml.sax.SAXParseException: Content is not allowed in prolog."
Such failed outbound messages are also marked for RETRY, each such retries add delay for each subsequent failure, which will always happen with requestbin, as they will never give expected response to Salesforce. You can watch success/failure of outbound message in Salesforce setup area here:

Setup > Administration Setup > Monitoring > Outbound Messages
Failed Outbound Messages 

So, after a while of testing with request/inspect bin you will realise that you are getting too many repeated messages in requestbin. It eventually confuses developer/tester which one is really making sense for the situation.


Solution ?

Requestbin/Inspectbin are logging SOAP messages in a great way, we don't need to change that. A wrapper service is needed which could sit between salesforce and requestbin. This service will send original request to requestbin, but return back to Salesforce the acknowledgement XML response it expects. 

For ex. 
http://sfdcutils.appspot.com/ombin?endpoint=http://inspectb.in/2552ba0f
Here  feed "endpoint" param with URL from any of your favorite requestbin/inspectbin or similar service, rest all should be awesome !

Live Demo

You can check this video for more details and a quick demo: