Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

wso2 - how to read http headers in esb

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...