This simple demo is provided as an introduction to writing web services using WSO2 SOA Enablement Server for Java. It has a client side and a server side.
The server side contains the HelloService class. This is a simple web service implementation with one operation, "hello", which receives an input message with one string (like "world") and returns an output message with another string (like "Hello, world!"). This operation is written in Java as:
String hello(String message);
The server is started with the HelloServer class on an URL such as "http://jumbo:6060". HelloService is published there on the "/demo/basic/HelloService" path. SESJ executes the Web service directly from the HelloService class and automatically generates web service definition (WSDL). You can theoretically create a Web service from any Java class or instance.
The client side is implemented in the HelloClient class. It looks up the published Web service on the "[server URL] + /demo/basic/HelloService/wsdl" URL. A HelloService proxy interface is generated from the HelloService WSDL when the client is compiled. This interface is used in the HelloClient class.
This demo provides the most basic example of a Web service. At this point it might be appropriate to ask what are the most significant advantages of using web services:
Web services are based on well-known and supported network protocols, in this example, HTTP. This permits companies to create services that are firewall friendly and globally available.
The message itself is encoded into SOAP, which is an XML text document. It allows you to pass requests and data from virtually any programming language, operating system, and piece of hardware that can be connected into network.
What might be the most important feature of SESJ is the simplicity; no knowledge of HTTP, SOAP or XML is needed. You can create a Web service merely by writing a simple java class, or by using an existing class. On the client side the things are equally simple - a plain method call is rendered into a Web service invocation.
In addition to the files described in Files and Directories, this demo contains:
File or directory | Description |
---|---|
src/demo/basic/hello/server/ | Server source code |
src/demo/basic/hello/client/ | Client source code |
You can run the demo using "run.sh" or "run.bat" scripts. The script on invocation without arguments prints out a help message.
Demo can be run in two different ways:
Compile server classes ...
Windows: run.bat make_server Linux: ./run.sh make_server
Run the HelloServer (it starts SESJ and publishes HelloService class) ...
Windows: run.bat run_server Linux: ./run.sh run_server (use a new terminal)
You can look at HelloService WSDL on 'http://localhost:6060/demo/basic/HelloService/wsdl' from browser, for instance.
Make client classes ...
Windows: run.bat make_client Linux: ./run.sh make_client
Run the HelloClient (it calls HelloService) ...
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.
Be sure that you've started SESJ.
Compile the HelloService ...
Windows: run.bat make_service Linux: ./run.sh make_service
Deploy the HelloService 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 HelloClient (it calls HelloService) ...
Windows: run.bat run_client Linux: ./run.sh run_client
Undeploy the HelloService from the SESJ ...
Windows: run.bat undeploy_service Linux: ./run.sh undeploy_service