如何在 esb 中读取 http 标头 [英] how to read http headers in esb
问题描述
如何将属性设置为传入的 http 请求标头的值?我尝试了一些事情(见下文),但我的日志值都是空的,所以我显然没有正确读取标题值.我真正关心的标头值是 X-EMPID.使用 wso2esb 4.8.1.
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>
推荐答案
通过使用 XPath 变量,您可以方便地访问 HTTP 标头,技术上是 WSO2 ESB 中的传输标头.读取名为 X-EMPID
的 HTTP 标头的最简单方法是使用以下 XPath:$trp:X-EMPID
,其中 $trp
前缀表示冒号后面的部分是传输属性的名称.要记录标头值,您可以使用以下日志中介:
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>
要将属性 myProperty
设置为 X-EMPID
HTTP 标头(已存储在传输属性中)的值,您可以使用属性中介:
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" />
WSO2 网站上记录了该功能.
这篇关于如何在 esb 中读取 http 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!