«^»
10.2. ATotal: an Axis Web Service to store the sum of a series of values

Here is the code of the implementation of an Axis Web Service (called ATotal) that can be used to accumulate the sum of a series of values:

0256: package Pack;                                  // ATotalSoapBindingImpl.java
0257: public class ATotalSoapBindingImpl implements Pack.ATotal{
0258:    private double iTotal = 0.0;
0259:    public double inc(double pIncrement) throws java.rmi.RemoteException {
0260:       iTotal = iTotal + pIncrement;
0261:       return iTotal;
0262:    }
0263: }
If we proceed to use the six steps (described earlier) to produce an Axis Web Service, then each call of inc will use a different ATotalSoapBindingImpl object. What we want is for all calls of inc to access a specific ATotalSoapBindingImpl object. Besides getting a different object (called Request), Axis permits two other possibilities: either every call gets the same object (called Application) or a call can give the name of the object it wishes to use (called Session).

Step 3 of the six steps uses the WSDL2Java program. When executing this program, a -d option can be used to indicate which kind of Web Service is to be generated. So if a:

-d Session
option is supplied, as in:
java org.apache.axis.wsdl.WSDL2Java -o . -s -S true -d Session ^
   -Nurn:ATotal Pack ATotal.wsdl
the line:
<parameter name="scope" value="Session"/>
will appear in the file deploy.wsdd.

If this is done, the HTTP response from the first call of a method of the Web Service will include a header line like:

Set-Cookie: JSESSIONID=595B7DAE454938844EEB49EFFE67C6B3; Path=/axis
If a client wishes to access the object used in this call in later calls, it needs to capture this value and provide it in the header of the HTTP requests of subsequent calls to the Web Service, e.g.:
Cookie: JSESSIONID=595B7DAE454938844EEB49EFFE67C6B3