使用 nodejs 消费 Cloud for Customer 系统上的 Web service

举报
Jerry Wang 发表于 2021/10/31 13:50:10 2021/10/31
【摘要】 Jerry在公众号文章C4C和微信集成系列教程里曾经使用nodejs去消费C4C提供的标准webservice。看一个具体例子:C4C里Individual Customers可以维护Social User Profile,在Jerry上面的公众号文章里,正是把微信用户的open ID维护到Social User Profile的SocialMediaAccountUserID字段去,如下图...

Jerry在公众号文章C4C和微信集成系列教程里曾经使用nodejs去消费C4C提供的标准webservice。

看一个具体例子:C4C里Individual Customers可以维护Social User Profile,在Jerry上面的公众号文章里,正是把微信用户的open ID维护到Social User Profile的SocialMediaAccountUserID字段去,如下图所示。

那么已知一个Social Profile ID,如何用nodejs通过Web Service的方式获得该Profile明细?

首先到Administrator->Input and Output Management->Service Explorer中取得标准的查询Social User profile的web service:

https://<host name>/sap/bc/srt/scs/sap/requestforsocialmediauserprofi

然后使用nodejs module request给这个url发一个HTTP post请求。

您可以参考我github上的源代码。


var request = require('request');
var config = require("../../config.js");

function getSocialMediaProfile(profileID) {

  console.log("Jerry trace begin ***********************************");
  console.log("url: " + config.socialMediaProfileGetEndPoint);
  console.log("config.credential_qxl: " + config.credential_qxl);

  var ogetSocialMediaProfileOptions = {
        url: config.socialMediaProfileGetEndPoint,
        method: "POST",
        headers: {
            "content-type": "text/xml",
            'Authorization': 'Basic ' + new Buffer(config.credential_qxl).toString('base64')
        },
        body: '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:glob="http://sap.com/xi/SAPGlobal20/Global"><soapenv:Header/><soapenv:Body><glob:SocialMediaUserProfileRequest_sync>'
                      +'<SocialMediaUserProfileSelectionByElements>'
                      +'<SelectionBySocialMediaUserProfileID>'
                      +'<InclusionExclusionCode>I</InclusionExclusionCode>'
                      +'<IntervalBoundaryTypeCode>1</IntervalBoundaryTypeCode>'
                      +'<LowerBoundarySocialMediaUserProfileID >' + profileID + '</LowerBoundarySocialMediaUserProfileID>'
                      +'</SelectionBySocialMediaUserProfileID>'
                      +'</SocialMediaUserProfileSelectionByElements>'
                      +'</glob:SocialMediaUserProfileRequest_sync></soapenv:Body></soapenv:Envelope>'
              };

  console.log("body: " + ogetSocialMediaProfileOptions.body);
  console.log("Jerry trace end ***********************************");

  return new Promise(function(resolve,reject){
      request(ogetSocialMediaProfileOptions,function(error,response,body){

        console.log("Jerry web service response: " + body);
        var soapreg = /.*<SocialMediaUserAccountID>(.*)<\/SocialMediaUserAccountID>.*/;
	      var soapresult = soapreg.exec(body);
	      if( soapresult.length === 2){
	   		  resolve(soapresult[1]);
	      }
      });
    }); 
}

module.exports = getSocialMediaProfile;

将上述代码另存为文件getSocialMediaProfileTest.js, 直接使用node getSocialMediaProfileTest.js执行。

从console能观察到发送的HTTP post请求的body和返回的响应内容:

Netweaver和CloudFoundry的服务器日志

Netweaver

事务码SMICM,Goto->HTTP Plug-In->Server Logs:

CloudFoundry

假设我部署本地应用到CloudFoundry之后,应用的状态变为CRASHED。然而从应用的控制台看不出太多有用的信息。


此时可以使用命令cf logs <application name> --recent来查看服务器端日志:

从返回的日志我们能清楚看到应用部署后CRASH的原因为manifest.yml里为应用分配的512M不够大。


把该数字调大后错误即解决。

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。