I will be performing XSLT transformations. I would like to use elements from the transformed XML to add to the headers. I would like to pull the ServiceHeader/ServiceName and the TrackingInfo/RequestId to accomplish this. The XML follows. I have not be able to figure that out. Any help would be great.
<Service>
<ServiceHeader>
<ServiceName>GetInfo</ServiceName>
<Operation>GetCustInfo</Operation>
</ServiceHeader>
<TrackingInfo>
<RequestId>1234567890</RequestId>
<RequestTs>01/02/2018 01:00:00.000</RequestTs>
</TrackingInfo>
<RequestInfo>
<Name>Any Name</Name>
</RequestInfo>
</Service>
1 Like
You said “I would like to pull the ServiceHeader/ServiceName and the TrackingInfo/RequestId”. I think your use of XSLT before or after “pulling” is irrelevant. Correct me if that is mistaken.
To do what you want in Apigee Edge - to extract information from an XML payload - you can use the ExtractVariables policy. For the XML document you have above, it would look something like this:
<ExtractVariables name='EV-1'>
<Source>contrivedMessage</Source>
<VariablePrefix>extracted</VariablePrefix>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<XMLPayload>
<Variable name='svcname' type='string'>
<XPath>/Service/ServiceHeader/ServiceName/text()</XPath>
</Variable>
<Variable name='requestid' type='string'>
<XPath>/Service/TrackingInfo/RequestId/text()</XPath>
</Variable>
</XMLPayload>
</ExtractVariables>
After you extract this data you can use AssignMessage to set headers with those values. Like this:
<AssignMessage name='AM-Response'>
<Set>
<Headers>
<Header name='ServiceName'>{extracted.svcname}</Header>
<Header name='RequestId'>{extracted.requestid}</Header>
</Headers>
<Payload contentType='application/json'>{
"status" : "ok"
}</Payload>
</Set>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew='false' transport='http' type='response'/>
</AssignMessage>
The result I see (note the response headers) :
$ curl -i [https://${ORG}-${ENV}.apigee.net/extractvariables-1/t1](https://${ORG}-${ENV}.apigee.net/extractvariables-1/t1)
HTTP/1.1 200 OK
Date: Thu, 29 Mar 2018 00:57:42 GMT
Content-Type: application/json
Content-Length: 23
Connection: keep-alive
ServiceName: GetInfo
RequestId: 1234567890
{
"status" : "ok"
}
See attached for a working API Proxy.
apiproxy-extractvariables-1-20180328-1804.zip