Versions Compared

Key

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

...

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

    Note the property, <property xmlns:m0=" http://services.samples " name="stockprop" expression="$body/m0:getQuote"/> in the configuration. It is used to log the first <m0:getQuote> element of the request SOAP body.

    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>
             <log>
                <property xmlns:m0="http://services.samples" name="stockprop" expression="$body/m0:getQuote"/>
             </log>
             <send>
                <endpoint>
                   <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                </endpoint>
             </send>
          </inSequence>
          <outSequence>
             <send/>
          </outSequence>
       </target>
       <description></description>
    </proxy> 
  2. Send the following StockQuote request using the sample StockQuote client. For information on working with the sample client, see Using the Sample Clients.

    Code Block
    languagexml
    ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy
  3. Note the following message in the log.

    Code Block
    [2013-03-18 14:04:41,019] INFO - LogMediator To: /services/StockQuoteProxy, WSAction: urn:getQuote, SOAPAction: urn:getQuote, ReplyTo: http://www.w3.org/2005/08/addressing/anonymous, MessageID: urn:uuid:930f68f5-199a-4eff-90d2-ea679c2362ab, Direction: request, stockprop = <m0:getQuotexmlns:m0="http://services.samples"><m0:request><m0:symbol>IBM</m0:symbol></m0:request></m0:getQuote>

...

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

    Note the property, <property xmlns:wsa=" http://www.w3.org/2005/08/addressing " name="stockprop" expression="$header/wsa:To"/> in the configuration. It is used to log the value of wsa:To header of the SOAP request. 

    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>
             <log>
                <property xmlns:wsa="http://www.w3.org/2005/08/addressing" name="stockprop" expression="$header/wsa:To"/>
             </log>
             <send>
                <endpoint>
                   <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                </endpoint>
             </send>
          </inSequence>
          <outSequence>
             <send/>
          </outSequence>
       </target>
       <description></description>
    </proxy> 
  2. Send the following StockQuote request using the sample StockQuote client. For information on working with the sample client, see Using the Sample Clients.

    Code Block
    languagexml
    ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy
  3. Note the following message in the log.

    Code Block
    [2013-03-18 14:14:16,356] INFO - LogMediator To: http://localhost:9000/services/SimpleStockQuoteService, WSAction: urn:getQuote, SOAPAction: urn:getQuote, ReplyTo: http://www.w3.org/2005/08/addressing/anonymous, MessageID: urn:uuid:8a64c9cb-b82f-4d6f-a45d-bef37f8b664a, Direction: request,
    stockprop = http://localhost:9000/services/SimpleStockQuoteService

...

  1. Deploy the following proxy service using instructions in Adding a 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. 

    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>
             <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 following StockQuote request using the sample StockQuote client. For information on working with the sample client, see Using the Sample Clients.

    Code Block
    languagexml
    ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy/test/prefix
  3. Note the following message in the log.

    Code Block
    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

...

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

$ctx

Prefix for Synapse MessageContext properties and gets a property at the default scope. 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.

...

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

    Note the property, <property name="stockerrorprop" expression="$ctx: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 the following StockQuote request using the sample StockQuote client. For information on working with the sample client, see Using the Sample Clients.

    Code Block
    languagexml
    ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuoteProxy
  3. Note the following message in the 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.

...

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

    Note the property, <property name="stockprop" expression="$trp:Content-Type"/> in the configuration, which is used to log the Content-Type HTTP header of the request message.

    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>
             <log>
                 <property name="stockprop" expression="$trp:Content-Type"/>
             </log>
             <send>
                <endpoint>
                   <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                </endpoint>
             </send>
          </inSequence>
          <outSequence>
             <send/>
          </outSequence>
       </target>
       <description></description>
    </proxy> 

     

  2. Send the following StockQuote request using the sample StockQuote client. For information on working with the sample client, see Using the Sample Clients.

    Code Block
    languagexml
    ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy

     

  3. Note the following message in the log.

    Code Block
    [2013-03-18 12:23:14,101] INFO - LogMediator To: http://localhost:8280/services/StockQuoteProxy, WSAction: urn:getQuote, SOAPAction: urn:getQuote, ReplyTo: http://www.w3.org/2005/08/addressing/anonymous, MessageID: urn:uuid:25a3143a-5b18-4cbb-b8e4-27d4dd1895d2, Direction: request, stockprop = text/xml; charset=UTF-8 

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.

$url

The prefix used to get the URI element of a request URL.

...

  1. Create a REST API with the following configuration using instructions given in page Working with APIs.

    Code Block
    languagexml
    <api xmlns="http://ws.apache.org/ns/synapse" name="Editing" context="/editing">
       <resource methods="GET" uri-template="/edit?a={symbol}&b={value}">
          <inSequence>
             <log level="full">
                <property name="SYMBOL" expression="$url:a"></property>
                <property name="VALUE" expression="$url:b"></property>
             </log>
             <respond></respond>
          </inSequence>
       </resource>
    </api>
  2. Send a request to the REST API you created using a browser as follows:

    Code Block
    languagexml
     http://10.100.5.73:8280/editing/edit?a=wso2&b=2.4

    You will see the following in the log:
     

    Code Block
    languagexml
    LogMediator To: /editing/edit?a=wso2&b=2.4, MessageID: urn:uuid:36cb5ad7-f150-490d-897a-ee7b86a9307d, Direction: request, SYMBOL = wso2, VALUE = 2.4, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body></soapenv:Body></soapenv:Envelope>

...

The prefix used to refer to a particular parameter value passed externally by an invoker such as the Call Template Mediator.

Example of $func usage:

  1. Add a sequence template with the following configuration. See Adding a New Sequence Template for detailed instructions.

    Code Block
    languagexml
    <template xmlns="http://ws.apache.org/ns/synapse" name="HelloWordLogger">
       <sequence>
          <log level="full">
             <property xmlns:ns2="http://org.apache.synapse/xsd" xmlns:ns="http://org.apache.synapse/xsd" name="message" expression="$func:message"></property>
          </log>
       </sequence>
    </template>
  2. Deploy the following proxy service using instructions given in section  Adding a Proxy Service .

    Code Block
    languagexml
    <proxy xmlns="http://ws.apache.org/ns/synapse"
           name="StockQuoteProxy"
           transports="https,http"
           statistics="disable"
           trace="disable"
           startOnLoad="true">
       <target>
          <inSequence>
             <call-template target="HelloWorldLogger">
                <with-param name="message" value="HelloWorld"/>
             </call-template>
             <log/>
          </inSequence>
          <outSequence>
             <send/>
          </outSequence>
          <endpoint>
             <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
          </endpoint>
       </target>
       <description/>
    </proxy>
  3. Send the following StockQuote request using the sample StockQuote client. For information on working with the sample client, see Using the Sample Clients.

    Code Block
    languagexml
    ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy
  4. Note the following message in the log.

    Code Block
    languagexml
    LogMediator To: http://localhost:8280/services/StockQuoteProxy, WSAction: urn:getQuote, SOAPAction: urn:getQuote, ReplyTo: http://www.w3.org/2005/08/addressing/anonymous, MessageID: urn:uuid:8d90e21b-b5cc-4a02-98e2-24b324fa704c, Direction: request, message = HelloWorld

...

  1. Create an API with the following configuration. For information on how to create an API, see Working with APIs.

    Code Block
    languagexml
    <api context="/soapEnvelopeTest" name="SoapEnvelopeTest">
            <resource url-mapping="/*">
                <inSequence>
                    <loopback/>
                </inSequence>
                <outSequence>
                    <property name="messageType" scope="axis2" value="application/xml"/>
                    <payloadFactory media-type="xml">
                        <format>
                            <theData xmlns="http://some.namespace">
                                <item>$1</item>
                            </theData>
                        </format>
                        <args>
                            <arg evaluator="xml" expression="$env/*[local-name()='Body']/*[local-name()='jsonObject']/*"/>
                    </payloadFactory>
                    <property name="messageType" scope="axis2" value="application/json"/>
                    <send/>
                </outSequence>
            </resource>
    </api>
  2. Send a post request to the API you created (i.e.,http://localhost:8280/soapEnvelopeTest), with the following json payload using a rest client.

    Code Block
    languagexml
     {"content":{ "paramA": "ValueA", "paramB": "valueB" }}

    You will receive the following response:

    Code Block
    languagexml
    {"theData":{"item":{"content":{"paramA":"ValueA","paramB":"valueB"}}}}

...