This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

WSO2 ESB supports standard XPath functions and variables through its underlying XPath engine. The ESB also provides custom XPath functions and variables for accessing message properties.

XPath extension functions

There are two custom functions supported by the ESB as follows:

  1. synapse:get-property() function
  2. base64Encode() function

synapse:get-property()

The get-property() function allows any XPath expression used in a configuration to look up information from the current message context. Using property mediator, you can retrieve properties previously set, and/or information from the Synapse, Axis2 message contexts or transport header.

The syntax of the function takes the following format.

  • get-property(String propertyName)
  • get-property(String scope, String propertyName)

The function accepts scope as an optional parameter. It retrieves a message property at the given scope, which can be synapse, axis2 or transport. If you provide only the property name without the scope, the default Synapse scope will be used.

 

synapse:get-property( [(axis2 | axis2-client | transport),] <property_name> [,<dateformat>] )

You can use the get-property() function to retrieve Axis2 message context properties or transport headers. For example, synapse:get-property('transport', 'USER_AGENT'). Given below are special properties supported by the get-property() function.

NameReturn Value
ToIncoming URL as a String or empty string («») if a To address is not defined.
FromFrom address as a String or empty string («») if a From address is not defined
ActionSOAP Addressing Action header value as a String or empty string («») if a Action is not defined
FaultToSOAP FautTo header value as a String or empty string («») if a FaultTo address is not defined
ReplyToReplyTo header value as a String or empty string («») if a ReplyTo address is not defined
MessageIDA unique identifier (UUID) for the message as a String or empty string («») if MessageID is not defined. This id is guaranteed to be unique.
FAULTTRUE if the message has a fault or empty string if message doesn't have a fault
MESSAGE_FORMATReturns pox, get, soap11, soap12 depending on the message. If a message type is unknown this returns soap12
OperationNameOperation name corresponding to the message. A proxy service with a WSDL can have different operations. If the WSDL is not defined ESB defines fixed operations

base64Encode() function

The syntax of the function takes the following format.

  • base64Encode(string)

It returns the base64 encoded value of the string argument.

Synapse XPath variables

There is a set of predefined XPath variables that you can directly use to write XPaths in the Synapse configuration, instead of using the synapse:get-property() function. These XPath variables get properties of various scopes as follows:

body

The SOAP 1.1 or 1.2 body element. For example, expression="$body/getQuote" refers to the first getQuote element in the SOAP body regardless of whether the message is SOAP-11 or SOAP-12.

Header

The SOAP 1.1 or 1.2 header element. For example, expression="$header/wsa:To refers to the addressing To header regardless of whether this message is SOAP-11 or SOAP-12.

axis2

Gets the property at the axis2 scope.

For example, to get the property named 'messageType' use the following XPath expression:

$axis2:messageType

 

 

Prefix for Axis2 MessageContext properties. For example, expression="$axis2:REST_URL_POSTFIX" gives the value of the axis2 message context property with name REST_URL_POSTFIX. We have discussed an example below.

1. Deploy the following proxy service.

Note the property, <property name="stockprop" expression="$axis2:REST_URL_POSTFIX"/> in the configuration which is used to log the REST_URL_POSTFIX value of the request message.

<proxy xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <log>
            <property name="stockprop" expression="$axis2:REST_URL_POSTFIX"/>
         </log>
         <send>
            <endpoint>
              <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description></description>
</proxy>

2. Send the StockQuoteRequest using sample stockquote client as follows.

ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy/test/prefix 

3. Note the following message in the ESB log.

INFO - LogMediator To: http://localhost:8280/services/StockQuoteProxy/test/prefix, WSAction: urn:getQuote, SOAPAction: urn:getQuote, ReplyTo: http://www.w3.org/2005/08/addressing/anonymous, MessageID: urn:uuid:ecd228c5-106a-4448-9c83-3b1e957e2fe5, Direction: request, stockprop = /test/prefix

In this example, the property definition, <property name="stockprop" expression="$axis2:REST_URL_POSTFIX"/> is equivalent to <property name="stockprop" expression="get-property('axis2','REST_URL_POSTFIX')"/>

Similarly, you can use $axis2 prefix with HTTP Transport Properties.

ctx

Prefix for Synapse MessageContext properties. For example, expression="$ctx:RESPONSE" gives the value of the Synapse message context property with name "RESPONSE."

trp

Prefix for the transport headers. For example, expression="$trp:Content-Type" gives the value of the "Content-Type" transport header, which is going to be the Content-Type of the current message.

 

 

 

$axis2

 

$trp

Gets a transport header.

For example, to get the transport header named Content-Type use the following XPath expression:

$trp:Content-Type

HTTP transport headers are case-insensitive, so in the HTTP case,

$trp:Content-Type 

and

$trp:CONTENT-TYPE 

are equal.

$ctx

Gets a property at the default scope.

For example, to get the property named 'foo' at the default scope use the following XPath expression:

$ctx:foo

$url

Gets a URL parameter.

For example, to get the URL parameter named 'bar' use the following XPath expression:

$url:foo

 

 

 

 

 

 

 

 

 

Syntax

<property name="string" [action=set|remove] (value="literal" | expression="xpath") [scope=transport|axis2|axis2-client]/>
  • No labels