简体   繁体   English

通过HTTP Adapter MFP 7.1调用REST WebServices

[英]Call REST WebServices via HTTP Adapter MFP 7.1

We are developing IONIC App using MFP7.1. 我们正在使用MFP7.1开发IONIC App。 We are trying to call REST webservice to get some data using HTTP Adapter. 我们正在尝试使用HTTP适配器调用REST webservice来获取一些数据。

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, 这是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....... “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,“不能在这里反序列化WEBSERVICE实体的实例。用户在[Siyrce.org.apache.catal.inc.connector .......]的START_ARRAY令牌\\ n之外

Per the suggestion in the comments, try changing .toString() to JSON.stringify : 根据评论中的建议,尝试将.toString()更改为JSON.stringify

content:
    JSON.stringify(data)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM