This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 16456a2bb6712944b8f44685586bda8d577f1df9 Author: Benoit Tellier <[email protected]> AuthorDate: Fri May 29 12:21:34 2020 +0700 JAMES-3197 Matcher processing should handle NoClassDefFoundError --- .../org/apache/james/mailets/MailetErrorsTest.java | 20 +++++++++++- .../mailets/NoClassDefFoundErrorMatcher.java | 36 ++++++++++++++++++++++ .../impl/camel/MatcherSplitter.java | 4 +-- .../impl/jmx/JMXStateMailetProcessorListener.java | 2 +- .../lib/AbstractStateMailetProcessor.java | 2 +- .../lib/AbstractStateMailetProcessorTest.java | 10 +++--- 6 files changed, 64 insertions(+), 10 deletions(-) diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java index 175b4c4..b1cc490 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java @@ -105,7 +105,25 @@ public class MailetErrorsTest { awaitAtMostOneMinute.until(() -> probe.getRepositoryMailCount(ERROR_REPOSITORY) == 1); } - + + @Test + public void matcherProcessingShouldHandleClassNotFoundException() throws Exception { + jamesServer = TemporaryJamesServer.builder() + .withBase(SMTP_ONLY_MODULE) + .withMailetContainer(MailetContainer.builder() + .putProcessor(CommonProcessors.deliverOnlyTransport()) + .putProcessor(errorProcessor()) + .putProcessor(ProcessorConfiguration.root() + .addMailet(MailetConfiguration.builder() + .matcher(NoClassDefFoundErrorMatcher.class) + .mailet(Null.class)))) + .build(temporaryFolder.newFolder()); + MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class); + + smtpMessageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort()).sendMessage(FROM, FROM); + + awaitAtMostOneMinute.until(() -> probe.getRepositoryMailCount(ERROR_REPOSITORY) == 1); + } @Test public void mailetProcessorsShouldHandleRuntimeException() throws Exception { diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/NoClassDefFoundErrorMatcher.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/NoClassDefFoundErrorMatcher.java new file mode 100644 index 0000000..c03d8ca --- /dev/null +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/NoClassDefFoundErrorMatcher.java @@ -0,0 +1,36 @@ +/**************************************************************** + * 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.mailets; + +import java.util.Collection; + +import javax.mail.MessagingException; + +import org.apache.james.core.MailAddress; +import org.apache.mailet.Mail; +import org.apache.mailet.base.GenericMailet; +import org.apache.mailet.base.GenericMatcher; + +public class NoClassDefFoundErrorMatcher extends GenericMatcher { + @Override + public Collection<MailAddress> match(Mail mail) throws MessagingException { + throw new NoClassDefFoundError(); + } +} diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java index 89c8b61..1fb6116 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java @@ -90,7 +90,7 @@ public class MatcherSplitter { Collection<MailAddress> matchedRcpts = null; Collection<MailAddress> origRcpts = new ArrayList<>(mail.getRecipients()); long start = System.currentTimeMillis(); - Exception ex = null; + Throwable ex = null; TimeMetric timeMetric = metricFactory.timer(matcher.getClass().getSimpleName()); try { @@ -121,7 +121,7 @@ public class MatcherSplitter { ProcessorUtil.verifyMailAddresses(matchedRcpts); } - } catch (Exception me) { + } catch (Exception | NoClassDefFoundError me) { ex = me; if (onMatchException.equalsIgnoreCase("nomatch")) { // In case the matcher returned null, create an empty diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/jmx/JMXStateMailetProcessorListener.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/jmx/JMXStateMailetProcessorListener.java index 7840c4d..bc4bdbc 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/jmx/JMXStateMailetProcessorListener.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/jmx/JMXStateMailetProcessorListener.java @@ -69,7 +69,7 @@ public class JMXStateMailetProcessorListener implements MailetProcessorListener, } @Override - public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> rcpts, Collection<MailAddress> matches, long processTime, Exception e) { + public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> rcpts, Collection<MailAddress> matches, long processTime, Throwable e) { MatcherManagement mgmt = matcherMap.get(m); if (mgmt != null) { diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java index 0d6a399..70574bc 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java @@ -414,7 +414,7 @@ public abstract class AbstractStateMailetProcessor implements MailProcessor, Con * @param e * or null if no Exception was thrown */ - void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients, Collection<MailAddress> matches, long processTime, Exception e); + void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients, Collection<MailAddress> matches, long processTime, Throwable e); } diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java index c76a019..8cea067 100644 --- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java +++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java @@ -73,7 +73,7 @@ public abstract class AbstractStateMailetProcessorTest { @Override public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients, - Collection<MailAddress> matches, long processTime, Exception e) { + Collection<MailAddress> matches, long processTime, Throwable e) { if (MockMatcher.class.equals(m.getClass())) { assertThat(mailName).isEqualTo(mail.getName()); // match one recipient @@ -118,7 +118,7 @@ public abstract class AbstractStateMailetProcessorTest { @Override public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients, - Collection<MailAddress> matches, long processTime, Exception e) { + Collection<MailAddress> matches, long processTime, Throwable e) { if (MockMatcher.class.equals(m.getClass())) { assertThat(mailName).isEqualTo(mail.getName()); // match all recipient @@ -165,7 +165,7 @@ public abstract class AbstractStateMailetProcessorTest { @Override public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients, - Collection<MailAddress> matches, long processTime, Exception e) { + Collection<MailAddress> matches, long processTime, Throwable e) { if (ExceptionThrowingMatcher.class.equals(m.getClass())) { assertThat(mailName).isEqualTo(mail.getName()); // match no recipient because of the error @@ -204,7 +204,7 @@ public abstract class AbstractStateMailetProcessorTest { @Override public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients, - Collection<MailAddress> matches, long processTime, Exception e) { + Collection<MailAddress> matches, long processTime, Throwable e) { if (ExceptionThrowingMatcher.class.equals(m.getClass())) { latch.countDown(); } @@ -237,7 +237,7 @@ public abstract class AbstractStateMailetProcessorTest { @Override public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients, - Collection<MailAddress> matches, long processTime, Exception e) { + Collection<MailAddress> matches, long processTime, Throwable e) { if (MockMatcher.class.equals(m.getClass())) { assertThat(mailName).isEqualTo(mail.getName()); // match one recipient --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
