noel        2003/06/15 22:25:28

  Modified:    src/java/org/apache/james/core Tag: branch_2_1_fcs
                        MailetConfigImpl.java
               src/java/org/apache/james/transport Tag: branch_2_1_fcs
                        JamesSpoolManager.java LinearProcessor.java
  Log:
  VGP's initial support for on[Matcher|Mailet]Exception
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.3.4.3   +18 -1     
jakarta-james/src/java/org/apache/james/core/MailetConfigImpl.java
  
  Index: MailetConfigImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-james/src/java/org/apache/james/core/MailetConfigImpl.java,v
  retrieving revision 1.3.4.2
  retrieving revision 1.3.4.3
  diff -u -r1.3.4.2 -r1.3.4.3
  --- MailetConfigImpl.java     8 Mar 2003 21:54:03 -0000       1.3.4.2
  +++ MailetConfigImpl.java     16 Jun 2003 05:25:27 -0000      1.3.4.3
  @@ -68,7 +68,8 @@
   /**
    * Implements the configuration object for a Mailet.
    *
  - * @author Serge Knystautas <[EMAIL PROTECTED]>
  + * <P>CVS $Id$</P>
  + * @version 2.2.0
    */
   public class MailetConfigImpl implements MailetConfig {
   
  @@ -134,6 +135,22 @@
       public Iterator getInitParameterNames() {
           throw new UnsupportedOperationException("Not yet implemented");
           //return params.keySet().iterator();
  +    }
  +
  +    /**
  +     * Get the value of an (XML) attribute stored in this MailetConfig.
  +     *
  +     * @param name the name of the attribute whose value is to be retrieved.
  +     *
  +     * @return the attribute value
  +     */
  +    public String getInitAttribute(String name) {
  +        try {
  +            return configuration.getAttribute(name);
  +        } catch (ConfigurationException ce) {
  +            throw new RuntimeException("Embedded configuration exception was: " + 
ce.getMessage());
  +        }
  +
       }
   
       /**
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.20.4.6  +4 -3      
jakarta-james/src/java/org/apache/james/transport/JamesSpoolManager.java
  
  Index: JamesSpoolManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-james/src/java/org/apache/james/transport/JamesSpoolManager.java,v
  retrieving revision 1.20.4.5
  retrieving revision 1.20.4.6
  diff -u -r1.20.4.5 -r1.20.4.6
  --- JamesSpoolManager.java    2 Jun 2003 05:37:27 -0000       1.20.4.5
  +++ JamesSpoolManager.java    16 Jun 2003 05:25:27 -0000      1.20.4.6
  @@ -88,7 +88,8 @@
    * processor, and removing them from the spool when processing is
    * complete.
    *
  - * @version This is $Revision$
  + * <P>CVS $Id$</P>
  + * @version 2.2.0
    */
   public class JamesSpoolManager
       extends AbstractLogEnabled
  @@ -425,6 +426,7 @@
                               .append(mail.getName());
                       String exceptionMessage = exceptionMessageBuffer.toString();
                       getLogger().debug(exceptionMessage);
  +                    mail.setState(Mail.ERROR);
                       throw new MailetException(exceptionMessage);
                   }
                   StringBuffer logMessageBuffer = null;
  @@ -464,8 +466,7 @@
                       mail.setState(Mail.GHOST);
                       mail.setErrorMessage(e.getMessage());
                   } else {
  -                    //We got an error... send it to the error processor
  -                    mail.setState(Mail.ERROR);
  +                    //We got an error... send it to the requested processor
                       mail.setErrorMessage(e.getMessage());
                   }
               }
  
  
  
  1.10.4.4  +39 -4     
jakarta-james/src/java/org/apache/james/transport/LinearProcessor.java
  
  Index: LinearProcessor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-james/src/java/org/apache/james/transport/LinearProcessor.java,v
  retrieving revision 1.10.4.3
  retrieving revision 1.10.4.4
  diff -u -r1.10.4.3 -r1.10.4.4
  --- LinearProcessor.java      2 Jun 2003 05:40:27 -0000       1.10.4.3
  +++ LinearProcessor.java      16 Jun 2003 05:25:28 -0000      1.10.4.4
  @@ -63,6 +63,7 @@
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.james.core.MailImpl;
  +import org.apache.james.core.MailetConfigImpl;
   import org.apache.james.services.SpoolRepository;
   import org.apache.mailet.*;
   
  @@ -74,6 +75,7 @@
   import java.util.List;
   import java.util.Random;
   import java.util.Iterator;
  +import java.util.Locale;
   
   /**
    * Implements a processor for mails, directing the mail down
  @@ -95,6 +97,9 @@
    *  </processor>
    *
    * Note that the 'onerror' attribute is not yet supported.
  + *
  + * <P>CVS $Id$</P>
  + * @version 2.2.0
    */
   public class LinearProcessor 
       extends AbstractLogEnabled
  @@ -375,7 +380,23 @@
                       verifyMailAddresses(recipients);
                   }
               } catch (MessagingException me) {
  -                handleException(me, mail, 
matcher.getMatcherConfig().getMatcherName());
  +                // look in the matcher's mailet's init attributes
  +                MailetConfig mailetConfig = ((Mailet) 
mailets.get(i)).getMailetConfig();
  +                String onMatchException = ((MailetConfigImpl) 
mailetConfig).getInitAttribute("onMatchException");
  +                if (onMatchException == null) {
  +                    onMatchException = Mail.ERROR;
  +                } else {
  +                    onMatchException = 
onMatchException.trim().toLowerCase(Locale.US);
  +                }
  +                if (onMatchException.compareTo("nomatch") == 0) {
  +                    //In case the matcher returned null, create an empty Collection
  +                    recipients = new ArrayList(0);
  +                } else if (onMatchException.compareTo("matchall") == 0) {
  +                    recipients = mail.getRecipients();
  +                    // no need to verify addresses
  +                } else {
  +                    handleException(me, mail, 
matcher.getMatcherConfig().getMatcherName(), onMatchException);
  +                }
               }
   
               // Split the recipients into two pools.  notRecipients will contain the
  @@ -419,7 +440,20 @@
                   // Make sure all the recipients are still MailAddress objects
                   verifyMailAddresses(mail.getRecipients());
               } catch (MessagingException me) {
  -                handleException(me, mail, mailet.getMailetConfig().getMailetName());
  +                MailetConfig mailetConfig = mailet.getMailetConfig();
  +                String onMailetException = ((MailetConfigImpl) 
mailetConfig).getInitAttribute("onMailetException");
  +                if (onMailetException == null) {
  +                    onMailetException = Mail.ERROR;
  +                } else {
  +                    onMailetException = 
onMailetException.trim().toLowerCase(Locale.US);
  +                }
  +                if (onMailetException.compareTo("ignore") == 0) {
  +                    // ignore the exception and continue
  +                    // this option should not be used if the mail object can be 
changed by the mailet
  +                    verifyMailAddresses(mail.getRecipients());
  +                } else {
  +                    handleException(me, mail, 
mailet.getMailetConfig().getMailetName(), onMailetException);
  +                }
               }
   
               // See if the state was changed by the mailet
  @@ -482,12 +516,13 @@
        * @param me the exception to be handled
        * @param mail the mail being processed when the exception was generated
        * @param offendersName the matcher or mailet than generated the exception
  +     * @param nextState the next state to set
        *
        * @throws MessagingException thrown always, rethrowing the passed in exception
        */
  -    private void handleException(MessagingException me, Mail mail, String 
offendersName) throws MessagingException {
  +    private void handleException(MessagingException me, Mail mail, String 
offendersName, String nextState) throws MessagingException {
           System.err.println("exception! " + me);
  -        mail.setState(Mail.ERROR);
  +        mail.setState(nextState);
           StringWriter sout = new StringWriter();
           PrintWriter out = new PrintWriter(sout, true);
           StringBuffer exceptionBuffer =
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to