如何在SAP Netweaver网关HTTP适配器中使用响应?

时间:2022-11-11 22:14:37

I'm integrating SAP and IBM MobileFirst using SAP Netweaver Gateway HTTP Adapter. I am able to connect to the SAP Backend System successfully and I'm getting the data in a xml format. This is the response I'm getting:

我正在使用SAP Netweaver Gateway HTTP Adapter集成SAP和IBM MobileFirst。我能够成功连接到SAP后端系统,并且我以xml格式获取数据。这是我得到的回应:

{
"RETURN": "<?xml version=\"1.0\" encoding=\"utf-8\"?><app:service xml:base=\"http:\/\/sapecc.mss.com:8000\/sap\/opu\/sdata\/iwfnd\/SampleUserProcessing\/\" xmlns:app=\"http:\/\/www.w3.org\/2007\/app\" xmlns:atom=\"http:\/\/www.w3.org\/2005\/Atom\" xmlns:sap=\"http:\/\/www.sap.com\/Protocols\/SAPData\" xmlns:gp=\"http:\/\/www.sap.com\/Protocols\/SAPData\/GenericPlayer\" xmlns:m=\"http:\/\/schemas.microsoft.com\/ado\/2007\/08\/dataservices\/metadata\"><app:workspace sap:semantics=\"things\"><atom:title>Things<\/atom:title><\/app:workspace><app:workspace sap:semantics=\"data\"><atom:title>Data<\/atom:title><app:collection href=\"RoleCollection\" sap:creatable=\"true\" sap:updatable=\"true\" sap:deletable=\"true\"><atom:title>RoleCollection<\/atom:title><sap:member-title>Role<\/sap:member-title><\/app:collection><app:collection href=\"ImageCollection\" sap:creatable=\"true\" sap:updatable=\"true\" sap:deletable=\"true\"><atom:title>ImageCollection<\/atom:title><sap:member-title>Image<\/sap:member-title><\/app:collection><app:collection href=\"EmailCollection\" sap:creatable=\"true\" sap:updatable=\"true\" sap:deletable=\"true\"><atom:title>EmailCollection<\/atom:title><sap:member-title>Email<\/sap:member-title><\/app:collection><app:collection href=\"ActivitygroupCollection\" sap:creatable=\"true\" sap:updatable=\"true\" sap:deletable=\"true\"><atom:title>ActivitygroupCollection<\/atom:title><sap:member-title>Activitygroup<\/sap:member-title><\/app:collection><app:collection href=\"UserCollection\" sap:creatable=\"true\" sap:updatable=\"true\" sap:deletable=\"true\"><atom:title>UserCollection<\/atom:title><sap:icon>icon<\/sap:icon><sap:member-title>User<\/sap:member-title><atom:link href=\"SubscriptionCollection\" rel=\"http:\/\/www.sap.com\/Protocols\/SAPData\/rel#subscribe\"\/><\/app:collection><app:collection href=\"UserXnotificationCollection\" sap:creatable=\"false\" sap:updatable=\"false\" sap:deletable=\"false\"><atom:title>UserxnotificationCollection<\/atom:title><sap:member-title>UserXnotification<\/sap:member-title><\/app:collection><app:collection href=\"SubscriptionCollection\" sap:semantics=\"subscriptions\" sap:creatable=\"true\" sap:updatable=\"false\" sap:deletable=\"true\"><atom:title>Subscriptions<\/atom:title><sap:icon>\/sap\/public\/opu\/resources\/sap\/iwfnd\/subscription\/icon_subscription.png<\/sap:icon><sap:member-title>Subscription<\/sap:member-title><gp:collectionLayout display-order=\"1000\" top-level=\"true\"\/><\/app:collection><\/app:workspace><app:workspace sap:semantics=\"subscriptions&amp;notifications\"><atom:title>Subscriptions &amp; Notifications<\/atom:title><\/app:workspace><\/app:service>",
    "isSuccessful": true,
    "responseHeaders": {
      "content-type": "application\/xml",
      "dataserviceversion": "2.0",
      "server": "SAP NetWeaver Application Server \/ ABAP 731",
      "x-sap-odata-extension-version": "0.9;gp=0.8"
    },
    "statusCode": 200,
    "statusReason": "OK"
    }

Now I want to pick a particular value from the xml. Can any one help me out in this area?

现在我想从xml中选择一个特定的值。任何人都能在这方面帮助我吗?

function retrieveTravelAgencyProperty() {
var request = {
    CollectionName: "SampleUserProcessing",

};
return WL.Server.fetchNWBusinessObject(request);
}

1 个解决方案

#1


0  

So back in your client logic, in the success callback of the adapter invocation you get a JSON object. This JSON object contains the response.

所以回到你的客户端逻辑中,在适配器调用的成功回调中,你得到一个JSON对象。此JSON对象包含响应。

So what I'm thinking you should do is to:

所以我在想你应该做的是:

  1. Either extract to another variable, or work directly on, the "RETURN" key from the response and
  2. 要么提取到另一个变量,要么直接在响应中使用“RETURN”键

  3. Make it into a readable JSON format again, something like this: http://davidwalsh.name/convert-xml-json
  4. 再次将它变成可读的JSON格式,如下所示:http://davidwalsh.name/convert-xml-json

  5. Iterate over the refreshed respone to find the key:value you're looking for. For example:

    迭代刷新的respone来找到关键:你正在寻找的价值。例如:

    for (i = 0; i < resultSet.length; i++) {
        if (resultSet[i].name == "some-value") { // assumed that you know what you're lookign for.
            alert (resultSet[i].name);
    }
    

Step 2 is the difficult part... not sure about it.

第2步是困难的部分......不确定。

#1


0  

So back in your client logic, in the success callback of the adapter invocation you get a JSON object. This JSON object contains the response.

所以回到你的客户端逻辑中,在适配器调用的成功回调中,你得到一个JSON对象。此JSON对象包含响应。

So what I'm thinking you should do is to:

所以我在想你应该做的是:

  1. Either extract to another variable, or work directly on, the "RETURN" key from the response and
  2. 要么提取到另一个变量,要么直接在响应中使用“RETURN”键

  3. Make it into a readable JSON format again, something like this: http://davidwalsh.name/convert-xml-json
  4. 再次将它变成可读的JSON格式,如下所示:http://davidwalsh.name/convert-xml-json

  5. Iterate over the refreshed respone to find the key:value you're looking for. For example:

    迭代刷新的respone来找到关键:你正在寻找的价值。例如:

    for (i = 0; i < resultSet.length; i++) {
        if (resultSet[i].name == "some-value") { // assumed that you know what you're lookign for.
            alert (resultSet[i].name);
    }
    

Step 2 is the difficult part... not sure about it.

第2步是困难的部分......不确定。