为开发人员分配了一个名为“XYZ”的自定义属性。在API代理中,如何使用AccessEntity策略(以及教程中给出的AssignMessage和ExtractVariable策略:http://apigee.com/docs/api-services/content/retrieve-entity-profiles-using-accessentity)来检索它的值,以便可以在Javascript中进一步访问它?教程文档中给出的示例不是很清楚。
我有以下配置不起作用。 'XYZ'是开发人员自定义属性的名称:
AccessEntity政策 -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccessEntity async="false" continueOnError="false" enabled="true" name="access-developer-attribute">
<DisplayName>AccessEntity Developer Attribute</DisplayName>
<FaultRules/>
<Properties/>
<EntityIdentifier ref="XYZ"></EntityIdentifier>
<EntityType value="developer"></EntityType>
</AccessEntity>
AssignMessage政策 -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="convert-accessentity-xml-to-message-request">
<DisplayName>Convert AccessEntity Xml To Message Request</DisplayName>
<FaultRules/>
<Properties/>
<Set>
<Headers/>
<QueryParams/>
<FormParams/>
<Verb/>
<Path/>
<Payload type="text/xml">AccessEntity.access-developer-attribute</Payload>
</Set>
<AssignVariable>
<Name>name</Name>
<Value/>
<Ref/>
</AssignVariable>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="true" transport="http" type="request">accessentity.XYZ-attribute</AssignTo>
</AssignMessage>
ExtractVariables政策 -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="retrieve-developer-attribute">
<DisplayName>Retrieve Developer Domain</DisplayName>
<FaultRules/>
<Properties/>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<Source>accessentity.XYZ-attribute</Source>
<VariablePrefix>developer_attribute</VariablePrefix>
<XMLPayload stopPayloadProcessing="false">
<Namespaces/>
<Variable name="xyz" type="string">
<XPath>/Developer/Attributes/XYZ</XPath>
</Variable>
</XMLPayload>
</ExtractVariables>
Javascript -
var xyzValue = context.getVariable("developer_attribute.xyz");
答案 0 :(得分:1)
AccessEntity中的EntityIdentifier引用了一个标识要引用的开发人员的变量。您可以传递多种类型的数据来识别开发人员(developeremail,developerid,appid,consumerkey)。最好包括EntityIdentifier元素中使用的数据类型。在下面的示例中,使用者密钥存储在变量client_id中:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccessEntity async="false" continueOnError="false" enabled="true" name="access-developer-attribute">
<DisplayName>AccessEntity Developer Attribute</DisplayName>
<EntityIdentifier ref="client_id" type="consumerkey"></EntityIdentifier>
<EntityType value="developer"></EntityType>
</AccessEntity>
此外,您的AssignMessage策略未从AccessEntity.access-developer-attribute变量中正确检索。您需要围绕变量名称使用花括号,否则有效内容将是文本“AccessEntity.access-developer-attribute”。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="convert-accessentity-xml-to-message-request">
<DisplayName>Convert AccessEntity Xml To Message Request</DisplayName>
<Set>
<Payload type="text/xml">{AccessEntity.access-developer-attribute}</Payload>
</Set>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="true" transport="http" type="request">accessentity.XYZ-attribute</AssignTo>
</AssignMessage>
您还会注意到我删除了政策中未使用的字段。这使得政策更具可读性。
您的ExtractVariables和JavaScript应该可以正常工作。