Kamil created CAMEL-13633:
-----------------------------

             Summary: AuthenticationFailedException is not propagated to 
onException route
                 Key: CAMEL-13633
                 URL: https://issues.apache.org/jira/browse/CAMEL-13633
             Project: Camel
          Issue Type: Bug
          Components: camel-mail
    Affects Versions: 2.24.0
            Reporter: Kamil


If imaps Compotent throws:

 
{code:java}
javax.mail.AuthenticationFailedException: [AUTHENTICATIONFAILED] Invalid 
credentials (Failure)
        at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:732)
        at javax.mail.Service.connect(Service.java:388)
        at 
org.apache.camel.component.mail.MailConsumer.ensureIsConnected(MailConsumer.java:521)
        at 
org.apache.camel.component.mail.MailConsumer.poll(MailConsumer.java:95)
        at 
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)
        at 
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)
        at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
{code}
 

It is not propagated to onException Route.

Test case:
{code:java}
import javax.mail.AuthenticationFailedException;

import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.http.client.utils.URIBuilder;
import org.junit.Test;

public class EmailRouteTest extends CamelTestSupport {

  private static final String STATIC_ROUTE_FROM = "direct:email";

  @EndpointInject(uri = "mock:error")
  private MockEndpoint mockErrorEndpoint;

  @Produce(uri = STATIC_ROUTE_FROM)
  private ProducerTemplate sender;

  @Override
  protected RoutesBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
      @Override
      public void configure() throws Exception {
        final String routeUri = new URIBuilder()
            .setScheme("imaps")
            .setHost("imap.gmail.com")
            .setPort(993)
            .addParameter("username", "foobar")
            .addParameter("password", "foobar")
            .addParameter("debugMode", "false")
            .addParameter("delete", "false")
            .addParameter("unseen", "true")
            .addParameter("consumer.delay", "60000")
            .toString();

        onException(Exception.class)
          .handled(true)
          .to(mockErrorEndpoint);

        from(routeUri)
          .to("stream:out");

      }
    };
  }

  @Test
  public void shouldInterceptError() throws Exception {
    mockErrorEndpoint.expectedMessageCount(1);
    mockErrorEndpoint.expectedMessagesMatches(ex -> 
ex.getProperty(Exchange.EXCEPTION_CAUGHT).getClass().equals(AuthenticationFailedException.class));
    mockErrorEndpoint.assertIsSatisfied();
  }
}
{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to