Apigee - 键值映射 - 使用变量键的麻烦

时间:2015-04-17 16:59:24

标签: apigee

这是非常基本的,但我正在努力尝试从keyvaluemap构建/检索值。例如给定变量X和Y,其中X = 123abc,第一次执行时Y = foo,X = 456def,第二次执行时Y = bar,我希望有一个键值映射,其中[123abc] - > [foo]和[456def] - > [巴]。

但是,当我尝试使用X的值检索变量Z中的值时,我总是得到最后一个值:Z = bar。如果我删除键X = 456def,则检索键X = 123abc将返回错误,该键不存在。

我的猜测是,地图中只构建了一个值,并且它会被放入""好像没有设置变量。覆盖值" true"正在用最后一个附加值替换它。我确信该变量具有一个值,因为它在跟踪中的先前策略执行中正确显示。

语法中有什么东西吗?有什么想法吗?

我正在使用以下政策来构建密钥

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations mapIdentifier="map1" enabled="true" continueOnError="false" async="false" name="buildmap1">
    <DisplayName>build map1</DisplayName>
    <FaultRules/>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
    <InitialEntries/>
    <Put override="true">
        <Key>
            <Parameter>ref="X"</Parameter>
        </Key>
        <Value ref="Y"></Value>
    </Put>
    <Scope>organization</Scope>
</KeyValueMapOperations>

我使用以下内容检索密钥

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations mapIdentifier="map1" enabled="true" continueOnError="false" async="false" name="getmap1">
    <DisplayName>get map1</DisplayName>
    <FaultRules/>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
    <InitialEntries/>
    <Get assignTo="Z">
        <Key>
            <Parameter>ref="X"</Parameter>
        </Key>
    </Get>
    <Scope>organization</Scope>
</KeyValueMapOperations>

1 个答案:

答案 0 :(得分:0)

请查看https://community.apigee.com/articles/3384/keyvaluemap-kvmap-operations.html

上的文章
<Parameter ref='X'></Parameter>

其中X是变量。但是,您还希望使用两个变量构建复合键

<Parameter ref='X-Y'></Parameter>

不起作用。您需要使用Javascript策略来构建该组合密钥。

相关问题