You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by sa...@apache.org on 2001/03/07 05:55:43 UTC

cvs commit: xml-soap/java/src/org/apache/soap/transport/http SOAPHTTPConnection.java

sanjiva     01/03/06 20:55:43

  Modified:    java/src/org/apache/soap/transport/http
                        SOAPHTTPConnection.java
  Log:
  added support for maintaining HTTP sessions. see addressbook2 sample
  for an example of using it.
  
  Revision  Changes    Path
  1.10      +55 -2     xml-soap/java/src/org/apache/soap/transport/http/SOAPHTTPConnection.java
  
  Index: SOAPHTTPConnection.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/transport/http/SOAPHTTPConnection.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SOAPHTTPConnection.java	2001/01/20 01:39:03	1.9
  +++ SOAPHTTPConnection.java	2001/03/07 04:55:43	1.10
  @@ -81,8 +81,7 @@
    * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
    * @author Wouter Cloetens (wcloeten@raleigh.ibm.com)
    */
  -public class SOAPHTTPConnection implements SOAPTransport
  -{
  +public class SOAPHTTPConnection implements SOAPTransport {
     private BufferedReader responseReader;
     private Hashtable responseHeaders;
     private SOAPContext responseSOAPContext;
  @@ -92,6 +91,9 @@
     private int    timeout;
     private String userName;
     private String password;
  +  private boolean maintainSession;
  +  private String cookieHeader;
  +  private String cookieHeader2;
   
     /**
      * Set HTTP proxy host.
  @@ -144,6 +146,20 @@
     }
   
     /**
  +   * Indicate whether to maintain HTTP sessions.
  +   */
  +  public void setMaintainSession (boolean maintainSession) {
  +    this.maintainSession = true;
  +  }
  +
  +  /**
  +   * Return session maintanence status.
  +   */
  +  public boolean getMaintainSession (){
  +    return maintainSession;
  +  }
  +
  +  /**
      * Set the HTTP read timeout.
      *
      * @param timeout the amount of time, in ms, to block on reading data.
  @@ -163,6 +179,13 @@
     }
   
     /**
  +   * Copy the session cookies from all the response headers so that
  +   * we can maintain a session.
  +   */
  +  private void copySessionCookiesFromResponse (Hashtable respHdrs) {
  +  }
  +
  +  /**
      * This method is used to request that an envelope be posted to the
      * given URL. The response (if any) must be gotten by calling the
      * receive() function.
  @@ -190,6 +213,16 @@
         if (headers == null) {
           headers = new Hashtable ();
         }
  +      if (maintainSession) {
  +	// if there is saved cookie headers, put them in to the request
  +	if (cookieHeader2 != null) { // RFC 2965 header
  +	  headers.put ("Cookie2", cookieHeader2);
  +	} 
  +	if (cookieHeader != null) { // RFC 2109 header
  +	  headers.put ("Cookie", cookieHeader);
  +	}
  +      }
  +
         headers.put (Constants.HEADER_SOAP_ACTION, 
                      (action != null) ? ('\"' + action + '\"') : "");
         if (userName != null) {
  @@ -220,6 +253,26 @@
           responseReader = null;
         responseSOAPContext = response.getSOAPContext();
         responseHeaders = response.getHeaders();
  +      if (maintainSession) {
  +	// look for Set-Cookie2 and Set-Cookie headers and save them after
  +	// stripping everything after the ';' (i.e., ignore all cookie attrs)
  +
  +	cookieHeader2 = (String) responseHeaders.get ("Set-Cookie2");
  +	if (cookieHeader2 != null) {
  +	  int index = cookieHeader2.indexOf (';');
  +	  if (index != -1) {
  +	    cookieHeader2 = cookieHeader2.substring (0, index);
  +	  }
  +	}
  +
  +	cookieHeader = (String) responseHeaders.get ("Set-Cookie");
  +	if (cookieHeader != null) {
  +	  int index = cookieHeader.indexOf (';');
  +	  if (index != -1) {
  +	    cookieHeader = cookieHeader.substring (0, index);
  +	  }
  +	}
  +      }
       } catch (IllegalArgumentException e) {
         throw new SOAPException (Constants.FAULT_CODE_CLIENT, e.getMessage(), e);
       } catch (MessagingException e) {