Versions Compared

Key

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

...

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

 

Info

Note:

  • 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 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

...