davmail.caldav
Class CaldavConnection

java.lang.Object
  extended by java.lang.Thread
      extended by davmail.AbstractConnection
          extended by davmail.caldav.CaldavConnection
All Implemented Interfaces:
Runnable

public class CaldavConnection
extends AbstractConnection

Handle a caldav connection.


Nested Class Summary
protected static class CaldavConnection.CaldavRequest
           
protected  class CaldavConnection.CaldavResponse
          Caldav response wrapper, content sent in chunked mode to avoid timeout
protected  class CaldavConnection.ChunkedResponse
          Http chunked response.
 
Nested classes/interfaces inherited from class davmail.AbstractConnection
AbstractConnection.LineReaderInputStream, AbstractConnection.State
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.UncaughtExceptionHandler
 
Field Summary
protected  boolean closed
           
static BitSet ical_allowed_abs_path
          custom url encode path set for iCal 5
protected static int MAX_KEEP_ALIVE_TIME
          Maximum keep alive time in seconds
protected  org.apache.log4j.Logger wireLogger
           
 
Fields inherited from class davmail.AbstractConnection
client, in, os, password, session, state, userName
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CaldavConnection(Socket clientSocket)
          Initialize the streams and start the thread.
 
Method Summary
protected  void appendEventsResponses(CaldavConnection.CaldavResponse response, CaldavConnection.CaldavRequest request, List<ExchangeSession.Event> events)
           
 void appendFolderOrItem(CaldavConnection.CaldavResponse response, CaldavConnection.CaldavRequest request, ExchangeSession.Folder folder, String subFolder)
          Append folder object to Caldav response.
 void appendInbox(CaldavConnection.CaldavResponse response, CaldavConnection.CaldavRequest request, String subFolder)
          Append calendar inbox object to Caldav response.
protected  void appendItemResponse(CaldavConnection.CaldavResponse response, CaldavConnection.CaldavRequest request, ExchangeSession.Item item)
           
 void appendOutbox(CaldavConnection.CaldavResponse response, CaldavConnection.CaldavRequest request, String subFolder)
          Append calendar outbox object to Caldav response.
protected  HashMap<String,String> buildEtagHeader(String etag)
           
protected  void decodeCredentials(String authorization)
          Decode HTTP credentials
protected  String getContent(String contentLength)
           
protected  String getEventFileNameFromPath(String path)
           
protected  void handleFolderOrItem(CaldavConnection.CaldavRequest request)
           
protected  void handlePrincipals(CaldavConnection.CaldavRequest request)
           
 void handleRequest(String command, String path, Map<String,String> headers, String body)
          Handle caldav request.
protected  Map<String,String> parseHeaders()
           
 void patchCalendar(CaldavConnection.CaldavRequest request)
          Fake PROPPATCH response for request.
 void reportItems(CaldavConnection.CaldavRequest request)
          Report items listed in request.
 void run()
           
 void sendChunkedHttpResponse(int status, String contentType)
          Send Http response with given status in chunked mode.
 void sendDirectory(CaldavConnection.CaldavRequest request)
          Send caldav response for /directory/ request.
 void sendErr(Exception e)
          Send Http error response for exception
 void sendErr(int status, String message)
          Send Http error status and message.
 void sendFolderOrItem(CaldavConnection.CaldavRequest request)
          Send calendar response for request.
 void sendFreeBusy(String body)
          Send free busy response for body request.
 void sendGetRoot()
          Send simple html response to GET /.
 void sendHttpResponse(int status)
          Send Http response with given status.
 void sendHttpResponse(int status, Map<String,String> headers)
          Send Http response with given status and headers.
 void sendHttpResponse(int status, Map<String,String> headers, String contentType, byte[] content, boolean keepAlive)
          Send Http response with given status, headers, content type and content.
 void sendHttpResponse(int status, Map<String,String> headers, String contentType, String content, boolean keepAlive)
          Send Http response with given status, headers, content type and content.
 void sendInbox(CaldavConnection.CaldavRequest request)
          Send inbox response for request.
 void sendOptions()
          Send OPTIONS response.
 void sendOutbox(CaldavConnection.CaldavRequest request)
          Send outbox response for request.
 void sendPrincipal(CaldavConnection.CaldavRequest request, String prefix, String principal)
          Send Caldav principal response.
 void sendPrincipalsFolder(CaldavConnection.CaldavRequest request)
          Send principals folder.
 void sendRoot(CaldavConnection.CaldavRequest request)
          Send caldav response for / request.
 void sendUnauthorized()
          Send 401 Unauthorized response.
 void sendUnsupported(CaldavConnection.CaldavRequest request)
          Send 400 bad response for unsupported request.
 void sendUserRoot(CaldavConnection.CaldavRequest request)
          Send user response for request.
 void sendWellKnown()
          Send caldav response for /.well-known/ request.
protected  void setSocketTimeout(String keepAliveValue)
           
 
Methods inherited from class davmail.AbstractConnection
base64Decode, base64Encode, close, readClient, sendClient, sendClient, sendClient, sendClient
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_KEEP_ALIVE_TIME

protected static final int MAX_KEEP_ALIVE_TIME
Maximum keep alive time in seconds

See Also:
Constant Field Values

wireLogger

protected final org.apache.log4j.Logger wireLogger

closed

protected boolean closed

ical_allowed_abs_path

public static final BitSet ical_allowed_abs_path
custom url encode path set for iCal 5

Constructor Detail

CaldavConnection

public CaldavConnection(Socket clientSocket)
Initialize the streams and start the thread.

Parameters:
clientSocket - Caldav client socket
Method Detail

parseHeaders

protected Map<String,String> parseHeaders()
                                   throws IOException
Throws:
IOException

getContent

protected String getContent(String contentLength)
                     throws IOException
Throws:
IOException

setSocketTimeout

protected void setSocketTimeout(String keepAliveValue)
                         throws IOException
Throws:
IOException

run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread

handleRequest

public void handleRequest(String command,
                          String path,
                          Map<String,String> headers,
                          String body)
                   throws IOException
Handle caldav request.

Parameters:
command - Http command
path - request path
headers - Http headers map
body - request body
Throws:
IOException - on error

handlePrincipals

protected void handlePrincipals(CaldavConnection.CaldavRequest request)
                         throws IOException
Throws:
IOException

handleFolderOrItem

protected void handleFolderOrItem(CaldavConnection.CaldavRequest request)
                           throws IOException
Throws:
IOException

buildEtagHeader

protected HashMap<String,String> buildEtagHeader(String etag)

appendEventsResponses

protected void appendEventsResponses(CaldavConnection.CaldavResponse response,
                                     CaldavConnection.CaldavRequest request,
                                     List<ExchangeSession.Event> events)
                              throws IOException
Throws:
IOException

appendItemResponse

protected void appendItemResponse(CaldavConnection.CaldavResponse response,
                                  CaldavConnection.CaldavRequest request,
                                  ExchangeSession.Item item)
                           throws IOException
Throws:
IOException

appendFolderOrItem

public void appendFolderOrItem(CaldavConnection.CaldavResponse response,
                               CaldavConnection.CaldavRequest request,
                               ExchangeSession.Folder folder,
                               String subFolder)
                        throws IOException
Append folder object to Caldav response.

Parameters:
response - Caldav response
request - Caldav request
folder - folder object
subFolder - calendar folder path relative to request path
Throws:
IOException - on error

appendInbox

public void appendInbox(CaldavConnection.CaldavResponse response,
                        CaldavConnection.CaldavRequest request,
                        String subFolder)
                 throws IOException
Append calendar inbox object to Caldav response.

Parameters:
response - Caldav response
request - Caldav request
subFolder - inbox folder path relative to request path
Throws:
IOException - on error

appendOutbox

public void appendOutbox(CaldavConnection.CaldavResponse response,
                         CaldavConnection.CaldavRequest request,
                         String subFolder)
                  throws IOException
Append calendar outbox object to Caldav response.

Parameters:
response - Caldav response
request - Caldav request
subFolder - outbox folder path relative to request path
Throws:
IOException - on error

sendGetRoot

public void sendGetRoot()
                 throws IOException
Send simple html response to GET /.

Throws:
IOException - on error

sendInbox

public void sendInbox(CaldavConnection.CaldavRequest request)
               throws IOException
Send inbox response for request.

Parameters:
request - Caldav request
Throws:
IOException - on error

sendOutbox

public void sendOutbox(CaldavConnection.CaldavRequest request)
                throws IOException
Send outbox response for request.

Parameters:
request - Caldav request
Throws:
IOException - on error

sendFolderOrItem

public void sendFolderOrItem(CaldavConnection.CaldavRequest request)
                      throws IOException
Send calendar response for request.

Parameters:
request - Caldav request
Throws:
IOException - on error

patchCalendar

public void patchCalendar(CaldavConnection.CaldavRequest request)
                   throws IOException
Fake PROPPATCH response for request.

Parameters:
request - Caldav request
Throws:
IOException - on error

getEventFileNameFromPath

protected String getEventFileNameFromPath(String path)

reportItems

public void reportItems(CaldavConnection.CaldavRequest request)
                 throws IOException
Report items listed in request.

Parameters:
request - Caldav request
Throws:
IOException - on error

sendPrincipalsFolder

public void sendPrincipalsFolder(CaldavConnection.CaldavRequest request)
                          throws IOException
Send principals folder.

Parameters:
request - Caldav request
Throws:
IOException - on error

sendUserRoot

public void sendUserRoot(CaldavConnection.CaldavRequest request)
                  throws IOException
Send user response for request.

Parameters:
request - Caldav request
Throws:
IOException - on error

sendRoot

public void sendRoot(CaldavConnection.CaldavRequest request)
              throws IOException
Send caldav response for / request.

Parameters:
request - Caldav request
Throws:
IOException - on error

sendDirectory

public void sendDirectory(CaldavConnection.CaldavRequest request)
                   throws IOException
Send caldav response for /directory/ request.

Parameters:
request - Caldav request
Throws:
IOException - on error

sendWellKnown

public void sendWellKnown()
                   throws IOException
Send caldav response for /.well-known/ request.

Throws:
IOException - on error

sendPrincipal

public void sendPrincipal(CaldavConnection.CaldavRequest request,
                          String prefix,
                          String principal)
                   throws IOException
Send Caldav principal response.

Parameters:
request - Caldav request
prefix - principal prefix (users or public)
principal - principal name (email address for users)
Throws:
IOException - on error

sendFreeBusy

public void sendFreeBusy(String body)
                  throws IOException
Send free busy response for body request.

Parameters:
body - request body
Throws:
IOException - on error

sendErr

public void sendErr(Exception e)
             throws IOException
Send Http error response for exception

Parameters:
e - exception
Throws:
IOException - on error

sendUnsupported

public void sendUnsupported(CaldavConnection.CaldavRequest request)
                     throws IOException
Send 400 bad response for unsupported request.

Parameters:
request - Caldav request
Throws:
IOException - on error

sendErr

public void sendErr(int status,
                    String message)
             throws IOException
Send Http error status and message.

Parameters:
status - Http status
message - error messagee
Throws:
IOException - on error

sendOptions

public void sendOptions()
                 throws IOException
Send OPTIONS response.

Throws:
IOException - on error

sendUnauthorized

public void sendUnauthorized()
                      throws IOException
Send 401 Unauthorized response.

Throws:
IOException - on error

sendHttpResponse

public void sendHttpResponse(int status)
                      throws IOException
Send Http response with given status.

Parameters:
status - Http status
Throws:
IOException - on error

sendHttpResponse

public void sendHttpResponse(int status,
                             Map<String,String> headers)
                      throws IOException
Send Http response with given status and headers.

Parameters:
status - Http status
headers - Http headers
Throws:
IOException - on error

sendChunkedHttpResponse

public void sendChunkedHttpResponse(int status,
                                    String contentType)
                             throws IOException
Send Http response with given status in chunked mode.

Parameters:
status - Http status
contentType - MIME content type
Throws:
IOException - on error

sendHttpResponse

public void sendHttpResponse(int status,
                             Map<String,String> headers,
                             String contentType,
                             String content,
                             boolean keepAlive)
                      throws IOException
Send Http response with given status, headers, content type and content. Close connection if keepAlive is false

Parameters:
status - Http status
headers - Http headers
contentType - MIME content type
content - response body as string
keepAlive - keep connection open
Throws:
IOException - on error

sendHttpResponse

public void sendHttpResponse(int status,
                             Map<String,String> headers,
                             String contentType,
                             byte[] content,
                             boolean keepAlive)
                      throws IOException
Send Http response with given status, headers, content type and content. Close connection if keepAlive is false

Parameters:
status - Http status
headers - Http headers
contentType - MIME content type
content - response body as byte array
keepAlive - keep connection open
Throws:
IOException - on error

decodeCredentials

protected void decodeCredentials(String authorization)
                          throws IOException
Decode HTTP credentials

Parameters:
authorization - http authorization header value
Throws:
IOException - if invalid credentials


Copyright © 2001-2013 MickaĆ«l Guessant. All Rights Reserved.