org.apache.webdav.lib
Class WebdavSession

java.lang.Object
  |
  +--org.apache.webdav.lib.WebdavSession
All Implemented Interfaces:
org.apache.commons.httpclient.ConnectionInterceptor
Direct Known Subclasses:
WebdavResource

public class WebdavSession
extends java.lang.Object
implements org.apache.commons.httpclient.ConnectionInterceptor

This WebdavSession class is for the multi-session management of WebDAV clients. This class saves and restores the requested client. Clients that use persistent connections SHOULD limit the number of simultaneous connections that they maintain to a given server. A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy. A proxy SHOULD use up to 2*N connections to another server or proxy, where N is the number of simultaneously active users. These guidelines are intended to improve HTTP response times and avoid congestion.

Author:
Park, Sung-Gu

Field Summary
protected  org.apache.commons.httpclient.HttpClient client
          The Http client instance.
protected  int debug
          Debug level.
 
Constructor Summary
WebdavSession()
           
 
Method Summary
 void authenticate()
          Authenticate.
 void closeSession(org.apache.commons.httpclient.HttpClient client)
          Close an session and delete the connection information.
 void connect()
          Connect.
 void disconnect()
          Disconnect.
 boolean error(int status, java.lang.Exception e)
          Unexpected error.
 java.util.Enumeration findSessions(java.lang.String partOfAuthority)
          Find the sessions having the part of the authority string.
 org.apache.commons.httpclient.HttpClient getSessionInstance(org.apache.util.HttpURL httpURL)
          Get a HttpClient instance.
 org.apache.commons.httpclient.HttpClient getSessionInstance(org.apache.util.HttpURL httpURL, boolean reset)
          Get a HttpClient instance.
 java.util.Enumeration getSessions()
          Get all session information.
 boolean info(int status, java.util.Hashtable headers)
          Recieved an informational status code.
 boolean isSession(org.apache.util.HttpURL httpURL)
          Test a session to be connected.
 boolean isSession(java.lang.String authority)
          Test a session to be connected.
 void recievedExpectation()
          Recieved expectation.
 void recievedResponse()
          Recieved response.
 void requiredAuthentication()
          Authenticate.
 boolean retry(int status)
          Retry.
 void sentRequest()
          Sent request.
 void setDebug(int debug)
          Set debug level.
protected  void setSession(org.apache.commons.httpclient.HttpClient client)
          Set the session by the given client.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

client

protected org.apache.commons.httpclient.HttpClient client
The Http client instance.

debug

protected int debug
Debug level.
Constructor Detail

WebdavSession

public WebdavSession()
Method Detail

setDebug

public void setDebug(int debug)
Set debug level.

getSessionInstance

public org.apache.commons.httpclient.HttpClient getSessionInstance(org.apache.util.HttpURL httpURL)
                                                            throws java.io.IOException
Get a HttpClient instance. This method returns a new client instance for the first time. And it is saved util it's closed or reset.
Parameters:
httpURL - The http URL to connect. only used the authority part.
Returns:
An instance of HttpClient.
Throws:
java.io.IOException -  

getSessionInstance

public org.apache.commons.httpclient.HttpClient getSessionInstance(org.apache.util.HttpURL httpURL,
                                                                   boolean reset)
                                                            throws java.io.IOException
Get a HttpClient instance. This method returns a new client instance, when reset is true.
Parameters:
httpURL - The http URL to connect. only used the authority part.
reset - The reset flag to represent whether the saved information is used or not.
Returns:
An instance of HttpClient.
Throws:
java.io.IOException -  

setSession

protected void setSession(org.apache.commons.httpclient.HttpClient client)
                   throws java.io.IOException
Set the session by the given client. In order to save infomration of the client, it must be used.
Parameters:
client - The Http client instance.
Throws:
java.io.IOException -  

isSession

public boolean isSession(org.apache.util.HttpURL httpURL)
                  throws java.net.MalformedURLException
Test a session to be connected.
Parameters:
httpURL - The http URL to connect. only used the authority part.
Returns:
true if connected aleady.
Throws:
java.net.MalformedURLException -  

isSession

public boolean isSession(java.lang.String authority)
Test a session to be connected.
Parameters:
authority - The authority string.
Returns:
true if connected aleady.

findSessions

public java.util.Enumeration findSessions(java.lang.String partOfAuthority)
Find the sessions having the part of the authority string. The partOfAuthority can be user or host part.
Parameters:
partOfAuthority - The part of the authority string.
Returns:
Authorities to include the given string.

getSessions

public java.util.Enumeration getSessions()
Get all session information.
Returns:
Authorities of all session.

closeSession

public void closeSession(org.apache.commons.httpclient.HttpClient client)
                  throws java.io.IOException
Close an session and delete the connection information.
Parameters:
client - The HttpClient instance.
Throws:
java.io.IOException - Error in closing socket.

connect

public void connect()
Connect.
Specified by:
connect in interface org.apache.commons.httpclient.ConnectionInterceptor

disconnect

public void disconnect()
Disconnect.
Specified by:
disconnect in interface org.apache.commons.httpclient.ConnectionInterceptor

retry

public boolean retry(int status)
Retry.
Specified by:
retry in interface org.apache.commons.httpclient.ConnectionInterceptor
Returns:
boolean true if a retry should be attempted

info

public boolean info(int status,
                    java.util.Hashtable headers)
Recieved an informational status code.
Specified by:
info in interface org.apache.commons.httpclient.ConnectionInterceptor
Returns:
boolean true if a retry should be attempted

error

public boolean error(int status,
                     java.lang.Exception e)
Unexpected error.
Specified by:
error in interface org.apache.commons.httpclient.ConnectionInterceptor
Parameters:
status - Status code; can be equal to -1 if status code is not known
e - Underlying exception; can be null
Returns:
boolean true if processing of the request should be stopped

sentRequest

public void sentRequest()
Sent request.
Specified by:
sentRequest in interface org.apache.commons.httpclient.ConnectionInterceptor

recievedResponse

public void recievedResponse()
Recieved response.
Specified by:
recievedResponse in interface org.apache.commons.httpclient.ConnectionInterceptor

recievedExpectation

public void recievedExpectation()
Recieved expectation.
Specified by:
recievedExpectation in interface org.apache.commons.httpclient.ConnectionInterceptor

requiredAuthentication

public void requiredAuthentication()
Authenticate.
Specified by:
requiredAuthentication in interface org.apache.commons.httpclient.ConnectionInterceptor

authenticate

public void authenticate()
Authenticate.
Specified by:
authenticate in interface org.apache.commons.httpclient.ConnectionInterceptor