javascriptandroidibm-mobilefirstworklight-adaptersmobilefirst-adapters

MobileFirst - call adapter - ERR_CONNECTION_RESET


I have a problem with call MobileFirst adapter from my app. If I use swagger docs or postman to test adapter method, it works. Unfortunately from app preview, I receive message:

http://localhost:6015/mfp/api/adapters/ServiceAdapter/login?params=%5Btest%2C%20test123%5D net::ERR_CONNECTION_RESET

I don't understand why request to the adapter from my app is forwarded to the port 6015. During the tests (swagger and postman) I used 9080, maybe it is the problem, but I don't know how to change app target port from 6015 to 9080.

adapter xml:

<mfp:adapter name="ServiceAdapter"
         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>ServiceAdapter</displayName>
<description>ServiceAdapter</description>
<connectivity>
    <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
        <protocol>http</protocol>
        <domain>localhost</domain>
        <port>53873</port>
        <connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
        <socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
        <maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
    </connectionPolicy>
</connectivity>

<procedure name="login" secured="false" />

implementation:

function login(login, pass) {
    path = 'token';
    var input = {
        method : 'post',
        returnedContentType : 'json',
        path : path,
        headers : {
            'Content-Type' : 'application/x-www-form-urlencoded'
        },
        body : {
            contentType : 'application/x-www-form-urlencoded',
            content : 'username=' + login + '&password=' + pass + '&grant_type=password'
        }
    };
    return MFP.Server.invokeHttp(input);
}

and adapter call:

function Login() {
    var resourceRequest = new WLResourceRequest(
            "/adapters/ServiceAdapter/login",
            WLResourceRequest.GET
    );

    resourceRequest.setQueryParameter("params", "[" + $("#log").val() + ", " + $("#pass").val() + "]");
    resourceRequest.send().then(LoginSuccess, LoginFailure);
}

edited 6.04.2017:
additionally, i've noticed, that at the moment of adapter calling, i get this error in console from previewCordova.js file. it looks like variable req.url is undefined:

C:\...\npm\node_modules\mfpdev-cli\node_modules\mdo-app-preview\lib\previewCordova.js:579
    if(!req.url.startsWith('/')) {
                ^
TypeError: undefined is not a function
    at Server.<anonymous> (C:\..\npm\node_modules\mfpdev-cli\node_modules\mdo-app-preview\lib\previewCordova.js:579:17)
    at Server.emit (events.js:110:17)
    at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:491:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:111:23)
    at Socket.socketOnData (_http_server.js:343:22)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:538:20)

Solution

  • I've resolved a problem. My version of NodeJS doesn't support javascript String.prototype.startsWith method. So i've added this method to previewCordova.js file:

    if (!String.prototype.startsWith) {
      String.prototype.startsWith = function(searchString, position) {
        position = position || 0;
        return this.indexOf(searchString, position) === position;
      };
    }
    

    Newer versions of NodeJS had implemented startsWith method, so NodeJS upgrade should resolve problem too.