Re: Error sending email from Camel application

2018-01-05 Thread Charles Berger
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

2018-01-05 Thread Charles Berger
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

2018-01-04 Thread Charles Berger
Anyone able to help with this please?

On Thu, Dec 21, 2017 at 6:03 PM, Charles Berger
<charlesb.yesm...@googlemail.com> 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(Abs

Error sending email from Camel application

2017-12-21 Thread Charles Berger
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 

Re: Question about using Splitter

2017-12-20 Thread Charles Berger
> You should be able to convert your ImageCollection into List
> by simply doing something like:
>
> from("activemq:requestQueue")
> .convertBodyTo(ImageCollection.class)
> .setBody(simple("${body.images}"))
> .log("${body}")
> .split(body())
> .log("${body}")
> .to("bean:downloadImageQueue")
> .marshal().json(JsonLibrary.Jackson)
> .to("activemq:ftpQueue");

That has worked - thank you so much - I had spent way too long trying
to get past that step.


Re: Question about using Splitter

2017-12-20 Thread Charles Berger
Hi,

Thanks for replying.

> Instead of splitting ImageCollection as the body, I think you just need to
> split List as the body.

Are you suggesting that the ImageCollection class is actually
superfluous and I should use the List as the output
from the bean uploadRequestQueue instead?

Or is there a way in the route that I can call the method
ImageCollection.getImages() method to pass into the split?

Thanks,

Charles.


Question about using Splitter

2017-12-19 Thread Charles Berger
Hi,

I'm building my first application using Camel and have a question
about how to use a splitter.

My route receives a serialized Java class which contains a private
ArrayList of a POJO and getter and setter methods for the list.

I convert the serialized class into a its Java representation and then
apply it to a splitter.  What I want to get out of the Splitter is
each individual instance of the POJOs in the List but what I get
instead is the complete list.

Here is some code to show what I mean

public class ImageCollection {

private List images = new ArrayList();

public void setImages(List) { ... }

public List getImages() { }

}

public class SingleImageModel {

members ...

getters & setters

}

Routes:

The first route accepts a POST from a servlet, validates the incoming
payload and converts it into an instance of ImageCollection, which is
dispatched to the requestQueue, then returns a response to the client.

from("servlet:uploadUrl")
.log("Request: ${body}")
.to("bean:uploadRequestQueue")
.log("${body}")
.marshal().json(JsonLibrary.Jackson)
.wireTap("activemq:requestQueue")
.to("bean:formatResponse")
.end()


The second route is supposed to take the ImageCollection and split it
into the SingleImageModel instances


from("activemq:requestQueue")
.convertBodyTo(ImageCollection.class)
.log("${body}")
.split(bodyAs(ImageCollection.class))
.log("${body}")
.to("bean:downloadImageQueue")
.marshal().json(JsonLibrary.Jackson)
.to("activemq:ftpQueue");

I think I need to use an Aggregator to return the individual instances
of the SingleImageModel class from the list inside ImageCollection,
but I can't work out what that should do.

Instead, what is happening is that the bean registered for the
downloadImageQueue is receiving an instance of ImageCollection when it
expects an instance of SingleImageModel and the type conversion in
that bean is failing.

Any guidance much appreciated.

Thanks,

Charles.