इस उदाहरण में, Assign Message की तीन नीतियों का इस्तेमाल किया गया है:
<!-- Policy #1: Set variables in the request --> <AssignMessage name="AM-set-variables"> <!-- Create a variable named myAppSecret --> <AssignVariable> <Name>myAppSecret</Name> <Value>42</Value> </AssignVariable> <!-- Create a variable named config.environment --> <AssignVariable> <Name>config.environment</Name> <Value>test</Value> </AssignVariable> <!-- Create a variable named config.protocol --> <AssignVariable> <Name>config.protocol</Name> <Value>gopher</Value> </AssignVariable> </AssignMessage>
पहली नीति में, <AssignVariable> एलिमेंट, अनुरोध में तीन वैरिएबल बनाता है और उन्हें सेट करता है. हर <Name> एलिमेंट, वैरिएबल का नाम तय करता है. वहीं, <Value> वैल्यू तय करता है.
दूसरी नीति, वैल्यू को पढ़ने के लिए <AssignVariable> एलिमेंट का इस्तेमाल करती है. साथ ही, तीन नए वैरिएबल बनाती है:
<!-- Policy #2: Get variables from the request --> <AssignMessage continueOnError="false" enabled="true" name="get-variables"> <AssignTo createNew="false" transport="http" type="request"/> <!-- Get the value of myAppSecret and create a new variable, secret --> <AssignVariable> <Name>secret</Name> <Ref>myAppSecret</Ref> <Value>0</Value> </AssignVariable> <!-- Get the value of config.environment and create a new variable, environment --> <AssignVariable> <Name>environment</Name> <Ref>config.environment</Ref> <Value>default</Value> </AssignVariable> <!-- Get the value of config.protocol and create a new variable, protocol --> <AssignVariable> <Name>protocol</Name> <Ref>config.protocol</Ref> <Value>default</Value> </AssignVariable> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </AssignMessage>
दूसरी नीति में, <Ref> एलिमेंट, सोर्स वैरिएबल का रेफ़रंस देता है. साथ ही, <Name> एलिमेंट, नए वैरिएबल के नाम तय करते हैं. अगर <Ref> एलिमेंट से रेफ़र किया गया वैरिएबल ऐक्सेस नहीं किया जा सकता, तो <Value> एलिमेंट से तय की गई वैल्यू का इस्तेमाल किया जा सकता है.
नीतियों के इस सेट को आज़माने के लिए:
<Set> एलिमेंट का इस्तेमाल किया गया है. यहां दिए गए उदाहरण में, रिस्पॉन्स में एक एक्सएमएल पेलोड बनाया गया है. यह पेलोड, Edge क्लाइंट को वापस भेजता है:
<!-- Policy #3: Add variables to the response --> <AssignMessage continueOnError="false" enabled="true" name="put-em-in-the-payload"> <DisplayName>put-em-in-the-payload</DisplayName> <Set> <Payload contentType="application/xml"> <wrapper> <secret>{secret}</secret> <config> <environment>{environment}</environment> <protocol>{protocol}</protocol> </config> </wrapper> </Payload> </Set> <IgnoreUnresolvedVariables>true </IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="response"/> </AssignMessage>
ध्यान दें कि <Set> में फ़्लो वैरिएबल को ऐक्सेस करने का सिंटैक्स, उन्हें कर्ली ब्रैकेट में रैप करना है.
<Payload> एलिमेंट के contentType एट्रिब्यूट को "application/xml" पर सेट करना न भूलें.
curl -vL https://ahamilton-eval-test.apigee.net/myproxy
इसके अलावा, नतीजों को xmllint जैसे किसी यूटिलिटी के ज़रिए पाइप किया जा सकता है, ताकि एक्सएमएल को अच्छी तरह से फ़ॉर्मैट किए गए स्ट्रक्चर में दिखाया जा सके:
curl -vL https://ahamilton-eval-test.apigee.net/myproxy | xmllint --format -
जवाब का मुख्य हिस्सा कुछ ऐसा दिखना चाहिए:
<wrapper>
<secret>42</secret>
<config>
<environment>test</environment>
<protocol>gopher</protocol>
</config>
</wrapper>