james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joac...@apache.org
Subject svn commit: r481388 - in /james/server/trunk/src: java/org/apache/james/imapserver/ java/org/apache/james/imapserver/commands/ java/org/apache/james/imapserver/store/ test/org/apache/james/imapserver/handler/session/
Date Fri, 01 Dec 2006 20:59:08 GMT
Author: joachim
Date: Fri Dec  1 12:59:06 2006
New Revision: 481388

URL: http://svn.apache.org/viewvc?view=rev&rev=481388
Log:
all IMAP exceptions are rethrown, nested or logged now

Modified:
    james/server/trunk/src/java/org/apache/james/imapserver/ImapHandler.java
    james/server/trunk/src/java/org/apache/james/imapserver/ImapRequestHandler.java
    james/server/trunk/src/java/org/apache/james/imapserver/ImapSessionImpl.java
    james/server/trunk/src/java/org/apache/james/imapserver/SelectedMailboxSession.java
    james/server/trunk/src/java/org/apache/james/imapserver/commands/AppendCommand.java
    james/server/trunk/src/java/org/apache/james/imapserver/commands/CommandParser.java
    james/server/trunk/src/java/org/apache/james/imapserver/commands/CommandTemplate.java
    james/server/trunk/src/java/org/apache/james/imapserver/commands/FetchCommand.java
    james/server/trunk/src/java/org/apache/james/imapserver/store/MailboxException.java
    james/server/trunk/src/java/org/apache/james/imapserver/store/SimpleImapMessage.java
    james/server/trunk/src/java/org/apache/james/imapserver/store/SimpleMessageAttributes.java
    james/server/trunk/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java

Modified: james/server/trunk/src/java/org/apache/james/imapserver/ImapHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/ImapHandler.java?view=diff&rev=481388&r1=481387&r2=481388
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/ImapHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/ImapHandler.java Fri Dec  1 12:59:06
2006
@@ -139,6 +139,7 @@
                                            this,
                                            socket.getInetAddress().getHostName(),
                                            socket.getInetAddress().getHostAddress());
+            setupLogger(session);
 
             theWatchdog.start();
             while ( handlerIsUp && !sessionEnded && requestHandler.handleRequest(
in, outs, session ) ) {

Modified: james/server/trunk/src/java/org/apache/james/imapserver/ImapRequestHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/ImapRequestHandler.java?view=diff&rev=481388&r1=481387&r2=481388
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/ImapRequestHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/ImapRequestHandler.java Fri Dec
 1 12:59:06 2006
@@ -94,6 +94,7 @@
             tag = parser.tag( request );
         }
         catch ( ProtocolException e ) {
+            getLogger().debug("error parsing request", e);
             response.badResponse( REQUEST_SYNTAX );
             return;
         }
@@ -108,6 +109,7 @@
             commandName = parser.atom( request );
         }
         catch ( ProtocolException e ) {
+            getLogger().debug("error parsing request", e);            
             response.commandError( REQUEST_SYNTAX );
             return;
         }

Modified: james/server/trunk/src/java/org/apache/james/imapserver/ImapSessionImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/ImapSessionImpl.java?view=diff&rev=481388&r1=481387&r2=481388
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/ImapSessionImpl.java (original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/ImapSessionImpl.java Fri Dec 
1 12:59:06 2006
@@ -22,6 +22,7 @@
 
 import javax.mail.Flags;
 
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.james.imapserver.store.MailboxException;
 import org.apache.james.imapserver.store.MessageFlags;
 import org.apache.james.mailboxmanager.MailboxManagerException;
@@ -35,7 +36,7 @@
 /**
  * @version $Revision: 109034 $
  */
-public final class ImapSessionImpl implements ImapSession, ImapConstants
+public final class ImapSessionImpl extends AbstractLogEnabled implements ImapSession, ImapConstants
 {
     private ImapSessionState state = ImapSessionState.NON_AUTHENTICATED;
     private User user = null;
@@ -166,6 +167,7 @@
     public void setSelected( ImapMailboxSession mailbox, boolean readOnly ) throws MailboxManagerException
     {
         SelectedMailboxSession sessionMailbox = new SelectedMailboxSession(mailbox, this,
readOnly);
+        setupLogger(sessionMailbox);
         this.state = ImapSessionState.SELECTED;
         closeMailbox();
         this.selectedMailbox = sessionMailbox;

Modified: james/server/trunk/src/java/org/apache/james/imapserver/SelectedMailboxSession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/SelectedMailboxSession.java?view=diff&rev=481388&r1=481387&r2=481388
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/SelectedMailboxSession.java (original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/SelectedMailboxSession.java Fri
Dec  1 12:59:06 2006
@@ -30,13 +30,16 @@
 
 import javax.mail.Flags;
 
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.james.imapserver.store.MailboxException;
 import org.apache.james.mailboxmanager.MailboxListener;
 import org.apache.james.mailboxmanager.MailboxManagerException;
 import org.apache.james.mailboxmanager.MessageResult;
 import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
 
-public class SelectedMailboxSession implements MailboxListener {
+import sun.security.action.GetLongAction;
+
+public class SelectedMailboxSession extends AbstractLogEnabled implements MailboxListener
{
 
     private ImapSession _session;
     private boolean _readonly;
@@ -62,6 +65,7 @@
         try {
             _session.closeConnection("Mailbox " + mailbox.getName() + " has been deleted");
         } catch (MailboxManagerException e) {
+            getLogger().error("error closing connection", e);
         }
     }
 

Modified: james/server/trunk/src/java/org/apache/james/imapserver/commands/AppendCommand.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/commands/AppendCommand.java?view=diff&rev=481388&r1=481387&r2=481388
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/commands/AppendCommand.java (original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/commands/AppendCommand.java Fri
Dec  1 12:59:06 2006
@@ -155,7 +155,7 @@
                         messageBytes));
             } catch (Exception e) {
                 throw new ProtocolException("UnexpectedException: "
-                        + e.getMessage());
+                        + e.getMessage(), e);
 
             }
             return mm;

Modified: james/server/trunk/src/java/org/apache/james/imapserver/commands/CommandParser.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/commands/CommandParser.java?view=diff&rev=481388&r1=481387&r2=481388
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/commands/CommandParser.java (original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/commands/CommandParser.java Fri
Dec  1 12:59:06 2006
@@ -136,7 +136,7 @@
             return dateFormat.parse( dateString );
         }
         catch ( ParseException e ) {
-            throw new ProtocolException( "Invalid date format." );
+            throw new ProtocolException( "Invalid date format.", e);
         }
     }
 
@@ -160,7 +160,7 @@
             return dateFormat.parse( dateString );
         }
         catch ( ParseException e ) {
-            throw new ProtocolException( "Invalid date format." );
+            throw new ProtocolException( "Invalid date format.", e);
         }
     }
 
@@ -450,7 +450,7 @@
             }
         }
         catch ( NumberFormatException e ) {
-            throw new ProtocolException( "Invalid message set.");
+            throw new ProtocolException( "Invalid message set.", e);
         }
     }
 

Modified: james/server/trunk/src/java/org/apache/james/imapserver/commands/CommandTemplate.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/commands/CommandTemplate.java?view=diff&rev=481388&r1=481387&r2=481388
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/commands/CommandTemplate.java
(original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/commands/CommandTemplate.java
Fri Dec  1 12:59:06 2006
@@ -66,13 +66,16 @@
             doProcess( request, response, session );
         }
         catch ( MailboxException e ) {
+            getLogger().debug("error processing command ", e);
             response.commandFailed( this, e.getResponseCode(), e.getMessage() );
         }
         catch ( AuthorizationException e ) {
+            getLogger().debug("error processing command ", e);
             String msg = "Authorization error: Lacking permissions to perform requested operation.";
             response.commandFailed( this, msg );
         }
         catch ( ProtocolException e ) {
+            getLogger().debug("error processing command ", e);
             String msg = e.getMessage() + " Command should be '" +
                     getExpectedMessage() + "'";
             response.commandError( msg );

Modified: james/server/trunk/src/java/org/apache/james/imapserver/commands/FetchCommand.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/commands/FetchCommand.java?view=diff&rev=481388&r1=481387&r2=481388
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/commands/FetchCommand.java (original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/commands/FetchCommand.java Fri
Dec  1 12:59:06 2006
@@ -194,8 +194,7 @@
                 try {
                     handleBodyFetch(mimeMessage, sectionSpecifier, response);
                 } catch (MessagingException e) {
-                    // TODO chain exceptions
-                    throw new MailboxException(e.getMessage());
+                    throw new MailboxException(e.getMessage(), e);
                 }
             }
 
@@ -225,7 +224,7 @@
                 mimeMessage.writeTo(new CRLFOutputStream(bout));
             }
             catch ( IOException e ) {
-                throw new ProtocolException( "Error reading message source" );
+                throw new ProtocolException( "Error reading message source", e);
             }
             byte[] bytes = bout.toByteArray();
             addLiteral( bytes, response );
@@ -267,7 +266,7 @@
 
             }
             catch ( IOException e ) {
-                throw new ProtocolException( "Error reading message source" );
+                throw new ProtocolException( "Error reading message source", e);
             }
         }
         else {

Modified: james/server/trunk/src/java/org/apache/james/imapserver/store/MailboxException.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/store/MailboxException.java?view=diff&rev=481388&r1=481387&r2=481388
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/store/MailboxException.java (original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/store/MailboxException.java Fri
Dec  1 12:59:06 2006
@@ -96,6 +96,10 @@
         super(e);
     }
 
+    public MailboxException(String message, MessagingException e) {
+        super(message, e);
+    }
+
     public String getStatus()
     {
         return status;

Modified: james/server/trunk/src/java/org/apache/james/imapserver/store/SimpleImapMessage.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/store/SimpleImapMessage.java?view=diff&rev=481388&r1=481387&r2=481388
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/store/SimpleImapMessage.java (original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/store/SimpleImapMessage.java Fri
Dec  1 12:59:06 2006
@@ -82,7 +82,7 @@
                 attributes.setAttributesFor( mimeMessage );
             }
             catch ( MessagingException e ) {
-                throw new MailboxException( "Could not parse mime message." );
+                throw new MailboxException( "Could not parse mime message.", e);
             }
         }
         return attributes;

Modified: james/server/trunk/src/java/org/apache/james/imapserver/store/SimpleMessageAttributes.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/store/SimpleMessageAttributes.java?view=diff&rev=481388&r1=481387&r2=481388
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/store/SimpleMessageAttributes.java
(original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/store/SimpleMessageAttributes.java
Fri Dec  1 12:59:06 2006
@@ -111,6 +111,7 @@
         try {
             internalDate = msg.getSentDate();
         } catch (MessagingException me) {
+            getLogger().debug("error getting sent date", me);
         }
         if (internalDate == null) {
             // TODO setAttributesFor: decide what to do when internalDate is null
@@ -137,59 +138,59 @@
             try {
                 subject = ((MimeMessage)part).getSubject();
             } catch (MessagingException me) {
-                if (DEBUG) getLogger().debug("Messaging Exception for getSubject: " + me);
+                getLogger().debug("Messaging Exception for getSubject: " + me, me);
             }
         }
         try {
             from = part.getHeader("From");
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getHeader(From): " + me);
+            getLogger().debug("Messaging Exception for getHeader(From): " + me, me);
         }
         try {
             sender = part.getHeader("Sender");
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getHeader(Sender): " +
me);
+            getLogger().debug("Messaging Exception for getHeader(Sender): " + me, me);
         }
         try {
             replyTo = part.getHeader("Reply To");
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getHeader(Reply To): "
+ me);
+            getLogger().debug("Messaging Exception for getHeader(Reply To): " + me, me);
         }
         try {
             to = part.getHeader("To");
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getHeader(To): " + me);
+            getLogger().debug("Messaging Exception for getHeader(To): " + me, me);
         }
         try {
             cc = part.getHeader("Cc");
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getHeader(To): " + me);
+            getLogger().debug("Messaging Exception for getHeader(To): " + me, me);
         }
         try {
             bcc = part.getHeader("Bcc");
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getHeader(To): " + me);
+            getLogger().debug("Messaging Exception for getHeader(To): " + me, me);
         }
         try {
             inReplyTo = part.getHeader("In Reply To");
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getHeader(In Reply To):
" + me);
+            getLogger().debug("Messaging Exception for getHeader(In Reply To): " + me, me);
         }
         try {
             date = part.getHeader("Date");
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getHeader(Date): " + me);
+           getLogger().debug("Messaging Exception for getHeader(Date): " + me, me);
         }
         try {
             messageID = part.getHeader("Message-ID");
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getHeader(messageID): "
+ me);
+            getLogger().debug("Messaging Exception for getHeader(messageID): " + me, me);
         }
         String contentTypeLine = null;
         try {
             contentTypeLine = part.getContentType();
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getContentType(): " + me);
+           getLogger().debug("Messaging Exception for getContentType(): " + me, me);
         }
         if (contentTypeLine !=null ) {
             decodeContentType(contentTypeLine);
@@ -197,12 +198,12 @@
         try {
             contentID = part.getContentID();
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getContentUD(): " + me);
+            getLogger().debug("Messaging Exception for getContentUD(): " + me, me);
         }
         try {
             contentDesc = part.getDescription();
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getDescription(): " + me);
+            getLogger().debug("Messaging Exception for getDescription(): " + me, me);
         }
         try {
             contentEncoding = part.getEncoding();
@@ -211,13 +212,13 @@
                 contentEncoding = "7BIT";
             }
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getEncoding(): " + me);
+            getLogger().debug("Messaging Exception for getEncoding(): " + me, me);
         }
         if (DEBUG) {
             try {
                 String contentDisposition = part.getDisposition();
             } catch (MessagingException me) {
-                getLogger().debug("Messaging Exception for getEncoding(): " + me);
+                getLogger().debug("Messaging Exception for getEncoding(): " + me, me);
             }
         }
 
@@ -225,9 +226,9 @@
             // TODO this doesn't work
             lineCount = part.getLineCount();
         } catch (MessagingException me) {
-            if (DEBUG) getLogger().debug("Messaging Exception for getLineCount(): " + me);
+            getLogger().debug("Messaging Exception for getLineCount(): " + me, me);
         } catch (Exception e) {
-            if (DEBUG) getLogger().debug("Exception for getLineCount(): " + e);
+            getLogger().debug("Exception for getLineCount(): " + e, e);
         }
 
         // Recurse through any embedded parts
@@ -251,8 +252,7 @@
                     }
                 }
             } catch (Exception e) {
-                getLogger().debug("Messaging Exception for getContent(): " + e);
-                e.printStackTrace();
+                getLogger().debug("Messaging Exception for getContent(): " + e, e);
             }
         } else if (primaryType.equalsIgnoreCase("message")) {
             getLogger().info("This part contains an embedded message of subtype: " + secondaryType);
@@ -412,6 +412,7 @@
             try {
                 netAddr = new InternetAddress(address);
             } catch (AddressException ae) {
+                getLogger().debug("error parsing address", ae);
                 return null;
             }
             String personal = netAddr.getPersonal();
@@ -429,6 +430,7 @@
                 buf.append(SP);
                 buf.append(Q + mailAddr.getHost() + Q);
             } catch (ParseException pe) {
+                getLogger().debug("error parsing MailAddress", pe);
                 buf.append( NIL + SP + NIL);
             }
             buf.append(RB);
@@ -446,7 +448,7 @@
     void decodeContentType(String rawLine) {
         int slash = rawLine.indexOf("/");
         if( slash == -1){
-            if (DEBUG) getLogger().debug("decoding ... no slash found");
+            getLogger().debug("decoding ... no slash found");
             return;
         } else {
             primaryType = rawLine.substring(0, slash).trim();
@@ -562,9 +564,7 @@
             buf.append(RB);
             return buf.toString();
         } catch (Exception e) {
-            getLogger().error("Exception while parsing BodyStrucuture: " + e);
-            e.printStackTrace();
-            throw new RuntimeException("Exception in parseBodyStructure");
+            throw new RuntimeException("Exception in parseBodyStructure", e);
         }
     }
 

Modified: james/server/trunk/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java?view=diff&rev=481388&r1=481387&r2=481388
==============================================================================
--- james/server/trunk/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java
(original)
+++ james/server/trunk/src/test/org/apache/james/imapserver/handler/session/AbstractSessionTest.java
Fri Dec  1 12:59:06 2006
@@ -38,6 +38,7 @@
 import javax.mail.Flags.Flag;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.avalon.framework.logger.LogEnabled;
 import org.apache.james.imapserver.ImapRequestHandler;
 import org.apache.james.imapserver.ImapSession;
 import org.apache.james.imapserver.ImapSessionImpl;
@@ -79,6 +80,7 @@
         session = new ImapSessionImpl(theConfigData.getMailboxManagerProvider(),
                 theConfigData.getUsersRepository(), new MockImapHandler(),
                 HOST_NAME, HOST_ADDRESS);
+        ((LogEnabled)session).enableLogging(new MockLogger());
         handler = new ImapRequestHandler();
         handler.enableLogging(new MockLogger());
         mailboxManager=theConfigData.getMailboxManagerProvider().getMailboxManagerInstance(new
MockUser());



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message