1

We are developing IONIC App using MFP7.1. We are trying to call REST webservice to get some data using HTTP Adapter.

I have the following adapter implementation file,

 function getFeed(username,password) {
  var data = {
    "username" : username,
    "password" : password
  };

    var input = {
        method : 'post',
        returnedContentType : 'plain',
        path : 'PATH HERE',
     body: {
        content: data.toString(),
        contentType: 'application/json; charset=utf-8;',
      },
    };
  return WL.Server.invokeHttp(input);
 }

And here is the adapter.xml,

<mfp:adapter name="http"
             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>http</displayName>
    <description>http</description>
    <connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>http</protocol>
      <domain>DOMAIN NAME HERE</domain>
      <port>PORT NO HERE</port>
            <connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
            <socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
            <maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
        </connectionPolicy>
    </connectivity>
  <procedure name="getFeed"/>
</mfp:adapter>

We did the following to call the adapter within my ionic provider,

 var resourceRequest = new WLResourceRequest("adapters/http/getFeed", WLResourceRequest.GET);
   resourceRequest.setQueryParameter("params", "['username', 'password']");
   resourceRequest.send().then(
       function(response) {
            alert('response   '+JSON.stringify(response.responseText));
       },
       function(response) {
            alert("HTTP Failure  "+JSON.stringify(response));
       }
   );

I am getting the following error in the error log,

"errors\":[],\"info\""statuscode\":400}","responseJSON":{"statusReason":"Bad Request","responseHeaders":{"Transfer-Encoding":"chunked","Server":"Apache-Coyote/1.1","Connection":"close","Content-Type":"text/plain"},"isSuccessful":true,"Can not deserialize instance of WEBSERVICE entity here.User out of START_ARRAY token\n at[Siyrce.org.apache.catal.inc.connector.......

S.M.Priya
  • 354
  • 4
  • 15
  • it looks like there is some issue between the adapter on the MFP server and the backend. It seems like the backend is returning a 400 response to the adapter and the adater just sends this 400 response back to your mobile client. Could there be an issue with the request that the adapter is sending out to the backend? – Moty Drimer Sep 08 '16 at 13:29
  • 2
    I think this line: content: data.toString() is trouble. toString() is not the correct way to stringify an object in JS. It will work but it will probably just give you "[Object object]" in this case – Moty Drimer Sep 08 '16 at 13:39
  • @s.m.priya, did you try what Moty suggested above? – Idan Adar Oct 14 '16 at 04:01

1 Answers1

0

Per the suggestion in the comments, try changing .toString() to JSON.stringify:

content:
    JSON.stringify(data)
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • what is difference between client adapter call methods WLResourceRequest and WL.Client.invokeProcedure? – Suhas Gosavi Feb 08 '17 at 09:35
  • See the first paragraph here: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/7.1/server-side-development/invoking-adapter-procedures-hybrid-client-applications/#overview – Idan Adar Feb 08 '17 at 09:36
  • so using WLResourceRequest we can access external resources also that is the only difference between these two calls? – Suhas Gosavi Feb 08 '17 at 09:39