MCS: Calling SOAP connector bypassing XML/JSON translator

In the MCS project we are working we have to create some SOAP Connectors to integrate with Siebel. A great thing of MCS is that although we are going to consume a SOAP web service, the XML payload is automatically translated into JSON. You can get more info in MCS Documentation.

I would like to thank Oracle Mobile PM  team, specially Grant Ronald and Frédéric Desbiens for their great help and for sharing best practices about this issue.

As soon as we create a SOAP Connector and try to test it we can see that the body we have to provide is a JSON.

But there are some cases where the translator is not perfect. We had a problem with some services that had an XML structure like this:

The translator seems not to add the  namespaces in the header therefore Siebel cannot parse the request.

The solution is to send a XML instead of a JSON, bypassing the translator.
We can test this in SOAP Connector tester. As we need the required XML, we can get it in any web service client tool like for example SoapUI.

We also have to set “Content-Type: application/xml;charset:UTF-8” and “Accept: application/xml” as header parameters.

If we test the Connector we can see that the web service call is working.

How do we implement the Custom API to send a XML payload to the connector?
The answer is to set the XML we want to send as the body of the request and set the header parameters we previously use to test the connector.

But, is this the recommended approach? Yes it is, but instead of sending a String with the SOAP message it is more secure to send it as a JavaScript object.

In order to implement this we have to follow some steps:

  1. Download and Install Node.js. link
  2. Install xml2js module.
  3. In this example test_rrs is the directory where the package.json file resides.

  4. Add xml2js as a dependency in package.json
  5. Moving to our javascript file, as I already stated before the first idea was to build the SOAP message as a string. This first image is the base implementation and we are going to make some changes to it.
  6. First we need to add var xml2js = require(‘xml2js’); at the top of our implementation.

    This is the tricky part, we need to create a JSON like this.
    ‘ $ ‘ means that we want to add attributes to the XML element.
    ‘ _ ‘ means that we want to have something inside that element.

    The last thing we have to do is to create a xml2js.Builder object and execute buildObject method using the json object we have just create. The result of this method is the body we are going to send.
After the implementation is done we just have to put everything inside the zip file and upload it to MCS.
If you want to know more about xml2js click here.

You Might Also Like

Leave a Reply