AW: Error sending email from Camel application
Hi Charles, I'm not sure if I can help you out, but a couple of days ago I had an error with sending multiple REST requests to a remote server. I aggregated the responses values of each request in a complicated Map of Map of Maps structure that resided in the Camel header. After a couple of requests, the http handshake threw an exception. After some debugging I figured out: Camel uses the complete Camel Header to setup the http header. So the toString() result of my Map of Map of Maps went into the http request as a header, and that grew too large. What helped me out was to implement a custom headerFilterStrategy in which I managed to keep all of my custom header values out of the way. Maybe this will help you... Regards, Christian -Ursprüngliche Nachricht- Von: Charles Berger [mailto:charlesb.yesm...@googlemail.com] Gesendet: Freitag, 5. Januar 2018 13:30 An: users@camel.apache.org Betreff: Re: Error sending email from Camel application The route is taking properties from a POJO and building up a message to use to send an email. I add the from, to & subject headers in the route which are just string values. The message body is created using a Velocity template which extracts some values from the POJO. I included some tracers in the route and here is the info that is logged by Camel immediately before calling the SMTP endpoint (I've anonymised some of the data): 2018-01-05 11:42:09,265 [] org.apache.camel.processor.interceptor.Tracer INFO - ID-iusa16025-local-1515152339856-0-11 >>> (emailNotifications) log[body] --> smtp://localhost <<< Pattern:InOnly, Headers:{breadcrumbId=ID-iusa16025-local-1515152339856-0-11, Content-Type=application/json, downloadSuccessful=false, from=nore...@xxx.com, JMSCorrelationID=null, JMSCorrelationIDAsBytes=null, JMSDeliveryMode=2, JMSDestination=queue://emailQueue, JMSExpiration=0, JMSMessageID=ID:iusa16025.local-64140-1515152341226-7:1:2:1:1, JMSPriority=4, JMSRedelivered=false, JMSReplyTo=null, JMSTimestamp=1515152529152, JMSType=null, JMSXGroupID=null, JMSXUserID=null, subject=EDM Image Manager Alert, to=x...@yyy.com}, BodyType:String, Body:Hi, Image https://i.xxx.com/zzz.png for template Sample Template failed to upload to the CDN. XXX Image Manager team. The error message logged is this: 2018-01-05 11:42:09,312 [] org.apache.camel.processor.DefaultErrorHandler ERROR - Failed delivery for (MessageId: ID-iusa16025-local-1515152339856-0-13 on ExchangeId: ID-iusa16025-local-1515152339856-0-11). Exhausted after delivery attempt: 1 caught: org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value queue://emailQueue due com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.util.Vector$1 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.apache.activemq.command.ActiveMQQueue["reference"]->javax.naming.Reference["all"]) Message History --- RouteId ProcessorId Processor Elapsed (ms) [emailNotifications] [emailNotifications] [activemq://emailQueue ] [ 153] [emailNotifications] [convertBodyTo4] [convertBodyTo[com.yesmail.edmimagebridge.model.SingleImageModel] ] [ 2] [emailNotifications] [setHeader1] [setHeader[subject] ] [ 0] [emailNotifications] [setHeader2] [setHeader[to] ] [ 4] [emailNotifications] [setHeader3] [setHeader[from] ] [ 0] [emailNotifications] [to9 ] [velocity:errorEmailBody.vm ] [ 101] [emailNotifications] [log10 ] [log ] [ 0] [emailNotifications] [to10 ] [smtp://localhost ] [46] Stacktrace --- org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value queue://emailQueue due com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.util.Vector$1 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference c
Re: Error sending email from Camel application
Looks like I've managed to fix this, with some help from this post on StackOverflow: https://stackoverflow.com/questions/33397359/how-to-configure-jackson-objectmapper-for-camel-in-spring-boot What I did is to create a new ObjectMapper instance and disabled the SerializationFeature.FAIL_ON_EMPTY_BEANS feature: private static ObjectMapper getCustomObjectMapper() { ObjectMapper om = new ObjectMapper(); om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); return om; } I then added this instance to the JNDI registry using the name "json-jackson": registry.bind("json-jackson", getCustomObjectMapper()); This code is executed in the CameContextLifecycle.beforeStart method. I also had to modify the Content-Type of the request to text/plain so that the message text was included in the email body rather than as an attachment.
Re: Error sending email from Camel application
The route is taking properties from a POJO and building up a message to use to send an email. I add the from, to & subject headers in the route which are just string values. The message body is created using a Velocity template which extracts some values from the POJO. I included some tracers in the route and here is the info that is logged by Camel immediately before calling the SMTP endpoint (I've anonymised some of the data): 2018-01-05 11:42:09,265 [] org.apache.camel.processor.interceptor.Tracer INFO - ID-iusa16025-local-1515152339856-0-11 >>> (emailNotifications) log[body] --> smtp://localhost <<< Pattern:InOnly, Headers:{breadcrumbId=ID-iusa16025-local-1515152339856-0-11, Content-Type=application/json, downloadSuccessful=false, from=nore...@xxx.com, JMSCorrelationID=null, JMSCorrelationIDAsBytes=null, JMSDeliveryMode=2, JMSDestination=queue://emailQueue, JMSExpiration=0, JMSMessageID=ID:iusa16025.local-64140-1515152341226-7:1:2:1:1, JMSPriority=4, JMSRedelivered=false, JMSReplyTo=null, JMSTimestamp=1515152529152, JMSType=null, JMSXGroupID=null, JMSXUserID=null, subject=EDM Image Manager Alert, to=x...@yyy.com}, BodyType:String, Body:Hi, Image https://i.xxx.com/zzz.png for template Sample Template failed to upload to the CDN. XXX Image Manager team. The error message logged is this: 2018-01-05 11:42:09,312 [] org.apache.camel.processor.DefaultErrorHandler ERROR - Failed delivery for (MessageId: ID-iusa16025-local-1515152339856-0-13 on ExchangeId: ID-iusa16025-local-1515152339856-0-11). Exhausted after delivery attempt: 1 caught: org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value queue://emailQueue due com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.util.Vector$1 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.apache.activemq.command.ActiveMQQueue["reference"]->javax.naming.Reference["all"]) Message History --- RouteId ProcessorId Processor Elapsed (ms) [emailNotifications] [emailNotifications] [activemq://emailQueue ] [ 153] [emailNotifications] [convertBodyTo4] [convertBodyTo[com.yesmail.edmimagebridge.model.SingleImageModel] ] [ 2] [emailNotifications] [setHeader1] [setHeader[subject] ] [ 0] [emailNotifications] [setHeader2] [setHeader[to] ] [ 4] [emailNotifications] [setHeader3] [setHeader[from] ] [ 0] [emailNotifications] [to9 ] [velocity:errorEmailBody.vm ] [ 101] [emailNotifications] [log10 ] [log ] [ 0] [emailNotifications] [to10 ] [smtp://localhost ] [46] Stacktrace --- org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value queue://emailQueue due com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.util.Vector$1 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.apache.activemq.command.ActiveMQQueue["reference"]->javax.naming.Reference["all"]) The message suggests that I should disable SerializationFeature.FAIL_ON_EMPTY_BEANS but I'm not sure how to achieve that. I'm researching that just now and I was looking at doing something like this: JacksonDataFormat df = new JacksonDataFormat(java.util.Vector.class); df.disableFeature(SerializationFeature.FAIL_ON_EMPTY_BEANS); in beforeStart method of my CamelContextLifecycle class.
Re: Error sending email from Camel application
Hi >From the stacktrace it seems its some kind of header that is causing this jackson conversion as its .toString method is called. What objects do you store in the headers? Maybe use tracer, or debug your Camel application and see which header has the problem. On Thu, Jan 4, 2018 at 8:01 PM, Charles Berger wrote: > Anyone able to help with this please? > > On Thu, Dec 21, 2017 at 6:03 PM, Charles Berger > wrote: >> Hi, >> >> I have the following route in my application which sends an email >> based on a template filled out with data from the SingleImageModel >> class: >> >> from(ACTIVEMQ_EMAIL_QUEUE) >> .routeId(ROUTE_EMAIL_NOTIFICATIONS) >> .convertBodyTo(SingleImageModel.class) >> // set subject, from address & to address >> .setHeader("subject", constant(EMAIL_SUBJECT)) >> .setHeader("to", simple("${body.email}")) >> .setHeader("from", constant(EMAIL_FROM)) >> // format the message body >> .to(VELOCITY_EMAIL) >> .log("${body}") >> // send email >> .to(SMTP_URL) >> .end(); >> >> When it tries to execute the SMTP step the message fails with the >> following error: >> >> 2017-12-21 17:30:08,034 [] >> org.apache.camel.processor.DefaultErrorHandler ERROR - Failed delivery >> for (MessageId: ID-iusa16025-local-1513877322283-0-13 on ExchangeId: >> ID-iusa16025-local-1513877322283-0-11). Exhausted after delivery >> attempt: 1 caught: org.apache.camel.TypeConversionException: Error >> during type conversion from type: java.lang.String to the required >> type: java.lang.String with value queue://emailQueue due >> com.fasterxml.jackson.databind.JsonMappingException: No serializer >> found for class java.util.Vector$1 and no properties discovered to >> create BeanSerializer (to avoid exception, disable >> SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: >> org.apache.activemq.command.ActiveMQQueue["reference"]->javax.naming.Reference["all"]) >> >> The stacktrace is: >> >> org.apache.camel.TypeConversionException: Error during type conversion >> from type: java.lang.String to the required type: java.lang.String >> with value queue://emailQueue due >> com.fasterxml.jackson.databind.JsonMappingException: No serializer >> found for class java.util.Vector$1 and no properties discovered to >> create BeanSerializer (to avoid exception, disable >> SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: >> org.apache.activemq.command.ActiveMQQueue["reference"]->javax.naming.Reference["all"]) >> at >> org.apache.camel.impl.converter.BaseTypeConverterRegistry.createTypeConversionException(BaseTypeConverterRegistry.java:667) >> at >> org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:158) >> at org.apache.camel.component.mail.MailBinding.asString(MailBinding.java:717) >> at >> org.apache.camel.component.mail.MailBinding.appendHeadersFromCamelMessage(MailBinding.java:398) >> at >> org.apache.camel.component.mail.MailBinding.populateMailMessage(MailBinding.java:117) >> at org.apache.camel.component.mail.MailProducer.process(MailProducer.java:58) >> at >> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) >> at >> org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:178) >> at >> org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:445) >> at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:173) >> at >> org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:181) >> at >> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) >> at >> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) >> at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) >> at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) >> at >> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) >> at >> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) >> at >> org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:112) >> at >> org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:719) >> at >> org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:679) >> at >> org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:649) >> at >> org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:317) >> at >> org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPolli
Re: Error sending email from Camel application
Anyone able to help with this please? On Thu, Dec 21, 2017 at 6:03 PM, Charles Berger wrote: > Hi, > > I have the following route in my application which sends an email > based on a template filled out with data from the SingleImageModel > class: > > from(ACTIVEMQ_EMAIL_QUEUE) > .routeId(ROUTE_EMAIL_NOTIFICATIONS) > .convertBodyTo(SingleImageModel.class) > // set subject, from address & to address > .setHeader("subject", constant(EMAIL_SUBJECT)) > .setHeader("to", simple("${body.email}")) > .setHeader("from", constant(EMAIL_FROM)) > // format the message body > .to(VELOCITY_EMAIL) > .log("${body}") > // send email > .to(SMTP_URL) > .end(); > > When it tries to execute the SMTP step the message fails with the > following error: > > 2017-12-21 17:30:08,034 [] > org.apache.camel.processor.DefaultErrorHandler ERROR - Failed delivery > for (MessageId: ID-iusa16025-local-1513877322283-0-13 on ExchangeId: > ID-iusa16025-local-1513877322283-0-11). Exhausted after delivery > attempt: 1 caught: org.apache.camel.TypeConversionException: Error > during type conversion from type: java.lang.String to the required > type: java.lang.String with value queue://emailQueue due > com.fasterxml.jackson.databind.JsonMappingException: No serializer > found for class java.util.Vector$1 and no properties discovered to > create BeanSerializer (to avoid exception, disable > SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: > org.apache.activemq.command.ActiveMQQueue["reference"]->javax.naming.Reference["all"]) > > The stacktrace is: > > org.apache.camel.TypeConversionException: Error during type conversion > from type: java.lang.String to the required type: java.lang.String > with value queue://emailQueue due > com.fasterxml.jackson.databind.JsonMappingException: No serializer > found for class java.util.Vector$1 and no properties discovered to > create BeanSerializer (to avoid exception, disable > SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: > org.apache.activemq.command.ActiveMQQueue["reference"]->javax.naming.Reference["all"]) > at > org.apache.camel.impl.converter.BaseTypeConverterRegistry.createTypeConversionException(BaseTypeConverterRegistry.java:667) > at > org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:158) > at org.apache.camel.component.mail.MailBinding.asString(MailBinding.java:717) > at > org.apache.camel.component.mail.MailBinding.appendHeadersFromCamelMessage(MailBinding.java:398) > at > org.apache.camel.component.mail.MailBinding.populateMailMessage(MailBinding.java:117) > at org.apache.camel.component.mail.MailProducer.process(MailProducer.java:58) > at > org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) > at > org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:178) > at > org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:445) > at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:173) > at > org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:181) > at > org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) > at > org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) > at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) > at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) > at > org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) > at > org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) > at > org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:112) > at > org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:719) > at > org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:679) > at > org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:649) > at > org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:317) > at > org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:255) > at > org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1166) > at > org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1158) > at > org.springframework.jms.listener.DefaultMessageL
Error sending email from Camel application
Hi, I have the following route in my application which sends an email based on a template filled out with data from the SingleImageModel class: from(ACTIVEMQ_EMAIL_QUEUE) .routeId(ROUTE_EMAIL_NOTIFICATIONS) .convertBodyTo(SingleImageModel.class) // set subject, from address & to address .setHeader("subject", constant(EMAIL_SUBJECT)) .setHeader("to", simple("${body.email}")) .setHeader("from", constant(EMAIL_FROM)) // format the message body .to(VELOCITY_EMAIL) .log("${body}") // send email .to(SMTP_URL) .end(); When it tries to execute the SMTP step the message fails with the following error: 2017-12-21 17:30:08,034 [] org.apache.camel.processor.DefaultErrorHandler ERROR - Failed delivery for (MessageId: ID-iusa16025-local-1513877322283-0-13 on ExchangeId: ID-iusa16025-local-1513877322283-0-11). Exhausted after delivery attempt: 1 caught: org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value queue://emailQueue due com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.util.Vector$1 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.apache.activemq.command.ActiveMQQueue["reference"]->javax.naming.Reference["all"]) The stacktrace is: org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value queue://emailQueue due com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.util.Vector$1 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.apache.activemq.command.ActiveMQQueue["reference"]->javax.naming.Reference["all"]) at org.apache.camel.impl.converter.BaseTypeConverterRegistry.createTypeConversionException(BaseTypeConverterRegistry.java:667) at org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:158) at org.apache.camel.component.mail.MailBinding.asString(MailBinding.java:717) at org.apache.camel.component.mail.MailBinding.appendHeadersFromCamelMessage(MailBinding.java:398) at org.apache.camel.component.mail.MailBinding.populateMailMessage(MailBinding.java:117) at org.apache.camel.component.mail.MailProducer.process(MailProducer.java:58) at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:178) at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:445) at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:173) at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:181) at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:112) at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:719) at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:679) at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:649) at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:317) at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:255) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1166) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1158) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1055) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thr