Search code examples
apigee

Load flow variables with non-string values in ApiGEE


I need to save the value of the system variable "system.timestamp" into a flow variable. (The idea is to obtain the duration of some callout policies in between)

However, I can't read it because the AssignMessage policy raises the fault:

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

Neither Long nor Integer values can be read, only strings, which is kind of strange because what would be the case of exposing variables one cannot read?

I am trying to avoid the "non elegant" Javascript policy, if that is possible at all, so here's the [very basic] AssignMessage policy I'm using to read the value:

<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 variable is documented here: http://apigee.com/docs/api-services/reference/variables-reference#-a-class-jumplink-name-system-a-system-variables


Solution

  • If the AssignMessage policy doesn't work, you should be able to accomplish this using a JavaScript policy. That would allow you to convert the timestamp to whatever form it needs to be. Similarly, a JavaScript policy could be used to do any timing calculations or manipulations later on in the proxy.