Search code examples
javascriptibm-mobilefirstmobilefirst-adaptersmobilefirst-server

MobileFirst V8.0.0 , cordova client app can't get response from JavaScriptSOAP (SOAP integration)


MobileFirst V8.0.0 , cordova client app can't get response from JavaScriptSOAP (SOAP Integration):

I have a problem accessing a JavaScriptSOAP (Example Adapter) from a Cordova client app, there is no response from Adapter JavaScriptSOAP.
I'm using Mobilefirst Server 8.0 Development Foundation kit.

Question: What is the reason I can't get the response, does it requires to setting the security again, if security where to set it.

1) Client App Cordova (index.js)

var app = {
    // Application Constructor
    initialize: function() {
      this.bindEvents();
    },
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.getElementById("btn_submit").addEventListener('click', app.submitRequest);
    },

    submitRequest:function() {
var resourceRequest = new WLResourceRequest("/adapters/JavaScriptSOAP/getWeatherInfo", WLResourceRequest.GET);
resourceRequest.setQueryParameter("params", "['Washington', 'United States']");
 resourceRequest.send().then(app.onSuccess, app.onFailure);

    },
onSuccess: function(response) {
        WL.Logger.info("Success: " + response.responseText);
        window.plugins.spinnerDialog.hide();


       var $result = $(response.invocationResult.Envelope.Body.GetWeatherResponse.GetWeatherResult);
       var weatherInfo = {
        location: $result.find('Location').text(),
        time: $result.find('Time').text(),
        wind: $result.find('Wind').text(),
        temperature: $result.find('Temperature').text(),
    };

  document.getElementById("div_result").innerHTML= weatherInfo;
    },

    onFailure: function(response) {

        WL.Logger.info("Failure: " + JSON.stringify(response));
        window.plugins.spinnerDialog.hide();

        var resultText = "Failure: " + JSON.stringify(response);

        document.getElementById("div_result").innerHTML = resultText;
    }

};

2) Java Script Adapter - JavaScriptSOAP (from GITHUB example)

2.1) JavascriptSOAP-impl.js

function getWeatherInfo(cityName, countryName) {
    var request =
        <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
            <soap:Body>
                <GetWeather xmlns="http://www.webserviceX.NET">
                    <CityName>{cityName}</CityName>
                    <CountryName>{countryName}</CountryName>
                </GetWeather>
            </soap:Body>
        </soap:Envelope>;

    var input = {
        method: 'post',
        returnedContentType: 'xml',
        path: '/globalweather.asmx',
        body: {
            content: request.toString(),
            contentType: 'text/xml; charset=utf-8'
        }
    };

    var result = MFP.Server.invokeHttp(input);

    var xmlDoc = new XML(result.Envelope.Body.GetWeatherResponse.GetWeatherResult);

    var weatherInfo = {
        Location: xmlDoc.Location.toString(),
        Time: xmlDoc.Time.toString(),
        Wind: xmlDoc.Wind.toString(),
        Temperature: xmlDoc.Temperature.toString()
    };

    MFP.Logger.debug("This is a debug message from a JavaScript adapter" + weatherInfo.Temperature);


    // return result.Envelope.Body;
    return weatherInfo;
};

2.2) adapter.xml

<mfp:adapter name="JavaScriptSOAP"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mfp="http://www.ibm.com/mfp/integration"
    xmlns:http="http://www.ibm.com/mfp/integration/http">

    <displayName>JavaScriptSOAP</displayName>
    <description>JavaScriptSOAP</description>
    <connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>http</protocol>
            <domain>www.webservicex.net</domain>
            <port>80</port>
        </connectionPolicy>
    </connectivity>

    <procedure name="getCitiesByCountry"/>
    <procedure name="getWeatherInfo"/>
</mfp:adapter>

Solution

  • Are you getting any error (kindly mention if any) ? Which Response Code you are getting ?

    After deploying adapter, I am assuming you are getting response code : 200

    But Data not found in "GetWhetherResult".

    you are getting Response Body as:

       {
          "isSuccessful": true,
          "GetWeatherResponse": {
            "xmlns": "http://www.webserviceX.NET",
            "GetWeatherResult": "Data Not Found"
          }
        }
    

    Check in MobileFirst Swagger enter image description here

    Using parameter
    MobileFirst Swagger