Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Sending SMTP Mail with attachment fails due to curious Class cast

Hello everybody.
I'm new to the Talend ESB and of course I've read the manuals, but now I'm stuck with a strange behaviour.
I'd like to set up a route consuming files from a SFTP server, transfering them to our server's tmp directory. After each file is transferred, I'd like to send the file as attachment within an email to our mail server. So far so good. 😉
I managed to establish the sftp connection, transfer the files and even send a plain text email with the transferred file name. But as soon as I am trying to create an attachment via an javax.activationDataHandler and passing this object to the Method addAttachment(...) of the outgoing message, the esb console throws an exception:
2011-12-12 12:55:51,580 | ERROR | _transfer/Archiv | DefaultErrorHandler | ache.camel.processor.CamelLogger 232 | 158 - org.apache.camel.camel-cor
e - 2.8.2 | Failed delivery for exchangeId: ID-Q4DE8ISY507-60685-1323690312020-2-17. Exhausted after delivery attempt: 1 caught: org.springframework.mail.MailPreparationException: Could not prepare mail; nested exception is java.lang.ClassCastException: javax.activation.DataHandler cannot be cast to javax.activation.DataHandler
org.springframework.mail.MailPreparationException: Could not prepare mail; nested exception is java.lang.ClassCastException: javax.activation.DataHandler cannot
be cast to javax.activation.DataHandler
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:367)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:344)
at org.apache.camel.component.mail.MailProducer.process(MailProducer.java:44)
...
Caused by: java.lang.ClassCastException: javax.activation.DataHandler cannot be cast to javax.activation.DataHandler
at org.apache.camel.component.mail.MailBinding.addAttachmentsToMultipart(MailBinding.java:427)
at org.apache.camel.component.mail.MailBinding.createMixedMultipartAttachments(MailBinding.java:417)
at org.apache.camel.component.mail.MailBinding.appendAttachmentsFromCamel(MailBinding.java:405)
at org.apache.camel.component.mail.MailBinding.populateMailMessage(MailBinding.java:112)
at org.apache.camel.component.mail.MailProducer$1.prepare(MailProducer.java:46)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:352)
... 41 more

The exception message is: <b>javax.activation.DataHandler cannot be cast to javax.activation.DataHandler</b>
My suggestsion is a conflict between the different "activation.jar" files?! I am stuck with this message since three days and nearly getting nuts. Neither "googling" nor reading and searching other threads and topics did it for me. I searched the Spring Docs, Camel Docs, Karaf Docs and especially the TESB docs.
Maybe it is just a simple "misconfiguration"? It would be nice getting some help from you!
I'm using a java SDK 1.6 Update 29 with the latest stable release of TESB (version 5.0.0). Our server environment consists of a six core AMD Opteron with 16 GB RAM and windows server 2008 os installed.
The attached picture displays the route and the source code of the cProcessor component that i am using to add the attachment.
Thnaks for any repsonses!
Kind regards.
Alexander
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

We found the root cause of you problem. It is a missing import-package directive for javax.activation in the META-INF of the route bundle. For more details see the corresponding issue: http://jira.talendforge.org/browse/TESB-4278. We will fix this in our next release. Unfortunately there is no real workaround for your problem at the moment (except you like to fiddle in your bundle manifest and add the missing package yourself)

View solution in original post

6 Replies
Anonymous
Not applicable
Author

Hello Alexander,
Yes, it seems there are two activation JAR files which are loaded by two Classloaders. How do you start your route, from Studio or exported and deployed to the ESB runtime?
Renat
Anonymous
Not applicable
Author

Hi Renat.
I created the route via TESB Studio 5.0.0 and exported it as OSGI Bundle / ESB ready. I copied the new .jar file manually to the deploy directory of our running TESB instance.
Maybe I should mention, that I installed the camel-mail-2.8.2.jar manually the command: "osgi:install file:///<PATH_TO_JAR_FILE>/camel-mail-2.8.2.jar"! Because otherwise the TESB was'nt able to locate the scheme smtp:// to deliver as an endpoint!
Regards
Alexander
Anonymous
Not applicable
Author

Hello Alexander,
Just got to reproduce your issue 2 seconds ago. It works from Studio, however doesn't work from Runtime. Will investigate and get back to your ASAP.
BTW you may simply type features:install camel-mail to install the camel-mail feature in Talend ESB. We deliver all of the camel build-in components, they are just not activated by default.
Renat
Anonymous
Not applicable
Author

Hi Renat.
Thanks for investigating.
Just thought, I would lose my mind while thinking about this exception! 🙂
Regards
Alexander
Anonymous
Not applicable
Author

Hello Alexander,
The problem appeared to be more complicated than it seemed. I created a JIRA for it:
http://jira.talendforge.org/browse/TESB-4278
You may watch it, it will be updated as soon as issue is solved. For now (versions 5.0.0 and 5.0.1) you could export your routes as standalone and run them this way.
BTW did you tried to use data-services for your use-cases, it should be pretty trivial to implement such use-case using data integration components.
Renat
Anonymous
Not applicable
Author

We found the root cause of you problem. It is a missing import-package directive for javax.activation in the META-INF of the route bundle. For more details see the corresponding issue: http://jira.talendforge.org/browse/TESB-4278. We will fix this in our next release. Unfortunately there is no real workaround for your problem at the moment (except you like to fiddle in your bundle manifest and add the missing package yourself)