org.apache.webdav.lib
Class WebdavClient

java.lang.Object
  |
  +--org.apache.webdav.lib.WebdavClient

public class WebdavClient
extends java.lang.Object

WebDAV client.

Author:
Remy Maucherat

Field Summary
protected  Credentials credentials
          Credentials to use.
static java.lang.String DATE_FORMAT
          HTTP Date format pattern (RFC 2068, 822, 1123).
protected  int debug
          Debug level.
protected static java.text.DateFormat formatter
          Date formatter.
protected  boolean http11
          HTTP/1.1 flag.
protected  java.io.InputStream input
          Socket input stream.
protected  java.io.OutputStream output
          Socket output stream.
protected  java.lang.String sessionHost
          The host name specified when the startSession(host, port) method was called.
protected  int sessionPort
          Port number.
protected  java.net.Socket socket
          Client Socket in use.
protected  State state
          Session state.
static Header USER_AGENT
          User Agent.
 
Constructor Summary
WebdavClient()
           
WebdavClient(java.net.URL url)
           
WebdavClient(java.net.URL url, java.lang.String user, java.lang.String password)
           
 
Method Summary
protected  void closeConnection()
           
 void endSession()
          End a session.
 void executeMethod(WebdavMethod method)
          Execute a DAV method.
 int getDebug()
          Get debug level.
 java.lang.String getHost()
          Get the session host.
 int getPort()
          Get the session port.
 State getState()
          Get the state for lock information.
protected  boolean needToCloseConnection(WebdavMethod method, java.util.Hashtable responseHeaders)
          Return true if the connection should be closed after processing.
protected  boolean needToCloseOutput()
          Return true if the connection should be closed after sending the request.
protected  void openConnection()
           
protected  java.util.Hashtable parseHeaders(java.io.InputStream input)
          Parse headers.
protected  void parseStatusLine(java.lang.String statusLine, WebdavMethod method)
          Parse status line.
protected  java.lang.String readLine(java.io.InputStream input)
          Reads the input stream, one line at a time.
protected  void sendRequest(WebdavMethod method)
          Send a WebDAV request.
 void setCredentials(Credentials credentials)
          Set the credentials to use.
 void setDebug(int debug)
          Set debug level.
 void setSocket(java.net.Socket socket)
          Set the socket to use.
 void setState(State state)
          Set the client state.
 void startSession()
          Start a session.
 void startSession(java.lang.String host, int port)
          Start a session.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE_FORMAT

public static final java.lang.String DATE_FORMAT
HTTP Date format pattern (RFC 2068, 822, 1123).

USER_AGENT

public static final Header USER_AGENT
User Agent.

formatter

protected static final java.text.DateFormat formatter
Date formatter.

socket

protected java.net.Socket socket
Client Socket in use.

state

protected State state
Session state.

credentials

protected Credentials credentials
Credentials to use.

input

protected java.io.InputStream input
Socket input stream.

output

protected java.io.OutputStream output
Socket output stream.

sessionHost

protected java.lang.String sessionHost
The host name specified when the startSession(host, port) method was called.

sessionPort

protected int sessionPort
Port number.

http11

protected boolean http11
HTTP/1.1 flag.

debug

protected int debug
Debug level.
Constructor Detail

WebdavClient

public WebdavClient()

WebdavClient

public WebdavClient(java.net.URL url)

WebdavClient

public WebdavClient(java.net.URL url,
                    java.lang.String user,
                    java.lang.String password)
Method Detail

setSocket

public void setSocket(java.net.Socket socket)
Set the socket to use.

setCredentials

public void setCredentials(Credentials credentials)
Set the credentials to use.

setDebug

public void setDebug(int debug)
Set debug level.

getDebug

public int getDebug()
Get debug level.

getHost

public java.lang.String getHost()
Get the session host.

getPort

public int getPort()
Get the session port.

getState

public State getState()
Get the state for lock information.

setState

public void setState(State state)
Set the client state.

executeMethod

public void executeMethod(WebdavMethod method)
                   throws java.io.IOException,
                          WebdavException
Execute a DAV method.
Parameters:
method - WebDAV method to execute

startSession

public void startSession()
Start a session.

startSession

public void startSession(java.lang.String host,
                         int port)
Start a session.

endSession

public void endSession()
                throws java.io.IOException
End a session.

openConnection

protected void openConnection()
                       throws java.io.IOException,
                              java.net.UnknownHostException

closeConnection

protected void closeConnection()
                        throws java.io.IOException

sendRequest

protected void sendRequest(WebdavMethod method)
                    throws java.io.IOException,
                           WebdavException
Send a WebDAV request.
Parameters:
method - WebDAV method to execute

readLine

protected java.lang.String readLine(java.io.InputStream input)
                             throws java.io.IOException
Reads the input stream, one line at a time. Reads bytes into an array, until it reads a certain number of bytes or reaches a newline character, which it reads into the array as well.
Parameters:
input - Input stream on which the bytes are read
Returns:
The line that was read, or null if end-of-file was encountered
Throws:
java.io.IOException - if an input or output exception has occurred

parseStatusLine

protected void parseStatusLine(java.lang.String statusLine,
                               WebdavMethod method)
                        throws java.io.IOException,
                               WebdavException
Parse status line.
Parameters:
statusLine - String representing the HTTP status line
method - Webdav method

parseHeaders

protected java.util.Hashtable parseHeaders(java.io.InputStream input)
                                    throws java.io.IOException,
                                           WebdavException
Parse headers.
Parameters:
input - Input stream on which the bytes are read

needToCloseConnection

protected boolean needToCloseConnection(WebdavMethod method,
                                        java.util.Hashtable responseHeaders)
Return true if the connection should be closed after processing.

needToCloseOutput

protected boolean needToCloseOutput()
Return true if the connection should be closed after sending the request.