This demo shows how a service may store or retrieve its own configuration. A service's configuration is persistent - it is untouched by server reboots.
The service used in this demo is a currency convertor, storing the currencies and translation rates in its configuration. The currencies and translation rates are adjustable as part of the service's interface. This would of course have to be a separate interface with strict access control in a real world deployment.
The client can be called with no arguments in which case the default action is taken - attempt to convert 1000 CZK (Czech Crowns) to USD (United States Dollars), set the conversion rate of the two currencies above to 1 USD = 34 CZK, and then convert 10 USD to CZK.
The first call in the default action will yield null because the conversion rate is not set yet.
The client can also be called with three arguments to convert an arbitrary combination: the first argument is the source currency name, the second is the target currency name and the third is the amount to convert.
Following example will convert 10 US Dollars to Czech Korunas (include wasp.jar and build\client\classes in your classpath).
java demo.advanced.config.client.ConfigClient USD CZK 10
Using run.sh (run.bat) the syntax is:
run.sh run_client_convert USD CZK 10
To set an arbitrary rate, the client can be called with four arguments. The first argument should be the string "set_rate", the second argument is the source currency name, the third argument is the target currency name, and the fourth argument is the rate. This example will set the conversion rate 1 USD == 34 CZK.
java demo.advanced.config.client.ConfigClient set_rate USD CZK 34
Using run.sh (run.bat) the first parameter is hidden in the run target name and the syntax is:
run.sh run_client_set_rate USD CZK 34
In addition to the files described in Files and Directories, this demo contains:
File or directory | Description |
---|---|
src/demo/advanced/config/server/CurrencyConvertor.java | Currency convertor interface |
src/demo/advanced/config/server/ConfigService.java | Service implementation |
src/demo/advanced/config/server/Rate.java | Configuration interface for a single rate |
src/demo/advanced/config/server/RateSet.java | Configuration interface for the whole rateset |
src/demo/advanced/config/server/RateSet.mapping | Mapping of Java Beans properties to configuration names |
src/demo/advanced/config/client/ConfigClient.java | The client implementation |
You can run the demo using the "run.sh" (for Unix) or "run.bat" (for Windows) scripts. Running the script without arguments prints out a help message on screen.
The demo can be run in two different ways:
To use Runtime Publishing, follow these steps:
Compile the server classes.
Windows: run.bat make_server Linux: ./run.sh make_server
Run the ConfigServer (it starts SESJ and publishes ConfigService class).
Windows: run.bat run_server Linux: ./run.sh run_server (use a new terminal)
You can look at ConfigService WSDL on 'http://localhost:6060/demo/advanced/ConfigService/wsdl' from the browser.
Make the client classes.
Windows: run.bat make_client Linux: ./run.sh make_client
Run the ConfigClient (it calls ConfigService).
Windows: run.bat run_client Linux: ./run.sh run_client
If you wish to follow the progress of the invocation with SoapSpy, perform the following:
Run server_java60/bin/soapspy.bat or soapspy.sh. This will bring up the SoapSpy GUI.
Start spying by selecting Start Spying from the Spy menu or by clicking the spy icon in the main pane.
Run the client using the run spy_client command instead of run_client.
To run using Persistent Deployment:
Be sure that you've started SESJ.
Compile the ConfigService.
Windows: run.bat make_service Linux: ./run.sh make_service
Deploy the ConfigService on the SESJ.
Windows: run.bat deploy_service Linux: ./run.sh deploy_service
Make client classes.
Windows: run.bat make_client Linux: ./run.sh make_client
Run the ConfigClient (it calls ConfigService).
Windows: run.bat run_client Linux: ./run.sh run_client
Undeploy the ConfigService from the SESJ.
Windows: run.bat undeploy_service Linux: ./run.sh undeploy_service