通过HTTP适配器MFP 7.1调用REST WebServices

Call REST WebServices via HTTP Adapter MFP 7.1

本文关键字:调用 REST WebServices HTTP 适配器 MFP 通过      更新时间:2023-09-26

我们正在使用MFP7.1开发IONIC App。我们正在尝试使用HTTP适配器调用REST web服务来获取一些数据。

我有以下适配器实现文件

 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);
 }

这里是适配器。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>

我们做了下面的操作来调用离子提供程序中的适配器,

 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));
       }
   );

我在错误日志中得到以下错误,

"错误' ":[],'"info '"statuscode '":400}"、"responseJSON":{"statusReason":"坏请求"、"responseHeaders":{"传输编码":"分块"、"服务器":"Apache-Coyote/1.1","连接":"近","内容类型":"text/plain"},"isSuccessful":真的,"这里没有反序列化WEBSERVICE实体的实例。用户退出START_ARRAY token'n at[Siyrce.org.apache.catal.inc.connector.......

根据评论中的建议,尝试将.toString()更改为JSON.stringify:

content:
    JSON.stringify(data)