Improve javadoc
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@641 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
0847630d82
commit
ecffaed107
|
@ -18,17 +18,17 @@
|
||||||
*/
|
*/
|
||||||
package davmail.caldav;
|
package davmail.caldav;
|
||||||
|
|
||||||
import davmail.*;
|
import davmail.AbstractConnection;
|
||||||
import davmail.exception.DavMailException;
|
import davmail.BundleMessage;
|
||||||
|
import davmail.Settings;
|
||||||
import davmail.exception.DavMailAuthenticationException;
|
import davmail.exception.DavMailAuthenticationException;
|
||||||
|
import davmail.exception.DavMailException;
|
||||||
import davmail.exchange.ExchangeSession;
|
import davmail.exchange.ExchangeSession;
|
||||||
import davmail.exchange.ExchangeSessionFactory;
|
import davmail.exchange.ExchangeSessionFactory;
|
||||||
import davmail.exchange.ICSBufferedReader;
|
import davmail.exchange.ICSBufferedReader;
|
||||||
import davmail.ui.tray.DavGatewayTray;
|
import davmail.ui.tray.DavGatewayTray;
|
||||||
import org.apache.commons.httpclient.HttpException;
|
import org.apache.commons.httpclient.HttpException;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.httpclient.URI;
|
|
||||||
import org.apache.commons.httpclient.URIException;
|
|
||||||
import org.apache.commons.httpclient.util.URIUtil;
|
import org.apache.commons.httpclient.util.URIUtil;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
@ -55,7 +55,11 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
|
|
||||||
protected boolean closed;
|
protected boolean closed;
|
||||||
|
|
||||||
// Initialize the streams and start the thread
|
/**
|
||||||
|
* Initialize the streams and start the thread.
|
||||||
|
*
|
||||||
|
* @param clientSocket Caldav client socket
|
||||||
|
*/
|
||||||
public CaldavConnection(Socket clientSocket) {
|
public CaldavConnection(Socket clientSocket) {
|
||||||
super(CaldavConnection.class.getSimpleName(), clientSocket, "UTF-8");
|
super(CaldavConnection.class.getSimpleName(), clientSocket, "UTF-8");
|
||||||
wireLogger.setLevel(Settings.getLoggingLevel("httpclient.wire"));
|
wireLogger.setLevel(Settings.getLoggingLevel("httpclient.wire"));
|
||||||
|
@ -186,6 +190,14 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
DavGatewayTray.resetIcon();
|
DavGatewayTray.resetIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle caldav request.
|
||||||
|
* @param command Http command
|
||||||
|
* @param path request path
|
||||||
|
* @param headers Http headers map
|
||||||
|
* @param body request body
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void handleRequest(String command, String path, Map<String, String> headers, String body) throws IOException {
|
public void handleRequest(String command, String path, Map<String, String> headers, String body) throws IOException {
|
||||||
CaldavRequest request = new CaldavRequest(command, path, headers, body);
|
CaldavRequest request = new CaldavRequest(command, path, headers, body);
|
||||||
if (request.isOptions()) {
|
if (request.isOptions()) {
|
||||||
|
@ -327,6 +339,13 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
response.endResponse();
|
response.endResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append calendar object to Caldav response.
|
||||||
|
* @param response Caldav response
|
||||||
|
* @param request Caldav request
|
||||||
|
* @param subFolder calendar folder path relative to request path
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void appendCalendar(CaldavResponse response, CaldavRequest request, String subFolder) throws IOException {
|
public void appendCalendar(CaldavResponse response, CaldavRequest request, String subFolder) throws IOException {
|
||||||
response.startResponse(URIUtil.encodePath(request.getPath(subFolder)));
|
response.startResponse(URIUtil.encodePath(request.getPath(subFolder)));
|
||||||
response.startPropstat();
|
response.startPropstat();
|
||||||
|
@ -363,6 +382,13 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
response.endResponse();
|
response.endResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append calendar inbox object to Caldav response.
|
||||||
|
* @param response Caldav response
|
||||||
|
* @param request Caldav request
|
||||||
|
* @param subFolder inbox folder path relative to request path
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void appendInbox(CaldavResponse response, CaldavRequest request, String subFolder) throws IOException {
|
public void appendInbox(CaldavResponse response, CaldavRequest request, String subFolder) throws IOException {
|
||||||
response.startResponse(URIUtil.encodePath(request.getPath(subFolder)));
|
response.startResponse(URIUtil.encodePath(request.getPath(subFolder)));
|
||||||
response.startPropstat();
|
response.startPropstat();
|
||||||
|
@ -388,6 +414,13 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
response.endResponse();
|
response.endResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append calendar outbox object to Caldav response.
|
||||||
|
* @param response Caldav response
|
||||||
|
* @param request Caldav request
|
||||||
|
* @param subFolder outbox folder path relative to request path
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void appendOutbox(CaldavResponse response, CaldavRequest request, String subFolder) throws IOException {
|
public void appendOutbox(CaldavResponse response, CaldavRequest request, String subFolder) throws IOException {
|
||||||
response.startResponse(URIUtil.encodePath(request.getPath(subFolder)));
|
response.startResponse(URIUtil.encodePath(request.getPath(subFolder)));
|
||||||
response.startPropstat();
|
response.startPropstat();
|
||||||
|
@ -410,6 +443,10 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
response.endResponse();
|
response.endResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send simple html response to GET /.
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendGetRoot() throws IOException {
|
public void sendGetRoot() throws IOException {
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
buffer.append("Connected to DavMail<br/>");
|
buffer.append("Connected to DavMail<br/>");
|
||||||
|
@ -418,6 +455,11 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
sendHttpResponse(HttpStatus.SC_OK, null, "text/html;charset=UTF-8", buffer.toString(), true);
|
sendHttpResponse(HttpStatus.SC_OK, null, "text/html;charset=UTF-8", buffer.toString(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send inbox response for request.
|
||||||
|
* @param request Caldav request
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendInbox(CaldavRequest request) throws IOException {
|
public void sendInbox(CaldavRequest request) throws IOException {
|
||||||
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
||||||
response.startMultistatus();
|
response.startMultistatus();
|
||||||
|
@ -432,6 +474,11 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send outbox response for request.
|
||||||
|
* @param request Caldav request
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendOutbox(CaldavRequest request) throws IOException {
|
public void sendOutbox(CaldavRequest request) throws IOException {
|
||||||
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
||||||
response.startMultistatus();
|
response.startMultistatus();
|
||||||
|
@ -440,6 +487,11 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send calendar response for request.
|
||||||
|
* @param request Caldav request
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendCalendar(CaldavRequest request) throws IOException {
|
public void sendCalendar(CaldavRequest request) throws IOException {
|
||||||
String folderPath = request.getExchangeFolderPath();
|
String folderPath = request.getExchangeFolderPath();
|
||||||
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
||||||
|
@ -455,6 +507,11 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fake PROPPATCH response for request.
|
||||||
|
* @param request Caldav request
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void patchCalendar(CaldavRequest request) throws IOException {
|
public void patchCalendar(CaldavRequest request) throws IOException {
|
||||||
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
||||||
response.startMultistatus();
|
response.startMultistatus();
|
||||||
|
@ -477,6 +534,11 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report events listed in request.
|
||||||
|
* @param request Caldav request
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void reportEvents(CaldavRequest request) throws IOException {
|
public void reportEvents(CaldavRequest request) throws IOException {
|
||||||
String folderPath = request.getExchangeFolderPath();
|
String folderPath = request.getExchangeFolderPath();
|
||||||
List<ExchangeSession.Event> events;
|
List<ExchangeSession.Event> events;
|
||||||
|
@ -521,6 +583,11 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send user response for request.
|
||||||
|
* @param request Caldav request
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendUserRoot(CaldavRequest request) throws IOException {
|
public void sendUserRoot(CaldavRequest request) throws IOException {
|
||||||
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
||||||
response.startMultistatus();
|
response.startMultistatus();
|
||||||
|
@ -544,6 +611,11 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send caldav response for / request.
|
||||||
|
* @param request Caldav request
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendRoot(CaldavRequest request) throws IOException {
|
public void sendRoot(CaldavRequest request) throws IOException {
|
||||||
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
||||||
response.startMultistatus();
|
response.startMultistatus();
|
||||||
|
@ -604,6 +676,13 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send Caldav principal response.
|
||||||
|
* @param request Caldav request
|
||||||
|
* @param prefix principal prefix (users or public)
|
||||||
|
* @param principal principal name (email address for users)
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendPrincipal(CaldavRequest request, String prefix, String principal) throws IOException {
|
public void sendPrincipal(CaldavRequest request, String prefix, String principal) throws IOException {
|
||||||
// actual principal is email address
|
// actual principal is email address
|
||||||
String actualPrincipal = principal;
|
String actualPrincipal = principal;
|
||||||
|
@ -652,6 +731,11 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send free busy response for body request.
|
||||||
|
* @param body request body
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendFreeBusy(String body) throws IOException {
|
public void sendFreeBusy(String body) throws IOException {
|
||||||
HashMap<String, String> valueMap = new HashMap<String, String>();
|
HashMap<String, String> valueMap = new HashMap<String, String>();
|
||||||
ArrayList<String> attendees = new ArrayList<String>();
|
ArrayList<String> attendees = new ArrayList<String>();
|
||||||
|
@ -719,6 +803,11 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send Http error response for exception
|
||||||
|
* @param e exception
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendErr(Exception e) throws IOException {
|
public void sendErr(Exception e) throws IOException {
|
||||||
String message = e.getMessage();
|
String message = e.getMessage();
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
|
@ -727,46 +816,101 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
sendErr(HttpStatus.SC_SERVICE_UNAVAILABLE, message);
|
sendErr(HttpStatus.SC_SERVICE_UNAVAILABLE, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send 400 bad response for unsupported request.
|
||||||
|
* @param request Caldav request
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendUnsupported(CaldavRequest request) throws IOException {
|
public void sendUnsupported(CaldavRequest request) throws IOException {
|
||||||
BundleMessage message = new BundleMessage("LOG_UNSUPORTED_REQUEST", request);
|
BundleMessage message = new BundleMessage("LOG_UNSUPORTED_REQUEST", request);
|
||||||
DavGatewayTray.error(message);
|
DavGatewayTray.error(message);
|
||||||
sendErr(HttpStatus.SC_BAD_REQUEST, message.format());
|
sendErr(HttpStatus.SC_BAD_REQUEST, message.format());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send Http error status and message.
|
||||||
|
* @param status Http status
|
||||||
|
* @param message error messagee
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendErr(int status, String message) throws IOException {
|
public void sendErr(int status, String message) throws IOException {
|
||||||
sendHttpResponse(status, null, "text/plain;charset=UTF-8", message, false);
|
sendHttpResponse(status, null, "text/plain;charset=UTF-8", message, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send OPTIONS response.
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendOptions() throws IOException {
|
public void sendOptions() throws IOException {
|
||||||
HashMap<String, String> headers = new HashMap<String, String>();
|
HashMap<String, String> headers = new HashMap<String, String>();
|
||||||
headers.put("Allow", "OPTIONS, GET, PROPFIND, PUT, POST");
|
headers.put("Allow", "OPTIONS, GET, PROPFIND, PUT, POST");
|
||||||
sendHttpResponse(HttpStatus.SC_OK, headers);
|
sendHttpResponse(HttpStatus.SC_OK, headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send 401 Unauthorized response.
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendUnauthorized() throws IOException {
|
public void sendUnauthorized() throws IOException {
|
||||||
HashMap<String, String> headers = new HashMap<String, String>();
|
HashMap<String, String> headers = new HashMap<String, String>();
|
||||||
headers.put("WWW-Authenticate", "Basic realm=\"" + BundleMessage.format("UI_DAVMAIL_GATEWAY") + '\"');
|
headers.put("WWW-Authenticate", "Basic realm=\"" + BundleMessage.format("UI_DAVMAIL_GATEWAY") + '\"');
|
||||||
sendHttpResponse(HttpStatus.SC_UNAUTHORIZED, headers, null, (byte[]) null, false);
|
sendHttpResponse(HttpStatus.SC_UNAUTHORIZED, headers, null, (byte[]) null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send Http response with given status.
|
||||||
|
* @param status Http status
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendHttpResponse(int status) throws IOException {
|
public void sendHttpResponse(int status) throws IOException {
|
||||||
sendHttpResponse(status, null, null, (byte[]) null, true);
|
sendHttpResponse(status, null, null, (byte[]) null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send Http response with given status and headers.
|
||||||
|
* @param status Http status
|
||||||
|
* @param headers Http headers
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendHttpResponse(int status, Map<String, String> headers) throws IOException {
|
public void sendHttpResponse(int status, Map<String, String> headers) throws IOException {
|
||||||
sendHttpResponse(status, headers, null, (byte[]) null, true);
|
sendHttpResponse(status, headers, null, (byte[]) null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send Http response with given status in chunked mode.
|
||||||
|
* @param status Http status
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendChunkedHttpResponse(int status) throws IOException {
|
public void sendChunkedHttpResponse(int status) throws IOException {
|
||||||
HashMap<String, String> headers = new HashMap<String, String>();
|
HashMap<String, String> headers = new HashMap<String, String>();
|
||||||
headers.put("Transfer-Encoding", "chunked");
|
headers.put("Transfer-Encoding", "chunked");
|
||||||
sendHttpResponse(status, headers, "text/xml;charset=UTF-8", (byte[]) null, true);
|
sendHttpResponse(status, headers, "text/xml;charset=UTF-8", (byte[]) null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send Http response with given status, headers, content type and content.
|
||||||
|
* Close connection if keepAlive is false
|
||||||
|
* @param status Http status
|
||||||
|
* @param headers Http headers
|
||||||
|
* @param contentType MIME content type
|
||||||
|
* @param content response body as string
|
||||||
|
* @param keepAlive keep connection open
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendHttpResponse(int status, Map<String, String> headers, String contentType, String content, boolean keepAlive) throws IOException {
|
public void sendHttpResponse(int status, Map<String, String> headers, String contentType, String content, boolean keepAlive) throws IOException {
|
||||||
sendHttpResponse(status, headers, contentType, content.getBytes("UTF-8"), keepAlive);
|
sendHttpResponse(status, headers, contentType, content.getBytes("UTF-8"), keepAlive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send Http response with given status, headers, content type and content.
|
||||||
|
* Close connection if keepAlive is false
|
||||||
|
* @param status Http status
|
||||||
|
* @param headers Http headers
|
||||||
|
* @param contentType MIME content type
|
||||||
|
* @param content response body as byte array
|
||||||
|
* @param keepAlive keep connection open
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
public void sendHttpResponse(int status, Map<String, String> headers, String contentType, byte[] content, boolean keepAlive) throws IOException {
|
public void sendHttpResponse(int status, Map<String, String> headers, String contentType, byte[] content, boolean keepAlive) throws IOException {
|
||||||
sendClient("HTTP/1.1 " + status + ' ' + HttpStatus.getStatusText(status));
|
sendClient("HTTP/1.1 " + status + ' ' + HttpStatus.getStatusText(status));
|
||||||
sendClient("Server: DavMail Gateway");
|
sendClient("Server: DavMail Gateway");
|
||||||
|
@ -1111,6 +1255,9 @@ public class CaldavConnection extends AbstractConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Caldav response wrapper, content sent in chunked mode to avoid timeout
|
||||||
|
*/
|
||||||
protected class CaldavResponse {
|
protected class CaldavResponse {
|
||||||
Writer writer;
|
Writer writer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue