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

AttachmentConverter is not automatically discovered

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Workaround
    • 3.0.0, 3.0.1, 3.1.0
    • None
    • camel-mail
    • Reproduced on Windows 7 and CentOS 6.10, with Oracle JDK 8, OpenJDK 8 and OpenJDK 11.

    • Unknown

    Description

      I have a very basic usage of camel-mail that's been working fine with Camel 2.x:

      import java.io.IOException;
      import org.apache.camel.CamelContext;
      import org.apache.camel.ProducerTemplate;
      import org.apache.camel.impl.DefaultCamelContext;
      
      public class MailTest {
          public static void main(String[] args) throws IOException {
              try (CamelContext ctx = new DefaultCamelContext(); ProducerTemplate pt = ctx.createProducerTemplate()) {
                  ctx.start();
                  pt.sendBody("smtp://localhost:25?to=me@mydomain", "Hello, World");
              }
          }
      }
      

      It is packaged as an executable jar using maven-assembly-plugin jar-with-dependencies.

      When I run it with Camel 3.x (tested with 3.0.0, 3.0.1 and 3.1.0), I get below error:

      Exception in thread "main" org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[]
              at org.apache.camel.CamelExecutionException.wrapCamelExecutionException(CamelExecutionException.java:47)
              at org.apache.camel.support.ExchangeHelper.extractResultBody(ExchangeHelper.java:636)
              at org.apache.camel.impl.engine.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:568)
              at org.apache.camel.impl.engine.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:564)
              at org.apache.camel.impl.engine.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:189)
              at org.apache.camel.impl.engine.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:195)
              at MailTest.main(MailTest.java:10)
      Caused by: java.lang.NullPointerException
              at org.apache.camel.component.mail.MailBinding.populateMailMessage(MailBinding.java:133)
              at org.apache.camel.component.mail.MailProducer.process(MailProducer.java:61)
              at org.apache.camel.support.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:67)
              at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:212)
              at org.apache.camel.processor.SharedCamelInternalProcessor$1.process(SharedCamelInternalProcessor.java:110)
              at org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.process(DefaultAsyncProcessorAwaitManager.java:84)
              at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:107)
              at org.apache.camel.impl.engine.DefaultProducerCache.send(DefaultProducerCache.java:185)
              at org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:176)
              at org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:172)
              at org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:153)
              at org.apache.camel.impl.engine.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:187)
              ... 2 more
      

      Conversion of the in message to AttachmentMessage appears to be failing.
      When I checked file META-INF/services/org/apache/camel/TypeConverterLoader in my assembled jar, it was missing the "org.apache.camel.attachment.AttachmentConverterLoader" entry.

      If I now add the following line after starting the Camel context:

      new AttachmentConverterLoader().load(ctx.getTypeConverterRegistry());
      

      then mail sending is working fine again.

      Am I doing smth wrong or is this a Camel 3.x bug?
      Possible link with CAMEL-13677?

      Attachments

        Activity

          People

            Unassigned Unassigned
            laurent149 Laurent Chabot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: