【问题标题】:Add method in JS HTTP Adapters for MobileFirst 8在 MobileFirst 8 的 JS HTTP 适配器中添加方法
【发布时间】:2016-09-01 06:40:00
【问题描述】:

我正在尝试使用 JavaScript HTTP 适配器从 SOAP Web 服务中获取一些数据。为此,我将 MFP8 和 Ionic 与 TypeScript 一起使用。

我有以下适配器实现文件,

function getFeed(params) {
  var sr =
          "<soapenv:Envelope " +
          "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
          "xmlns:len=\"targetNamespace HERE" >" +
          "<soapenv:Header/>"+
          "<soapenv:Body>" +
          "<len:authentication>" +
          "<username>"+params[0]+"</username>"+
          "<password>"+params[1]+"</password>"+
          "</authentication></soapenv:Body></soapenv:Envelope>";

    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : 'PATH HERE',
      body: {
            content: sr,
            contentType: 'text/xml; charset=utf-8',
          },
    };
  return MFP.Server.invokeHttp(input);
}

这里是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>

因此,按照 API 文档,我执行了以下操作以在我的 ionic 提供程序中调用适配器,

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

因为,我需要从 SOAP 服务中获取特定数据。为此,我需要传递参数和方法。

在知识中心阅读,我发现了一些关于使用查询字符串调用参数的东西,我可以传递参数。

我的要求是也传递方法名称。

谁能告诉我如何传递方法名?

感谢任何人的帮助!!!

【问题讨论】:

    标签: javascript ionic-framework ibm-mobilefirst


    【解决方案1】:

    您可以传递任意数量的参数,例如,您可以执行以下操作:

    在适配器中:

    function getFeed(method, username, password) {
      var sr =
              "<soapenv:Envelope " +
              "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
              "xmlns:len=\"targetNamespace HERE" >" +
              "<soapenv:Header/>"+
              "<soapenv:Body>" +
              "<len:authentication>" +
              "<method>"+method+"</method>"+
              "<username>"+username+"</username>"+
              "<password>"+password+"</password>"+
              "</authentication></soapenv:Body></soapenv:Envelope>";
    
        var input = {
            method : 'post',
            returnedContentType : 'xml',
            path : 'PATH HERE',
          body: {
                content: sr,
                contentType: 'text/xml; charset=utf-8',
              },
        };
      return MFP.Server.invokeHttp(input);
    }
    

    在客户端:

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

    请求中的 JSON 数组语法只是通过网络传递参数的方式,并不意味着您在适配器中返回了一个数组。它的工作原理是将数组中的第一个元素分配给第一个函数参数,将第二个元素分配给第二个参数,等等......

    【讨论】:

    • 我已经尝试过了。我无法获取方法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多