WSO2 ESB print all TRANSPORT_HEADERS

◇◆丶佛笑我妖孽 提交于 2019-12-08 09:00:14

问题


I can print individual transport headers in the WSO2 ESB with the following code inside a sequence:

<log level="custom">
    <property name="oneHeader" expression="$trp:FILE_NAME"/>
</log>

But I need to print all available transport properties. There is a axis2 property called "[TRANSPORT_HEADERS][1]", but when printing this property it is always empty.

<log level="custom">
    <property name="allHeaders" expression="get-property('axis2','TRANSPORT_HEADERS')"/>
</log>

Because I don't know all header names, I need to know how to print all transport headers?


回答1:


I don't know how to print all the transport properties, but if you set a breakpoint in your sequence and enable debugging as described in https://docs.wso2.com/display/EI611/Debugging+Mediation, you can find all the transport properties in the 'Variables' tab.




回答2:


We can't log this property using property mediator since this is an internal JAVA Map in axis2-transports. Hence We may need to use a class mediator for this purpose.

Following is a sample one.

You may place the class mediator jar directly in EI_HOME/lib or ESB_HOME/repository/components/lib and use the following config

<class name="org.sample.LogTransportHeaders"/>

in the proxy or API after adding following to log4j.properties file

log4j.logger.org.sample.LogTransportHeaders=INFO

Please refer here for further details : https://medium.com/@nirothipanram/wso2-ei-print-all-transport-headers-12aabb4027cc




回答3:


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.

for more.



来源:https://stackoverflow.com/questions/44132595/wso2-esb-print-all-transport-headers

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