This demo shows how to access and process SOAP messages at the XML/SOAP level in a stream-based manner. Stream-based processing of a message can be useful when a service processes large XML/SOAP documents and the classical approach using the tree-like SAAJ API is too memory consuming.
To demonstrate stream-based processing functionality, we have created a simple service that calculates a total price including tax based on tax value. The tax value isn't directly in the outgoing SOAP message, which is reading from the inData.xml file. Instead, a message handler fills in this value in the SOAP message based on country. Both the service and the message handler process the SOAP message in a stream-based manner using the tokenizer. Because the processed message can be very large, the client uses asynchronous invocation to perform the call. The response SOAP message is saved to the outData.xml file.
The XML messages in this demo use a SOAP protocol that looks like the following:
<envelope> <body> <items> <item><amount>10</amount><country>CZK</country><tax/><sum/></item> <item><amount>10</amount><country>US</country><tax/><sum/></item> .... </items> </body> </envelope>
The handler modifies the message in the following way:
<envelope> <body> <items> <item><amount>10</amount><country>CZK</country><tax>22</tax><sum/></item> <item><amount>10</amount><country>US</country><tax>22</tax><sum/></item> .... </items> </body> </envelope>
The service modifies the message in the following way:
<envelope> <body> <items> <item><amount>10</amount><country>CZK</country><tax>22</tax><sum>12.2</sum></item> <item><amount>10</amount><country>US</country><tax>22</tax><sum>10</sum></item> .... </items> </body> </envelope>
This message is at the same time sent to the client as a response.
In addition to the files described in Files and Directories, this demo contains:
File or directory | Description |
---|---|
inData.xml | SOAP message to process |
src/demo/advanced/streamprocessing/server/ | Server source code |
src/demo/advanced/streamprocessing/client/ | Client source code |
src/package.xml | Deployment descriptor |
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:
Ensure that you have not started SESJ.
Compile the server classes.
Windows: run.bat make_server Linux: ./run.sh make_server
Run StreamProcessingServer (it starts SESJ and publishes StreamProcesingService class).
Windows: run.bat run_server Linux: ./run.sh run_server (use a new terminal)
Make the client classes.
Windows: run.bat make_client Linux: ./run.sh make_client
Run StreamProcessingClient (it calls StreamProcessingService):
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 have started SESJ.
Compile StreamProcessingService.
Windows: run.bat make_service Linux: ./run.sh make_service
Deploy StreamProcessingService on the SESJ.
Windows: run.bat deploy_service Linux: ./run.sh deploy_service
Make the client classes.
Windows: ./run.bat make_client Linux: ./run.sh make_client
Run StreamProcessingClient (it calls StreamProcessingService).
Windows: ./run.bat run_client Linux: ./run.sh run_client
Undeploy StreamProcessingService from the SESJ.
Windows: run.bat undeploy_service Linux: ./run.sh undeploy_service