简体   繁体   English

在Apigee中,如何使用AccessEntity策略以及稍后在Javascript中为开发人员获取自定义属性值?

[英]In Apigee, how to get a custom attribute value for a developer using the AccessEntity policy and later in Javascript?

There is a custom attribute assigned to a developer called 'XYZ'. 有一个自定义属性分配给名为“XYZ”的开发人员。 In the API proxy, how can the AccessEntity policy (along with the AssignMessage and ExtractVariable policies as given in the tutorial: http://apigee.com/docs/api-services/content/retrieve-entity-profiles-using-accessentity ) be used to retrieve the value for it so that it can be accessed further in Javascript? 在API代理中,AccessEntity策略如何(以及教程中给出的AssignMessage和ExtractVariable策略: http ://apigee.com/docs/api-services/content/retrieve-entity-profiles-using-accessentity)用于检索它的值,以便可以在Javascript中进一步访问它? The example given in the tutorial doc is not very clear. 教程doc中给出的示例不是很清楚。

I have the following configurations that are not working. 我有以下配置不起作用。 'XYZ' is the name of the developer's custom attribute: 'XYZ'是开发人员自定义属性的名称:

AccessEntity policy- 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 policy - 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 policy - 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 - Javascript -

var xyzValue = context.getVariable("developer_attribute.xyz");

The EntityIdentifier ref in AccessEntity refers to a variable that identifies the developer to be referenced. AccessEntity中的EntityIdentifier引用了一个标识要引用的开发人员的变量。 There are multiple types of data you can pass in to identify the developer (developeremail, developerid, appid, consumerkey). 您可以传递多种类型的数据来识别开发人员(developeremail,developerid,appid,consumerkey)。 It is best to include the type of data being used in the EntityIdentifier element. 最好包括EntityIdentifier元素中使用的数据类型。 In the example below, the consumer key is stored in the variable client_id: 在下面的示例中,使用者密钥存储在变量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>

Also, your AssignMessage policy is not correctly retrieving from the AccessEntity.access-developer-attribute variable. 此外,您的AssignMessage策略未正确从AccessEntity.access-developer-attribute变量中检索。 You need curly braces around the variable name, otherwise the payload will be the text "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>

You'll notice also that I've deleted unused fields in the policies. 您还会注意到我已删除了策略中未使用的字段。 This makes the policies more readable. 这使得策略更具可读性。

Your ExtractVariables and JavaScript should work fine. 您的ExtractVariables和JavaScript应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM