简体   繁体   English

从后端获取空响应 - Gatewayscript

[英]Getting empty response from backend - Gatewayscript

I have to get the details of an agent from backend server based on agent_id.我必须根据 agent_id 从后端服务器获取代理的详细信息。 We are passing few input parameters in headers.我们在标头中传递了几个输入参数。 i want to get the request ID number in case of error.我想在出现错误时获取请求 ID 号。 I have written the gateway script as below:我编写了如下网关脚本:

// Define modules
var sm   = require('service-metadata.js');
var hm   = require('header-metadata.js');
var apim = require('./apim.custom.js'); 

var LegacyAgentNumber = apim.getvariable('request.parameters.LegacyAgentNumber');
var requestId = apim.getvariable('request.parameters.requestId');
var channelId = apim.getvariable('request.parameters.channelId');
var channelName = apim.getvariable('request.parameters.channelName');
var sm_user = apim.getvariable('request.parameters.sm_user');

// To send as query parameters
var queryString = '$filter=contains(LegacyAgentNumber,%27'+legacyAgentNumber+'%27)';

apim.setvariable('queryString', queryString);
apim.setvariable('requestId', requestId);
apim.setvariable('channelId', channelId);
apim.setvariable('channelName', channelName);
apim.setvariable('sm_user', sm_user);

var contentType = apim.getvariable('request.headers.content-type');
apim.setvariable(sm_user, contentType, 'set');

if (error) {

     {
//here I want to print the requestID from headers as values in errorId and refidRequest fields.
"errorId": "{requestId}Err",

"refidRequest": "{requestId}",

"httpCode": "400",

"httpMessage": "Bad Request",

"moreInformation": "Invalid Input Parameters"

} 

else {

        // read response data

        // get the response status code

        var vid = apim.getvariable ('request.parameters.id');
var vapiversion = apim.getvariable('api.version');
var vapiname = apim.getvariable('api.name');


var sresponse= {"AgentMailingAddressKeepAliveResponse": {"responseHeader": {
   "id": vid +"_rs",
   "refidRequest": vid,
   "cmdType": "response",
   "cmdStatus": "Success",
   "message": "keepAlive response message "+vapiname+":"+vapiversion
}}}
apim.setvariable('message.body',response);
apim.setvariable('message.headers.content-type','application/json');
apim.setvariable('message.status.code',200);

Here is the URI: https://dev.blah.com:port/enterprise/dev/agencies/agency/books/book/agents/{agent_id}/contact-information?requestId=_123&channelId=OL&channelName=OL这是 URI: https://dev.blah.com:port/enterprise/dev/agencies/agency/books/book/agents/{agent_id}/contact-information?requestId=_123&channelId=OL&channelName=OL

How do i write the query string for this and achieve to get the details from the target.我如何为此编写查询字符串并实现从目标获取详细信息。

As I see you have already saved the necessary data in the variables.如我所见,您已经在变量中保存了必要的数据。 So did you try a query like below in invoke policy?那么您是否在调用策略中尝试过如下查询?

https://dev.blah.com:port/enterprise/dev/agencies/agency/books/book/agents/$(agentId)/contact-information?requestId=$(requestId)&channelId=$(channelId)&channelName=$(channelName)

Also you don't need to use this files:你也不需要使用这个文件:

var sm   = require('service-metadata.js');
var hm   = require('header-metadata.js');
var apim = require('./apim.custom.js'); 

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

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