Improve exception handling : log exception name

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@37 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2007-03-14 11:55:37 +00:00
parent f75d326d3c
commit 47ebe0e153
7 changed files with 43 additions and 28 deletions

View File

@ -12,7 +12,7 @@ import java.net.Socket;
* Generic connection common to pop3 and smtp implementations
*/
public class AbstractConnection extends Thread {
protected Socket client;
protected BufferedReader in;
protected OutputStream os;
@ -34,7 +34,7 @@ public class AbstractConnection extends Thread {
try {
client.close();
} catch (IOException e2) {
DavGatewayTray.error("Exception while getting socket streams",e2);
DavGatewayTray.error("Exception while getting socket streams", e2);
}
DavGatewayTray.error("Exception while getting socket streams", e);
return;
@ -64,13 +64,14 @@ public class AbstractConnection extends Thread {
/**
* Read a line from the client connection.
* Log message to stdout
*
* @return command line or null
* @throws IOException
* @throws IOException when unable to read line
*/
public String readClient() throws IOException {
String line = in.readLine();
if (line != null && !line.startsWith("PASS")) {
DavGatewayTray.debug("< "+line);
DavGatewayTray.debug("< " + line);
} else {
DavGatewayTray.debug("< PASS ********");
}

View File

@ -12,6 +12,7 @@ public class DavGateway {
/**
* Start the gateway, listen on spécified smtp and pop3 ports
* @param args command line parameter config file path
*/
public static void main(String[] args) {

View File

@ -80,6 +80,8 @@ public class BASE64EncoderStream extends FilterOutputStream {
/**
* Builds a BASE64 encoding stream on top of the given underlying output
* stream, with the default maximum number of characters per line.
*
* @param out output stream
**/
public BASE64EncoderStream(OutputStream out) {
this(out, LINE_LENGTH);
@ -117,6 +119,7 @@ public class BASE64EncoderStream extends FilterOutputStream {
try {
flush();
} catch (IOException ignored) {
// ignore
}
@ -347,7 +350,8 @@ public class BASE64EncoderStream extends FilterOutputStream {
encoder.close();
} catch (IOException e) {
} // try
// ignore
} // try
// Return Encoded Byte Array
return byteStream.toByteArray();

View File

@ -120,8 +120,6 @@ public class ExchangeSession {
/**
* Create an exchange session for the given URL.
* The session is not actually established until a call to login()
*
* @param url Outlook Web Access URL
*/
public ExchangeSession() {
// SimpleDateFormat are not thread safe, need to create one instance for
@ -320,7 +318,7 @@ public class ExchangeSession {
* Close session.
* This will only close http client, not the actual Exchange session
*
* @throws IOException
* @throws IOException if unable to close Webdav context
*/
public void close() throws IOException {
wdr.close();
@ -328,6 +326,10 @@ public class ExchangeSession {
/**
* Create message in current folder
*
* @param subject message subject line
* @param messageBody mail body
* @throws java.io.IOException when unable to create message
*/
public void createMessage(String subject, String messageBody) throws IOException {
createMessage(currentFolderUrl, subject, messageBody);
@ -336,6 +338,11 @@ public class ExchangeSession {
/**
* Create message in specified folder.
* Will overwrite an existing message with same subject in the same folder
*
* @param folderUrl Exchange folder URL
* @param subject message subject line
* @param messageBody mail body
* @throws java.io.IOException when unable to create message
*/
public void createMessage(String folderUrl, String subject, String messageBody) throws IOException {
String messageUrl = URIUtil.encodePathQuery(folderUrl + "/" + subject + ".EML");
@ -448,7 +455,8 @@ public class ExchangeSession {
/**
* Delete oldest messages in trash.
* keepDelay is the number of days to keep messages in trash before delete
* @throws IOException
*
* @throws IOException when unable to purge messages
*/
public void purgeOldestTrashMessages() throws IOException {
int keepDelay = Settings.getIntProperty("davmail.keepDelay");
@ -645,9 +653,9 @@ public class ExchangeSession {
fullHeaders += "CC: " + cc + "\n";
}
} catch (ParseException e) {
throw new RuntimeException("Unable to rebuild header " + e.getMessage());
throw new RuntimeException("Unable to rebuild header " + e + " " + e.getMessage());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Unable to rebuild header " + e.getMessage());
throw new RuntimeException("Unable to rebuild header " + e + " " + e.getMessage());
}
}
StringBuffer result = new StringBuffer();
@ -741,7 +749,7 @@ public class ExchangeSession {
}
} catch (IOException e) {
throw new RuntimeException("Unable to preprocess headers " + e.getMessage());
throw new RuntimeException("Unable to preprocess headers " + e + " " + e.getMessage());
}
}
@ -835,7 +843,7 @@ public class ExchangeSession {
quotedOs = (MimeUtility.encode(os, mimeHeader.contentTransferEncoding));
}
} catch (MessagingException e) {
throw new IOException(e.getMessage());
throw new IOException(e + " " + e.getMessage());
}
String decodedPath = URIUtil.decode(attachment.href);
@ -882,7 +890,7 @@ public class ExchangeSession {
}
} catch (HttpException e) {
throw new IOException(e.getMessage());
throw new IOException(e + " " + e.getMessage());
}
}
@ -891,7 +899,7 @@ public class ExchangeSession {
try {
quotedOs = (MimeUtility.encode(os, mimeHeader.contentTransferEncoding));
} catch (MessagingException e) {
throw new IOException(e.getMessage());
throw new IOException(e + " " + e.getMessage());
}
String currentBody;
if ("text/html".equals(mimeHeader.contentType)) {
@ -1144,7 +1152,7 @@ public class ExchangeSession {
List<Attribute> htmlBodyAllImgList = xmlBody.getNodes("//img/@src");
// remove absolute images from body img list
List<String> htmlBodyImgList = new ArrayList<String>();
for (Attribute imgAttribute:htmlBodyAllImgList) {
for (Attribute imgAttribute : htmlBodyAllImgList) {
String value = imgAttribute.getValue();
if (!value.startsWith("http://") && !value.startsWith("https://")) {
htmlBodyImgList.add(value);

View File

@ -99,13 +99,13 @@ public class PopConnection extends AbstractConnection {
sendOK("PASS");
state = AUTHENTICATED;
} catch (UnknownHostException e) {
DavGatewayTray.error("Connection failed",e);
sendERR("Connection failed : "+e+" "+e.getMessage());
DavGatewayTray.error("Connection failed", e);
sendERR("Connection failed : " + e + " " + e.getMessage());
// close connection
break;
} catch (Exception e) {
DavGatewayTray.error("Authentication failed",e);
sendERR("authentication failed : "+e+" "+e.getMessage());
DavGatewayTray.error("Authentication failed", e);
sendERR("authentication failed : " + e + " " + e.getMessage());
}
}
} else if ("CAPA".equalsIgnoreCase(command)) {
@ -136,8 +136,8 @@ public class PopConnection extends AbstractConnection {
sendClient("");
sendClient(".");
} catch (Exception e) {
DavGatewayTray.error("Error retreiving message",e);
sendERR("error retreiving message " + e.getMessage());
DavGatewayTray.error("Error retreiving message", e);
sendERR("error retreiving message " + e + " " + e.getMessage());
}
} else {
sendERR("invalid message number");
@ -150,7 +150,7 @@ public class PopConnection extends AbstractConnection {
messages.get(messageNumber).delete();
sendOK("DELETE");
} catch (Exception e) {
DavGatewayTray.error("Error deleting message",e);
DavGatewayTray.error("Error deleting message", e);
sendERR("error deleting message");
}
} else {
@ -185,19 +185,19 @@ public class PopConnection extends AbstractConnection {
os.flush();
}
} catch (IOException e) {
DavGatewayTray.error("Exception handling client",e);
DavGatewayTray.error("Exception handling client", e);
} finally {
try {
client.close();
} catch (IOException e2) {
DavGatewayTray.debug("Exception closing client",e2);
DavGatewayTray.debug("Exception closing client", e2);
}
try {
if (session != null) {
session.close();
}
} catch (IOException e3) {
DavGatewayTray.debug("Exception closing gateway",e3);
DavGatewayTray.debug("Exception closing gateway", e3);
}
}

View File

@ -14,6 +14,7 @@ public class PopServer extends AbstractServer {
/**
* Create a ServerSocket to listen for connections.
* Start the thread.
* @param port pop listen port, 110 if not defined (0)
*/
public PopServer(int port) {
super((port == 0) ? PopServer.DEFAULT_PORT : port);

View File

@ -102,7 +102,7 @@ public class SmtpConnection extends AbstractConnection {
} catch (Exception e) {
DavGatewayTray.error("Authentication failed",e);
state = AUTHENTICATED;
sendClient("451 Error : " + e.getMessage());
sendClient("451 Error : " +e+" "+ e.getMessage());
}
} else {
@ -140,7 +140,7 @@ public class SmtpConnection extends AbstractConnection {
* Decode SMTP credentials
*
* @param encodedCredentials smtp encoded credentials
* @throws java.io.IOException
* @throws java.io.IOException if invalid credentials
*/
protected void decodeCredentials(String encodedCredentials) throws IOException {
BASE64Decoder decoder = new BASE64Decoder();