You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by Ong Boon Pang <on...@coleridge.com.sg> on 2001/11/01 04:22:15 UTC

RE: session maintance

Hi,

>Oh I see, so the session will persists for the same call object. Is there
>any way to implement a session for a a client, nomatter if its new or same
>call, but not application scope because than if anohter client accesses
>methods, there will be trouble.
Are you refering to the client side or server side of the SOAP?

If its client side,the code shown previously allow the all
3 Call objects: getID, square and cube  to use the same "shc" object
hence invoking those 3 call objects will maintain a single client session
on the server.

If its server side, you would want to code those 3 methods like:

private String getRunInfo(){
   return Thread.currentThread().toString()+" using obj: "+this.toString();
}


public String getID(SOAPContext soapCtx, String msg)throws SOAPException{
     String str=getRunInfo()+" running: getID("+msg+")";

     HttpSession httpSess= 
soapCtx.getProperty(org.apache.soap.Constants.BAG_HTTPSESSION);

     httpSess.setMaxInactiveInterval(900); // set session time out
     httpSess.setAttribute("getID", str);

         System.out.println(str);
         return str;
}

private int val= -1;

public String square(SOAPContext soapCtx, int num){
     val=num;
     HttpSession httpSess= 
soapCtx.getProperty(org.apache.soap.Constants.BAG_HTTPSESSION);
     String str=(String)httpSess.getAttribute("getID");

         System.out.println(getRunInfo()+" running: square("+num+") val:"+val);
     return "["+str+"]"+(num*num);
}

public String cube(SOAPContext soapCtx){
     HttpSession httpSess= 
soapCtx.getProperty(org.apache.soap.Constants.BAG_HTTPSESSION);
     String str=(String)httpSess.getAttribute("getID");

         System.out.println(getRunInfo()+" running: cube() val:"+val);

     return "["+str+"]"+(val*val*val);
}

Call getID, square, cube in such sequence... you should be able to see the 
difference.
Hope it helps...
If misunderstand your question, please clarify to me.

Cheers,
Boon Pang
ongbp@coleridge.com.sg
At 07:41 PM 10/30/2001 -0800, you wrote:
>Oh I see, so the session will persists for the same call object. Is there
>any way to implement a session for a a client, nomatter if its new or same
>call, but not application scope because than if anohter client accesses
>methods, there will be trouble.
>
>Sincerely,
>Oleg
>
>-----Original Message-----
>From: Ong Boon Pang [mailto:ongbp@coleridge.com.sg]
>Sent: Tuesday, October 30, 2001 7:26 PM
>To: soap-user@xml.apache.org
>Subject: Re: session maintance
>
>
>Hi Oleg,
>
>  >For some reason each call from the same client gives me different session
>ID
>That is b'coz you didn't use a single instance of
>org.apache.soap.transport.http.SOAPHTTPConnection
>across all Call Objects.
>
>private Call getID = new Call(), square=new Call(), cube=new Call();
>
>...
>SOAPHTTPConnection shc=new SOAPHTTPConnection();
>
>getID.setTargetObjectURI("urn:jsoap-svc-example");
>getID.setMethodName("getID");
>getID.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
>getID.setSOAPTransport( shc);
>
>square.setTargetObjectURI("urn:jsoap-svc-math");
>square.setMethodName("square");
>square.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
>square.setSOAPTransport( shc);
>
>cube.setTargetObjectURI("urn:jsoap-svc-math");
>cube.setMethodName("cube");
>cube.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
>cube.setSOAPTransport( shc);
>
>cheers,
>Boon Pang
>ongbp@coleridge.com.sg