noel        2003/06/17 09:03:15

  Modified:    src/java/org/apache/james/core MailetConfigImpl.java
               src/java/org/apache/james/transport JamesSpoolManager.java
                        LinearProcessor.java
  Log:
  VGP's initial support for on[Matcher|Mailet]Exception
  
  Revision  Changes    Path
  1.8       +18 -0     
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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- MailetConfigImpl.java     8 Mar 2003 21:14:01 -0000       1.7
  +++ MailetConfigImpl.java     17 Jun 2003 16:03:14 -0000      1.8
  @@ -68,6 +68,8 @@
   /**
    * Implements the configuration object for a Mailet.
    *
  + * <P>CVS $Id$</P>
  + * @version 2.2.0
    */
   public class MailetConfigImpl implements MailetConfig {
   
  @@ -133,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());
  +        }
  +
       }
   
       /**
  
  
  
  1.33      +4 -4      
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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- JamesSpoolManager.java    28 Apr 2003 14:00:40 -0000      1.32
  +++ JamesSpoolManager.java    17 Jun 2003 16:03:14 -0000      1.33
  @@ -89,8 +89,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
  @@ -383,6 +383,7 @@
                               .append(mail.getName());
                       String exceptionMessage = exceptionMessageBuffer.toString();
                       getLogger().debug(exceptionMessage);
  +                    mail.setState(Mail.ERROR);
                       throw new MailetException(exceptionMessage);
                   }
                   StringBuffer logMessageBuffer = null;
  @@ -417,8 +418,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.20      +37 -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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- LinearProcessor.java      2 Jun 2003 06:19:41 -0000       1.19
  +++ LinearProcessor.java      17 Jun 2003 16:03:15 -0000      1.20
  @@ -96,6 +96,9 @@
    *  &lt;/processor&gt;
    *
    * Note that the 'onerror' attribute is not yet supported.
  + *
  + * <P>CVS $Id$</P>
  + * @version 2.2.0
    */
   public class LinearProcessor
       extends AbstractLogEnabled
  @@ -376,7 +379,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
               // recipients on the message that the matcher did not return.
  @@ -419,7 +438,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 +514,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