Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

...

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

...

$ctx

Prefix for Synapse MessageContext properties. For example, to get the value of Synapse message context property with name ERROR_MESSAGE, use the XPath expression $ctx:ERROR_MESSAGE. We have discussed an example below.

Example of $ctx usage:

This example sends a request to a sample proxy service, and sets the target endpoint to a non-existent endpoint reference key. It causes a mediation fault, which triggers the fault sequence.

1. Deploy the following proxy service using instructions in Adding a Proxy Service.

Note the property, <property name="stockerrorprop" expression="$ctx:RESPONSE" gives the value of the Synapse message context property with name "RESPONSE."ERROR_MESSAGE"/> in the fault sequence configuration. It is used to log the error message that occurs due to a  mediation fault.

Code Block
languagehtml/xml
<proxy xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
        <send>
            <endpoint key="ep2"/>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
      <faultSequence>
         <log>
            <property name="stockerrorprop" expression="$ctx:ERROR_MESSAGE"/>
            <property name="Cause" expression="get-property('ERROR_MESSAGE')"/>
         </log>
      </faultSequence>
   </target>
   <description></description>
</proxy> 

2. Send a StockQuote request using the sample StockQuote client as follows.

ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuoteProxy

3. Note the following message in the ESB log.

Code Block
INFO - LogMediator To: /services/StockQuoteProxy, WSAction: urn:getQuote, SOAPAction: urn:getQuote, ReplyTo: http://www.w3.org/2005/08/addressing/anonymous, MessageID: urn:uuid:54205f7d-359b-4e82-9099-0f8e3bf9d014, Direction: request, stockerrorprop = Couldn't find the endpoint with the key : ep2 

In this example, the property definition, <property name="stockerrorprop" expression="$ctx:ERROR_MESSAGE"/> is equivalent to <property name="stockerrorprop" expression="get-property('ERROR_MESSAGE')"/>.

Similarly, you can use $ctx prefix with Generic Properties.

$trp

Prefix used to get the transport headers. For example, to get the transport header named Content-Type of the current message, use the XPath expression $trp:Content-Type. HTTP transport headers are not case sensitive. Therefore, $trp:Content-Type and $trp:CONTENT-TYPE are regarded as the same. We have discussed an example below.

...

In this example, the property definition, <property name="stockprop" expression="$trp:Content-Type"/> is equivalent to <property name="stockprop" expression="get-property('transport','Content-Type')"/>. Similarly, you can use $trp prefix with HTTP Transport Properties.

$ctx

Gets a property at the default scope.

...