How do you correctly return Location headers and do HATEOAS with Apigee?

女生的网名这么多〃 提交于 2019-12-12 04:57:18

问题


Our Apigee configuration looks a little like this:

Netscaler LB -> Apigee Router/Message Processor -> Netscaler LB - Target Server(s)

The target server in this case is a Java appliation with Jersey, and I'm using the Jersey @Context to retrieve the relevant URI info to set for example Location headers, but all the request details seem to relate to the Netscaler and not the originating request.

If we use an AssignMessage policy and manually set the X-Forwarded-Host URL to be the URL the client calls then everything works as it should do. Unfortunately there doesn't seem to be a variable we can use instead of hardcoding this - everything in the docs around the variables seems to indicate you can only get the paths after the domain itself.


回答1:


While in the <ProxyEnpoint> request segment, you can reference the variable request.header.host and it will give you the host that the client requested into Apigee.

For example, if you URI is https://myorg-test.apigee.net/resource, request.header.host in the request segment of the ProxyEndpoint will have a value of myorg-test.apigee.net.

If you try to reference this in the TargetEndpoint, it may already be overwritten to with the backend host for the target request. If you need it in the TargetEndpoint, assign it to a variable first in the ProxyEndpoint/PreFlow/Request and you can later reference the variable originalHost:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="grabOriginalHost">
    <AssignVariable>
        <Name>originalHost</Name>
      <Ref>request.header.host</Ref>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>


来源:https://stackoverflow.com/questions/24572542/how-do-you-correctly-return-location-headers-and-do-hateoas-with-apigee

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!