how to read http headers in esb

不羁的心 提交于 2019-11-27 07:13:51

问题


How do I set a property to the value of an incoming http request header? I tried a few things (see following), but my log values are all null, so I'm clearly not reading the header values correctly. The header value I really care about is X-EMPID. Using wso2esb 4.8.1.

Here are a couple of posts that led me to believe this would work, but I'm not having any luck yet.

<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="getaccount2"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="empid"
                   expression="get-property('transport', 'X-EMPID')"
                   scope="default"
                   type="STRING"/>
         <log level="custom">
            <property name="emp_id" expression="get-property('empid')"/>
         </log>
         <log level="custom">
            <property name="content_length"
                      expression="get-property('transport', 'Content-Length')"/>
         </log>
         <log level="custom">
            <property name="TRANSPORT_HEADERS" expression="get-property('TRANSPORT_HEADERS')"/>
         </log>

回答1:


You can conveniently access HTTP headers, which technically are transport headers in WSO2 ESB, by using XPath variables. The easiest way to read an HTTP header named X-EMPID is by using the following XPath: $trp:X-EMPID, where the $trp prefix indicates that the part following the colon is the name of a transport property. To log the header value you could use the following log mediator:

<log level="custom">
    <property name="X-EMPID value" expression="$trp:X-EMPID" />
</log>

To set the property myProperty to the value of X-EMPID HTTP header (which is already stored in a transport property) you would use the property mediator:

<property name="myProperty" expression="$trp:X-EMPID" />

The functionality is documented on the WSO2 site.



来源:https://stackoverflow.com/questions/25854766/how-to-read-http-headers-in-esb

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