Improve socket closed error handling

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1374 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-08-24 08:16:32 +00:00
parent 70f0cf851e
commit 3ecc0aa80e
4 changed files with 16 additions and 4 deletions

View File

@ -1534,6 +1534,7 @@ public abstract class ExchangeSession {
// load and parse message
mimeBody = new SharedByteArrayInputStream(getContent(this));
mimeMessage = new MimeMessage(null, mimeBody);
mimeBody.reset();
LOGGER.debug("Downloaded full message content for IMAP UID " + imapUid + " (" + mimeBody.available() + " bytes)");
}
}

View File

@ -32,6 +32,7 @@ import davmail.ui.tray.DavGatewayTray;
import davmail.util.IOUtil;
import davmail.util.StringUtil;
import org.apache.commons.httpclient.HttpException;
import org.apache.log4j.Logger;
import javax.mail.MessagingException;
import javax.mail.internet.*;
@ -49,6 +50,7 @@ import java.util.*;
* Still alpha code : need to find a way to handle message ids
*/
public class ImapConnection extends AbstractConnection {
private static final Logger LOGGER = Logger.getLogger(ImapConnection.class);
ExchangeSession.Folder currentFolder;
@ -278,6 +280,9 @@ public class ImapConnection extends AbstractConnection {
ExchangeSession.Message message = uidRangeIterator.next();
try {
handleFetch(message, uidRangeIterator.currentIndex, parameters);
} catch (SocketException e) {
// client closed connection
throw e;
} catch (IOException e) {
DavGatewayTray.log(e);
sendClient(commandId + " NO Unable to retrieve message: " + e.getMessage());
@ -549,7 +554,7 @@ public class ImapConnection extends AbstractConnection {
DavGatewayTray.debug(new BundleMessage("LOG_EXCEPTION_CLOSING_CONNECTION_ON_TIMEOUT"));
}
} catch (SocketException e) {
DavGatewayTray.debug(new BundleMessage("LOG_CLIENT_CLOSED_CONNECTION"));
LOGGER.warn(BundleMessage.formatLog("LOG_CLIENT_CLOSED_CONNECTION"));
} catch (Exception e) {
DavGatewayTray.log(e);
try {

View File

@ -27,7 +27,9 @@ import davmail.Settings;
import davmail.exception.DavMailException;
import davmail.exchange.ExchangeSession;
import davmail.exchange.ExchangeSessionFactory;
import davmail.imap.ImapConnection;
import davmail.ui.tray.DavGatewayTray;
import org.apache.log4j.Logger;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@ -43,6 +45,7 @@ import java.util.*;
* Handle a caldav connection.
*/
public class LdapConnection extends AbstractConnection {
private static final Logger LOGGER = Logger.getLogger(LdapConnection.class);
/**
* Davmail base context
*/
@ -1390,7 +1393,7 @@ public class LdapConnection extends AbstractConnection {
}
} catch (SocketException e) {
// client closed connection
DavGatewayTray.debug(new BundleMessage("LOG_CLIENT_CLOSED_CONNECTION"));
LOGGER.warn(BundleMessage.formatLog("LOG_CLIENT_CLOSED_CONNECTION"));
} catch (IOException e) {
DavGatewayTray.log(e);
try {

View File

@ -25,6 +25,7 @@ import davmail.exchange.ExchangeSession;
import davmail.exchange.ExchangeSessionFactory;
import davmail.ui.tray.DavGatewayTray;
import davmail.util.IOUtil;
import org.apache.log4j.Logger;
import java.io.FilterOutputStream;
import java.io.IOException;
@ -39,6 +40,8 @@ import java.util.StringTokenizer;
* Dav Gateway pop connection implementation
*/
public class PopConnection extends AbstractConnection {
private static final Logger LOGGER = Logger.getLogger(PopConnection.class);
private List<ExchangeSession.Message> messages;
/**
@ -136,7 +139,7 @@ public class PopConnection extends AbstractConnection {
state = State.AUTHENTICATED;
} catch (SocketException e) {
// can not send error to client after a socket exception
DavGatewayTray.warn(new BundleMessage("LOG_CLIENT_CLOSED_CONNECTION"), e);
LOGGER.warn(BundleMessage.formatLog("LOG_CLIENT_CLOSED_CONNECTION"));
} catch (Exception e) {
DavGatewayTray.error(e);
sendERR(e);
@ -202,7 +205,7 @@ public class PopConnection extends AbstractConnection {
doubleDotOutputStream.close();
} catch (SocketException e) {
// can not send error to client after a socket exception
DavGatewayTray.warn(new BundleMessage("LOG_CLIENT_CLOSED_CONNECTION"), e);
LOGGER.warn(BundleMessage.formatLog("LOG_CLIENT_CLOSED_CONNECTION"));
} catch (Exception e) {
DavGatewayTray.error(new BundleMessage("LOG_ERROR_RETRIEVING_MESSAGE"), e);
sendERR("error retreiving message " + e + ' ' + e.getMessage());