Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-13633

AuthenticationFailedException is not propagated to onException route

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Problem
    • 2.24.0
    • None
    • camel-mail
    • None
    • Unknown

    Description

      If imaps Compotent throws:

       

      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)
      

       

      It is not propagated to onException Route.

      Test case:

      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();
        }
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            eximius Kamil
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: