This is the second example that demonstrates the ease of integrating security and reliable messaging to the WSO2 Application Server.
It demonstrates trading interactions between a stock exchange, trader (stock broker) and a client (shareholder). A shareholder who needs to buy and sell shares, should first become a client of that particular trader. A trader can register his client (the shareholder) in the stock exchange. Once registered, the shareholder uses his Central Depository System (CDS) account to buy and sell.
The following section describes the services offered by each party involved.
- Client creates an account with a trader and receives a user ID. The Trader registers the Client with the stock exchange using client information.
- The Client obtains a CDS account using which he is allowed to trade. The Client can only buy and sell shares on the market through the Trader who registered him/her.
- The Trader places the client's buying and selling orders in the stock exchange.
- The trader also registers feed targets to the Exchange.
- To access any of the services from the stock exchange, the Trader needs to first login to the Exchange using the Trader's username and password.
- The Clients get stock quotes (company name, symbol, selling price, high, low), and portfolio information from the Trader. He also deposits money in his account through the Trader.
- The User (shareholder) can directly gain market information such as total traded shares, average price, and average size of trade from the stock exchange.
- Trader provides market data updates to the stock exchange.
In summary the services are as follows:
1. Services offered by Stock Exchange to Trader
- Registering clients
- Logging in to Stock Exchange
- Buying and selling shares for Clients
- Registering feed targets
2. Services offered by Stock Exchange to Client
- Provide market information such as total traded shares, average price, average size of trade
3. Services offered by Trader to Client
- Create accounts
- Ability to make deposits to account
- Buying and selling shares
- Get stock quote (name, symbol, price, high, low) and portfolio
4. Services offered by Trader to Stock Exchange
- Provide market data updates
Note: Attributes of Stock Quote are name, symbol, selling price, high price and low price
Building the sample
The sample is located in
For more information, see Building Axis2 Samples .
The build automatically copies the
.aar file containing the service into the repository.
On the Main menu, under Services, click List. The Deployed Services page will appear with the ExchangeTrader, ExchangeClient, TraderClient and TraderExchange services deployed.
If you do not see the services deployed, wait for a while for the deployment engine of Axis2 to pick up the newly added
.aar and the refresh/reload the page.
Running the service
From the terminal go to
Execute one of the following commands to run the client:
OS Command MS Windows run-client.bat [ -qos (rm | secure | securerm)] [-te <TraderService URL>] [-ee <ExchangeService URL> ] Unix/Linux run-client.sh [ -qos (rm | secure | securerm)] [-te <TraderService URL>] [-ee <ExchangeService URL> ]
TraderService URL is the End Point Reference (EPR) of the TraderClient. This can be obtained from the Management Console.
Go to the " Deployed Services" window and click on the service "TraderClient". This will open up its dashboard, where you can find its endpoints. (under services column) > End Points. For this sample the default URLs for the standalone distribution and the embeddable version are as follows:
The same for ExchangeService, according to this example is as follows:
If rm, secure or securerm is to be used, the following modules should be engaged. This can be done by selecting the Engage Module option from the Service Information page for the services listed in the management console.
- rm - Sandesha (Sandesha2)
- secure - Security (Rampart)
- securerm - Both Sandesha and Security
- If security is used, the default username / password for the client is test / test123.
- The listed EPR's are for the stand-alone server. When WSO2 Application Server is running inside a servlet container, the EPR's are different. It is recommended to get the EPR through the management console.
The options shown above are illustrated using the following samples.
Example 1: Without any Module Engaged
Trader directory, type the following command:
You should see the following:
Example 2: With the Security Module Engaged
- Login to the Application Server Management Console.
- Add a user (under configure menu -> Users and Roles) named "test" with password "test123."
- Similarly, add a role "testrole" and add user "test" to that role.
- Provide all permissions for this role.
- Then go to the "Deployed Services" window in the AS Management Console. (Manage > Service > List).
- Access the dashboard of the service "TraderClient" service by clicking on it.
- In the dashboard, under "Security," select "Username Token." Press "Next."
- Then select "testrole" from the user groups listed.
- Click "Finish."
Follow the same steps for ExchangeClient service. Then go to
<AS_HOME>/samples/Trader directory and type: ./run-client.sh -qos secure . You would see a prompt asking for the username and password before listing the operations available as follows:
Example 3: Creating an account
Example 4: Depositing money in the exchange
Sample 5: Buying '100 mn' stocks in the exchange
Example 6: Selling '50 mn' stocks in the exchange
Example 7: Getting the portfolio of the user 'test1' after buying a further '200 h' stocks
Similarly, you can explore the options available in the Trader client and see how it works for yourself.
Trader service internally calls the Stock exchange services. Since the internally-used stubs try to use the configuration of the container by default, engaging QoS on the Stock Exchange service will break the trader sample. Therefore, for the trader sample to run properly, QoS should not be engaged on the Stock Exchange service.
The WSDL files of the services can be found in: <AS_HOME>\samples\Trader\wsdl