【问题标题】:Apigee - key value map - trouble using a variable keyApigee - 键值映射 - 使用变量键的麻烦
【发布时间】:2015-04-17 16:59:23
【问题描述】:

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

但是,当我尝试使用 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>

【问题讨论】:

    标签: apigee


    【解决方案1】:

    请看https://community.apigee.com/articles/3384/keyvaluemap-kvmap-operations.html上的文章

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

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

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

    不会工作。您将需要使用 Javascript 策略来构建该复合键。

    【讨论】:

    • 请在此链接中添加一些上下文。 “鼓励链接到外部资源,但请在链接周围添加上下文,以便您的其他用户了解它是什么以及为什么存在。始终引用重要链接的最相关部分,以防目标站点无法访问或永久离线。”来自How to answer
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 2014-11-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    相关资源
    最近更新 更多