在ApiGEE中使用非字符串值加载流变量

时间:2014-10-09 15:30:47

标签: apigee

我需要将系统变量“system.timestamp”的值保存到流变量中。 (这个想法是在两者之间获得一些标注政策的持续时间)

但是,我无法读取它,因为AssignMessage策略引发了错误:

{
    "fault": {
        "faultstring": "java.lang.Integer cannot be cast to java.lang.String",
        "detail": {
            "errorcode": "Internal Server Error"
        }
    }
}

无法读取Long或Integer值,只读取字符串,这有点奇怪,因为暴露变量的情况会是什么,无法读取?

我试图避免使用“非优雅”的Javascript策略,如果可能的话,那么这就是我用来读取值的[非常基本的] AssignMessage策略:

<AssignMessage async="false" continueOnError="false" enabled="true" name="time-test">
    <DisplayName>TimeTest</DisplayName>

    <AssignVariable>
      <Name>myvar</Name>
      <Ref>system.timestamp</Ref>
    </AssignVariable>

    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

system.timestamp变量在此处记录:  http://apigee.com/docs/api-services/reference/variables-reference#-a-class-jumplink-name-system-a-system-variables

2 个答案:

答案 0 :(得分:1)

如果AssignMessage策略不起作用,您应该能够使用JavaScript policy完成此操作。这将允许您将时间戳转换为它需要的任何形式。同样,JavaScript策略可用于稍后在代理中进行任何计时计算或操作。

答案 1 :(得分:1)

Migs,这是该产品的当前限制。我还在我的代码中使用了system.timestamp,并使用1或2行JavaScript策略解决了这个问题,该策略创建了一个名为systemTimestamp的新字符串变量。我目前不知道更好的解决方案。

相关问题