2

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)
robr
  • 55
  • 8

2 Answers2

2

Mobilefirst App Preview connects to MFP server via proxy which runs on port 6015 and the behavior which you facing is normal, its nothing to do with the port.

ERR_CONNECTION_RESET Error is caused due to browser & not from Mobilefirst Server.

Try making request with different browser and also try by clearing browsing data/cache.

Vittal Pai
  • 3,317
  • 25
  • 36
  • ok, i tried in mozilla and error dissapeared, but adapter call still not working. is it possible, that mentioned proxy not started properly with Mobilefirst App Preview? i've started it with standard command: _mfpdev app preview android,ios,windows --type mbs --noprompt --pid_ – robr Apr 03 '17 at 12:25
  • @robr Go through [this tutorial](https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/application-development/using-mobilefirst-cli-to-manage-mobilefirst-artifacts/#preview-a-cordova-application) to learn how to run apps in preview mode. Also make sure your app's adapter call is working fine in cordova and If it doesn't resolves your problem, Kindly share the error response which you getting while you making calls to server in preview mode. – Vittal Pai Apr 03 '17 at 13:44
  • I may be grasping at straws here, but it's also possible that this kind of error could be due to firewall rules set up on your local machine - you could have rules in place to prevent anything from connecting to port 6015 on localhost. This is only a guess, but it is something that might be worth looking into. – patbarron Apr 03 '17 at 21:56
  • I went through tutorial and checked port rules, but without results. I edited question and described more precisly received error. – robr Apr 06 '17 at 21:19
0

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.

robr
  • 55
  • 8