All docs This doc
Skip to end of metadata
Go to start of metadata


This sample demonstrates how you can use the ESB to connect to endpoints with WS-Security for outgoing messages.

In this sample the stock quote client sends a request without WS-Security. The ESB is configured to enable WS-Security as per the policy specified in the policy_3.xml file, for outgoing messages to the SecureStockQuoteService endpoint hosted on the Axis2 instance.


Building the sample

The XML configuration for this sample is as follows: 

<definitions xmlns="">
    <localEntry key="sec_policy" src="file:repository/samples/resources/policy/policy_3.xml"/>
    <sequence name="main">
                <endpoint name="secure">
                    <address uri="http://localhost:9000/services/SecureStockQuoteService">
                        <enableSec policy="sec_policy"/>
            <header name="wsse:Security" action="remove"

This configuration file  synapse_sample_100.xml is available in the <ESB_HOME>/repository/samples directory.

To build the sample

  1. Start the ESB with the sample 100 configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration.

    The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."

  2. Start the Axis2 server. For instructions on starting the Axis2 server, see Starting the Axis2 server.

  3. Deploy the back-end service  SecureStockQuoteService. For instructions on deploying sample back-end services, see Deploying sample back-end services.

Executing the sample

The sample client used here is the Stock Quote Client, which can operate in several modes. For further details on this sample client and its operation modes, see Stock Quote Client.

To execute the sample client

  • Run the following command from the <ESB_HOME>/samples/axis2Client directory.

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

Analyzing the output

When you analyze the debug log output on the ESB console, you will see the encrypted message flowing to the service and the encrypted response being received by the ESB. You will also see that the wsse:Security header is removed from the decrypted message and the response is delivered back to the client, as expected. 

If you use TCPMon and send the message through it, you will see the message sent by the ESB to the secure service as follows:

POST http://localhost:9001/services/SecureStockQuoteService HTTP/1.1
SOAPAction: urn:getQuote
Content-Type: text/xml; charset=UTF-8
Transfer-Encoding: chunked
Connection: Keep-Alive
User-Agent: Synapse-HttpComponents-NIO

<?xml version='1.0' encoding='UTF-8'?>
   <soapenv:Envelope xmlns:xenc="" xmlns:wsa="" ..>
         <wsse:Security ..>
            <wsu:Timestamp ..>
            <wsse:BinarySecurityToken ...>
               <ds:KeyInfo Id="KeyId-29551621">
      <soapenv:Body xmlns:wsu="" wsu:Id="Id-3789605">
         <xenc:EncryptedData Id="EncDataId-3789605" Type="">
            <xenc:EncryptionMethod Algorithm="" />

  • No labels