Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Table of Contents

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.

Scenario Description

...

  1. Client creates an account with a trader and receives a user ID. The Trader registers the Client with the stock exchange using client information.

...

  1. 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.

...

  1. The Trader places the client's buying and selling orders in the stock exchange.

...

  1. The trader also registers feed targets to the Exchange.

...

  1. 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.

...

  1. 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.

...

  1. The User (shareholder) can directly gain market information such as total traded shares, average price, and average size of trade from the stock exchange.

...

  1. Trader provides market data updates to the stock exchange.

In summary the services are as follows:

...

Note: Attributes of Stock Quote are name, symbol, selling price, high price and low price

How to Build and run the Sample

Find the "CommodityQuote" sample discussed here in <AS_HOME>/samples/Trader directory. You need Apache Ant to build the sample.

The steps are as follows:

...

2. In a command prompt, switch to the Trader directory.

For example, cd AS_HOME\samples\Trader

3. From there, type ant .

4. The build resumes and should be completed successfully. You should see a message like this:

5. The build automatically copies the  

Building the sample

The sample is located in <AS_HOME>\Samples\Trader  directory.

For more information, see  Building Axis2 Samples .

The build automatically copies the .aar file containing the service into the repository. If you go to Deployed Services in the Application Serve Management Console, you will see the

On the Main menu, under Services, click List. The Deployed Services page will appear with the ExchangeTrader, ExchangeClient, TraderClient and TraderExchange services deployed.

Info

Note:
If you don't do not see the services deployed, wait for a while for the deployment engine of Axis2 to pick up the newly added .aar . Then and the refresh/reload the page.

6. To see the sample services in action, you can use the following syntax on the command prompt.

...

Running the service

  1. From the terminal go to <AS_HOME>\samples\Trader directory.

  2. Execute one of the following commands to run the client:

    OSCommand
    MS Windowsrun-client.bat [ -qos (rm | secure | securerm)] [-te <TraderService URL>] [-ee <ExchangeService URL> ]

...

  1. Unix/Linux

...

  1. run-client.sh [ -qos (rm | secure | securerm)] [-te <TraderService URL>] [-ee <ExchangeService URL> ]

You can find the run-client.bat and run-client.sh files in the <AS_HOME>/samples/Trader directory.

...

Terms used

TraderService URL is the End Point Reference (EPR) of the TraderClient. This can be obtained from the Management Console.

...

  • rm - Sandesha (Sandesha2)
  • secure - Security (Rampart)
  • securerm - Both Sandesha and Security

 

Note:
Info
  • 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

...

From the "Trader" directory, type the following command.:

Code Block
$ ./run-client.sh

...

You should see the following:

Code Block
Populating the stock market ................Done.
   Using following parameters
   TraderService URL : http://localhost:9762/services/TraderClient
   ExchangeService URL :
   http://localhost:9762/services/ExchangeClient

   STARTING TRADE SAMPLE CLIENT
   =============================

   ...

   Please select your operation...
   ---------------------------------

   (1) createAccount
   (2) getQuote
   (3) getSymbols
   (4) deposit
   (5) buy
   (6) sell
   (7) getPortFolio
   (8) getMarketInfo
   (9) Exit

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 "bob" to that role.
  • 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 secureYou secure . You would see a prompt asking for the username and password before listing the operations available as follows:

Code Block
Populating the stock market ................Done.

   Using following parameters
   TraderService URL : http://localhost:9763/services/TraderClient
   ExchangeService URL :
   http://localhost:9763/services/ExchangeClient
   QOS : security

   STARTING TRADE SAMPLE CLIENT

   =============================

   ...

   Please enter your username :test
   Please enter your password :test123

Example 3: Creating an account

...

Code Block
...Creating account...

Please enter the Name:test1
Please enter the password:test1

Results
-------
User ID :test1

Example 4: Depositing money in the exchange

...

Code Block
...Doing deposit...

Please enter the username:test1
Please enter the password:test1
Please enter the amount:100
   
Deposit Successful !!

Sample 5: Buying '100 mn' stocks in the exchange

...

Code Block
...Buying stocks...

Please enter the username:test1
Please enter the password:test1
Please enter the symbol:mn
Please enter the quantity:100

Results
-------
Status :true
Reason :Success

Example 6: Selling '50 mn' stocks in the exchange

...

Code Block
...Selling stocks...

Please enter the username:test1
Please enter the password:test1
Please enter the symbol:mn
Please enter the quantity:50

Results
--------
Status :true
Reason :Success

Example 7: Getting the portfolio of the user 'test1' after buying a further '200 h' stocks

...

Code Block
...Getting Portfolio...

Please enter the username:test1
Please enter the password:test1

Results
-------
Symbol:mn Amount:50
Symbol:h Amount:200

...