[英]jsonPath not working in apigee javascript policy
We have a json input from which we have to decode each element in the input and replace it back before going to the backend. 我们有一个json输入,从中我们必须解码输入中的每个元素,并在返回到后端之前将其替换回去。 we have used a Extract Variables policy to extract the elements, and in a Javascript policy we decode the elements by using a for loop.
我们使用了提取变量策略来提取元素,而在Javascript策略中,我们使用了for循环来对元素进行解码。 Now we have to replace the extracted elements with the decoded values.
现在我们必须用解码后的值替换提取的元素。 We tried to use jsonPath and replace the elements but getting a error called
我们尝试使用jsonPath并替换了元素,但遇到了一个错误
Execution of JavaScript-1 failed with error: Javascript runtime error: "ReferenceError: "jsonPath" is not defined. (JavaScript_1_js#5). at line 5
JavaScript-1的执行失败,并出现错误:
Javascript runtime error: "ReferenceError: "jsonPath" is not defined. (JavaScript_1_js#5). at line 5
The code we used for jsonpath is 我们用于jsonpath的代码是
var input = new String(context.getVariable("request.content"));
context.setVariable("input",input);
var path = jsonPath(input, "$..soldto").toJSONString();
context.setVariable("path",path);
Can we not use jsonPath in Apigee Javascript policy? 我们不能在Apigee Javascript策略中使用jsonPath吗?
By default if JSONPath is not present - you can download and add it to your proxy bundle. 默认情况下,如果不存在JSONPath-您可以下载并将其添加到代理包中。 You reference it using
includeURL
in the JS policy. 您可以在JS政策中使用
includeURL
对其进行引用。 This make it available to your JS code for use. 这使您的JS代码可以使用它。
http://apigee.com/docs/api-services/reference/javascript-policy#includeurl http://apigee.com/docs/api-services/reference/javascript-policy#includeurl
Also take a look at this same on how to use a custom JS lib which is not included. 还要看看如何使用未包含的自定义JS库的方法相同。
https://github.com/apigee/api-platform-samples/tree/master/sample-proxies/base64encoder/apiproxy https://github.com/apigee/api-platform-samples/tree/master/sample-proxies/base64encoder/apiproxy
The sample uses crypto JS. 该示例使用加密JS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.