Apache SOAP provides for session management by passing cookies via the HTTP headers. Earlier in this chapter, we saw an HTTP response from the server that included HTTP header entries called Set-Cookie and Set-Cookie2. The client application uses these cookies if it needs to make subsequent method invocations against the same session as the original request. The Apache SOAP API uses a simple technique for handling this. org.apache.soap.transport.http.SOAPHTTPConnection includes a method called setMaintainSession( ) that takes a single boolean parameter. This parameter, when set to true, tells the connection object to maintain the current session. The connection object implements this by keeping track of the cookies and sending them back to the server when the next method invocation takes place.
Go ahead and edit the deployment descriptor, setting the scope attribute to Session. Now run the client program again. You'll get the following output:
Result is 3
This output proves that the same instance of the service object was used for all of the method invocations. If you run it again you'll get the same result because a new instance of the session object is created on the first call to doSomething( ), and each subsequent method call uses the same service object. Because we're using the same instance of org.apache.soap.rpc.Call for every service call, we're also using the same instance of org.apache.soap.transport.http.SOAPHTTPConnection ...