问题
There is a custom attribute assigned to a developer called '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? The example given in the tutorial doc is not very clear.
I have the following configurations that are not working. 'XYZ' is the name of the developer's custom attribute:
AccessEntity policy-
<?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 -
<?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 -
<?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");
回答1:
The EntityIdentifier ref in AccessEntity refers to a variable that identifies the developer to be referenced. There are multiple types of data you can pass in to identify the developer (developeremail, developerid, appid, consumerkey). It is best to include the type of data being used in the EntityIdentifier element. In the example below, the consumer key is stored in the variable 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. You need curly braces around the variable name, otherwise the payload will be the text "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.
来源:https://stackoverflow.com/questions/21948465/in-apigee-how-to-get-a-custom-attribute-value-for-a-developer-using-the-accesse