james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <server-...@james.apache.org>
Subject [jira] [Commented] (JAMES-2275) Allow per Exception error handling in the mailet pipeline
Date Tue, 09 Jan 2018 03:21:00 GMT

    [ https://issues.apache.org/jira/browse/JAMES-2275?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16317612#comment-16317612
] 

ASF GitHub Bot commented on JAMES-2275:
---------------------------------------

Github user chibenwa commented on a diff in the pull request:

    https://github.com/apache/james-project/pull/96#discussion_r160310811
  
    --- Diff: mailet/standard/src/main/java/org/apache/james/transport/matchers/HasException.java
---
    @@ -0,0 +1,126 @@
    +/****************************************************************
    + * Licensed to the Apache Software Foundation (ASF) under one   *
    + * or more contributor license agreements.  See the NOTICE file *
    + * distributed with this work for additional information        *
    + * regarding copyright ownership.  The ASF licenses this file   *
    + * to you under the Apache License, Version 2.0 (the            *
    + * "License"); you may not use this file except in compliance   *
    + * with the License.  You may obtain a copy of the License at   *
    + *                                                              *
    + *   http://www.apache.org/licenses/LICENSE-2.0                 *
    + *                                                              *
    + * Unless required by applicable law or agreed to in writing,   *
    + * software distributed under the License is distributed on an  *
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
    + * KIND, either express or implied.  See the License for the    *
    + * specific language governing permissions and limitations      *
    + * under the License.                                           *
    + ****************************************************************/
    +
    +
    +
    +package org.apache.james.transport.matchers;
    +
    +import java.util.Collection;
    +
    +import javax.mail.MessagingException;
    +
    +import org.apache.mailet.Mail;
    +import org.apache.james.core.MailAddress;
    +import org.apache.mailet.base.GenericMatcher;
    +
    +/**
    + * <p>This Matcher determines if the exception specified in the condition or
    + * the subclasses of it has occured during the processing of the mail.
    + * If true, all recipients are returned, else null.
    + * This matcher presupposes that the exception occured has set at the attribute
    + * {@value org.apache.mailet.Mail#MAILET_ERROR_ATTRIBUTE_NAME} in the process.
    + * </p>
    + * 
    + * <p>Sample configuration:</p>
    + * <pre><code>
    + * &lt;mailet match="HasException=org.apache.james.managesieve.api.ManageSieveException"
class=&quot;&lt;any-class&gt;&quot;&gt;
    + * </code></pre>
    + *
    + * @version CVS $Revision$ $Date$
    + * @since 3.0.2
    + **/
    +public class HasException extends GenericMatcher
    +{
    +
    +    /**
    +     * The name of the exception class to match
    +     */    
    +    private String exceptionClassName;
    +    
    +    /**
    +     * The class of the specified exception class to match
    +     */
    +    private Class<? extends Throwable> exceptionClass;
    +
    +    /**
    +     * <p>Answers the recipients of the mail if the specified exception or
    +     * the subclasses of it has occured.</p>
    +     * 
    +     * @param mail
    +     */
    +    public Collection<MailAddress> match(Mail mail) throws MessagingException
    +    {
    +        Object exceptionValue = mail.getAttribute(Mail.MAILET_ERROR_ATTRIBUTE_NAME);
    +
    +        if (exceptionValue != null && exceptionClass.isAssignableFrom(exceptionValue.getClass()))
{
    +            return mail.getRecipients();
    +        } else {
    +            return null;
    +        }
    +    }
    +
    +    /**
    +     * Returns the exceptionClassName.
    +     * @return String
    +     */
    +    protected String getExceptionClassName()
    +    {
    +        return exceptionClassName;
    +    }
    +
    +    /**
    +     * Sets the exceptionClassName.
    +     * @param exceptionClassName The exceptionClassName to set
    +     */
    +    protected void setExceptionClassName(String exceptionClassName)
    +    {
    +    	this.exceptionClassName = exceptionClassName;
    +    }
    +
    +    /*
    +     * (non-Javadoc)
    +     * @see org.apache.mailet.base.GenericMatcher#init()
    --- End diff --
    
    This comment seems not really usefull...


> Allow per Exception error handling in the mailet pipeline
> ---------------------------------------------------------
>
>                 Key: JAMES-2275
>                 URL: https://issues.apache.org/jira/browse/JAMES-2275
>             Project: James Server
>          Issue Type: New Feature
>          Components: Mailet Contributions
>    Affects Versions: master
>            Reporter: Tellier Benoit
>              Labels: easy-fix, feature, newbie
>
> In JAMES-2271 from [~apptaro], the error handling system of the mailet pipeline can now
be customized using the *onMailetException* property. This allows specifying the processor
for error handling or ignore the error (by default error processor is triggered).
> While empowering the user to write custom error handling logic, the error handling code
capabilities is limited as the original exception is lost along the way.
> We should:
>  - Pass the Exception along with the Mail, as an attribute. 
> Thus mailet in the error processor can access and read it. Throwable being serializable,
this makes this change easy to perform.
>  - Implement specific error handling matchers:
>    - *HasException* would allow to see if a Mail has a specific exception
> {code:xml}
> <mailet match="HasException=org.apache.james.managesieve.api.ManageSieveException"
class="...>
>     ....
> </mailet>
> {code}
> ### How to implement this
> 1. Add a ERROR_ATTRIBUTE_NAME contant in the Mail interface
> 2. ProcessorUtil:: handleException should add the ERROR_ATTRIBUTE_NAME attriute using
the provided exception
> 3. Modify *AbstractStateMailetProcessorTest* to demonstrate that when a mailet or a matcher
throws, the Exception is attahed to the incoming mail.
> 4. In the mailet/standard project, you will implement the HasException matcher. You can
extend GenericMatcher and implement unit tests for your class.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
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