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

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

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

    https://github.com/apache/james-project/pull/96#discussion_r160385729
  
    --- Diff: 
mailet/standard/src/test/java/org/apache/james/transport/matchers/HasExceptionTest.java
 ---
    @@ -36,93 +36,126 @@
     public class HasExceptionTest {
     
         private FakeMail mockedMail;
    -    private Matcher matcher;
    +    private Matcher testee;
     
         @Before
         public void setUp() throws Exception {
             MimeMessage mimeMessage = MailUtil.createMimeMessage();
             mockedMail = MailUtil.createMockMail2Recipients(mimeMessage);
    -        matcher = new HasException();
    +        testee = new HasException();
         }
     
         @Test
         public void 
matchShouldReturnAddressesWhenSpecifiedExceptionHasOccurred() throws 
MessagingException {
             mockedMail.setAttribute(Mail.MAILET_ERROR_ATTRIBUTE_NAME, new 
javax.mail.internet.AddressException());
     
    -        FakeMatcherConfig matcherConfig = 
FakeMatcherConfig.builder().matcherName("HasException")
    -                .condition("javax.mail.internet.AddressException").build();
    +        FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder()
    +                .matcherName("HasException")
    +                .condition("javax.mail.internet.AddressException")
    +                .build();
     
    -        matcher.init(matcherConfig);
    +        testee.init(matcherConfig);
     
    -        
assertThat(matcher.match(mockedMail)).containsExactlyElementsOf(mockedMail.getRecipients());
    +        
assertThat(testee.match(mockedMail)).containsExactlyElementsOf(mockedMail.getRecipients());
         }
     
         @Test
         public void 
matchShouldReturnAddressesWhenSubclassOfSpecifiedExceptionHasOccurred() throws 
MessagingException {
             mockedMail.setAttribute(Mail.MAILET_ERROR_ATTRIBUTE_NAME, new 
javax.mail.internet.AddressException());
     
    -        FakeMatcherConfig matcherConfig = 
FakeMatcherConfig.builder().matcherName("HasException")
    -                .condition("javax.mail.MessagingException").build();
    +        FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder()
    +                .matcherName("HasException")
    +                .condition("javax.mail.MessagingException")
    +                .build();
     
    -        matcher.init(matcherConfig);
    +        testee.init(matcherConfig);
     
    -        
assertThat(matcher.match(mockedMail)).containsExactlyElementsOf(mockedMail.getRecipients());
    +        
assertThat(testee.match(mockedMail)).containsExactlyElementsOf(mockedMail.getRecipients());
         }
     
         @Test
         public void matchShouldReturnEmptyWhenOtherExceptionHasOccurred() 
throws MessagingException {
             mockedMail.setAttribute(Mail.MAILET_ERROR_ATTRIBUTE_NAME, new 
java.lang.RuntimeException());
     
    -        
matcher.init(FakeMatcherConfig.builder().matcherName("HasException").condition("javax.mail.MessagingException")
    +        testee.init(FakeMatcherConfig.builder()
    +                .matcherName("HasException")
    +                .condition("javax.mail.MessagingException")
                     .build());
     
    -        assertThat(matcher.match(mockedMail)).isEmpty();
    +        assertThat(testee.match(mockedMail)).isEmpty();
         }
     
         @Test
         public void 
matchShouldReturnEmptyWhenSuperclassOfSpecifiedExceptionHasOccurred() throws 
MessagingException {
             mockedMail.setAttribute(Mail.MAILET_ERROR_ATTRIBUTE_NAME, new 
javax.mail.MessagingException());
     
    -        FakeMatcherConfig matcherConfig = 
FakeMatcherConfig.builder().matcherName("HasException")
    -                .condition("javax.mail.internet.AddressException").build();
    +        FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder()
    +                .matcherName("HasException")
    +                .condition("javax.mail.internet.AddressException")
    +                .build();
     
    -        matcher.init(matcherConfig);
    +        testee.init(matcherConfig);
     
    -        assertThat(matcher.match(mockedMail)).isEmpty();
    +        assertThat(testee.match(mockedMail)).isEmpty();
         }
     
         @Test
         public void matchShouldReturnEmptyWhenNoExceptionHasOccurred() throws 
MessagingException {
    -        
matcher.init(FakeMatcherConfig.builder().matcherName("HasException").condition("java.lang.Exception").build());
    +        FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder()
    +                .matcherName("HasException")
    +                .condition("java.lang.Exception")
    +                .build();
     
    -        assertThat(matcher.match(mockedMail)).isEmpty();
    +        testee.init(matcherConfig);
    +
    +        assertThat(testee.match(mockedMail)).isEmpty();
         }
     
         @Test
         public void matchShouldReturnEmptyWhenNonExceptionIsAttached() throws 
MessagingException {
             mockedMail.setAttribute(Mail.MAILET_ERROR_ATTRIBUTE_NAME, new 
java.lang.String());
     
    -        FakeMatcherConfig matcherConfig = 
FakeMatcherConfig.builder().matcherName("HasException")
    -                .condition("java.lang.Exception").build();
    +        FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder()
    +                .matcherName("HasException")
    +                .condition("java.lang.Exception")
    +                .build();
     
    -        matcher.init(matcherConfig);
    +        testee.init(matcherConfig);
     
    -        assertThat(matcher.match(mockedMail)).isEmpty();
    +        assertThat(testee.match(mockedMail)).isEmpty();
         }
     
         @Test
         public void initShouldRaiseMessagingExceptionWhenInvalidClassName() 
throws MessagingException {
    -        FakeMatcherConfig matcherConfig = 
FakeMatcherConfig.builder().matcherName("HasException")
    -                .condition("java.lang.InvalidClassName").build();
    +        FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder()
    +                .matcherName("HasException")
    +                .condition("java.lang.InvalidClassName")
    +                .build();
     
    -        assertThatThrownBy(() -> 
matcher.init(matcherConfig)).isInstanceOf(MessagingException.class);
    +        assertThatThrownBy(() -> 
testee.init(matcherConfig)).isInstanceOf(MessagingException.class);
         }
     
         @Test
         public void 
initShouldRaiseMessagingExceptionWhenClassNameIsNotException() throws 
MessagingException {
    -        FakeMatcherConfig matcherConfig = 
FakeMatcherConfig.builder().matcherName("HasException")
    -                .condition("java.lang.String").build();
    +        FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder()
    +                .matcherName("HasException")
    +                .condition("java.lang.String")
    +                .build();
    +
    +        assertThatThrownBy(() -> 
testee.init(matcherConfig)).isInstanceOf(MessagingException.class);
    +    }
    +    
    +    @Test
    +    public void 
initShouldRaiseMessagingExceptionWhenClassNameIsNotFullyQualified() throws 
MessagingException {
    --- End diff --
    
    It seems that this method title is wrong.
    What I understand from the test is that a short class name is well 
recognized, then the _match_ method of the mailer is working.
    I propose that you change this method name to 
_matchShouldReturnAddressesWhenExceptionHasOccurredAndMatchesShortClassName_
    
    BTW thank you for taking care of my comments.


> 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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to