[mule-user] JMS Payload to PDF Email Attachment

6 views
Skip to first unread message

Tom Purcell

unread,
Oct 27, 2010, 1:25:04 PM10/27/10
to us...@mule.codehaus.org
Hello

A PDF file is generated by an application and sent to Mule as the payload of a JMS message. Mule must take that payload (which is now the MuleMessage payload?) and send it out as the attachment on an email. From googling I get that I must call message.addAttachment but that's where I'm stuck. That method wants a DataHandler as an argument and that wants a DataSource. My "DataSource" is the message payload. What kind of DataHandler should I use? Once I get the PDF added as an attachment do I need to specify the mime type? If so how?

I'm using Mule EE 2.2.5.

Thanks
Tom

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


David Dossot

unread,
Oct 27, 2010, 1:37:58 PM10/27/10
to us...@mule.codehaus.org
Create a javax.mail.util.ByteArrayDataSource with the PDF's bytes and "application/pdf" as it's content type. Then create a new javax.activation.DataHandler with this data source. That's it, you have an attachment :)

D.

Willem Peters

unread,
Oct 28, 2010, 6:31:36 AM10/28/10
to us...@mule.codehaus.org
Attached is a transformer to transform a message with as payload bytes from a file and a property "message" as the body for the email to a mulemessage that the email transport can simply send as email.

Just use FileToMuleMessage and then ObjectToMime in smtp:outbound-endpoint.

the mime file has to be put in to your lib dir of the java runtime. This is used by the transformer to set the mimetype for the attachment.


btw this is not working for all versions of the server because there was a bug with the outbound attachments see mule-5118

mime.types
FileToMuleMessage.java

Tom Purcell

unread,
Oct 28, 2010, 6:06:11 PM10/28/10
to us...@mule.codehaus.org
Hello

First, thank you both for your responses. I think I've made progress but I still do not have a an email with an attachment. Here's my mule-config:
{code}
<?xml version="1.0" encoding="UTF-8"?>
<mule
xmlns="http://www.mulesource.org/schema/mule/core/2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
xmlns:jms="http://www.mulesource.org/schema/mule/jms/2.2"
xmlns:smtp="http://www.mulesource.org/schema/mule/smtp/2.2"
xmlns:email="http://www.mulesource.org/schema/mule/email/2.2"
xmlns:script="http://www.mulesource.org/schema/mule/scripting/2.2"
xsi:schemaLocation="
http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
http://www.mulesource.org/schema/mule/jms/2.2 http://www.mulesource.org/schema/mule/jms/2.2/mule-jms.xsd
http://www.mulesource.org/schema/mule/smtp/2.2 http://www.mulesource.org/schema/mule/smtp/2.2/mule-smtp.xsd
http://www.mulesource.org/schema/mule/email/2.2 http://www.mulesource.org/schema/mule/email/2.2/mule-email.xsd
http://www.mulesource.org/schema/mule/scripting/2.2 http://www.mulesource.org/schema/mule/scripting/2.2/mule-scripting.xsd
">

<description>
mailAttachmentModel proto-type
</description>

<jms:activemq-connector
name="jmsConnector"
specification="1.1"
brokerURL="tcp://localhost:61616" />

<email:string-to-email-transformer name="stringToEmailTransformer"/>
<email:object-to-mime-transformer name="objectToMimeTransformer"/>

<model name="mailAttachmentModel">
<service name="mailAttachmentService">
<inbound>
<jms:inbound-endpoint queue="jms.queue.jreport.response">
<transformers>
<jms:jmsmessage-to-object-transformer/>
<script:transformer>
<script:script engine="groovy">
<script:text>
import javax.mail.util.ByteArrayDataSource
import javax.activation.DataHandler

log.info("**** message,getPayloadAsBytes(): " + message.getPayloadAsBytes())
log.info("**** message,getPayloadAsString(): " + message.getPayloadAsString())

String ssiReportFileName = message.getProperty("SsiReportFileName")
ByteArrayDataSource attachment = new ByteArrayDataSource(message.getPayloadAsBytes(), "application/pdf")
message.addAttachment(ssiReportFileName, new DataHandler(attachment))
message.setPayload(ssiReportFileName)

return message
</script:text>
</script:script>
</script:transformer>
</transformers>
</jms:inbound-endpoint>
</inbound>
<echo-component/>
<outbound>
<pass-through-router>
<smtp:outbound-endpoint
host="kermit"
port="25"
from="sup...@storeroomsolutions.com"
subject="mailAttachmentService"
to="tpur...@storeroomsolutions.com"
transformer-refs="stringToEmailTransformer objectToMimeTransformer">
</smtp:outbound-endpoint>
</pass-through-router>
</outbound>
</service>
</model>
</mule>
{code}

Here's my log:
{code}
DEBUG 2010-10-28 17:06:38,943 [ActiveMQ Session Task] org.mule.DefaultMuleSession: dispatching event to service: mailAttachmentService, event is: MuleEvent: 4184006e-e2d7-11df-8f1d-932c7b9d2629, sync=false, stop processing=false, DefaultInboundEndpoint{endpointUri=jms://jms.queue.jreport.response, connector=ActiveMQJmsConnector{this=4ff217ec, started=true, initialised=true, name='jmsConnector', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[jms], serviceOverrides=null}, transformer=[JMSMessageToObject{this=4d74f02c, name='JMSMessageToObject', ignoreBadInput=false, returnClass=class java.lang.Object, sourceTypes=[interface javax.jms.Message, interface javax.jms.TextMessage, interface javax.jms.ObjectMessage, interface javax.jms.BytesMessage, interface javax.jms.MapMessage, interface javax.jms.StreamMessage]}, ScriptTransformer{this=3844006e, name='ScriptTransformer', ignoreBadInput=false, returnClass=class java.lang.Object, sourceTypes=[]}], name='endpoint.jms.jms.queue.jreport.response', properties={}, transactionConfig=Transaction{factory=null, action=NEVER, timeout=0}, filter=null, deleteUnacceptedMessages=false, securityFilter=null, synchronous=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8}
DEBUG 2010-10-28 17:06:38,943 [ActiveMQ Session Task] org.mule.model.seda.SedaService: Service: mailAttachmentService has received asynchronous event on: jms://jms.queue.jreport.response
DEBUG 2010-10-28 17:06:38,944 [ActiveMQ Session Task] org.mule.model.seda.SedaService: Service: mailAttachmentService has received asynchronous event on: jms://jms.queue.jreport.response
DEBUG 2010-10-28 17:06:38,944 [ActiveMQ Session Task] org.mule.model.seda.SedaService: Service mailAttachmentService putting event on queue mailAttachmentService.service: MuleEvent: 4184006e-e2d7-11df-8f1d-932c7b9d2629, sync=false, stop processing=false, DefaultInboundEndpoint{endpointUri=jms://jms.queue.jreport.response, connector=ActiveMQJmsConnector{this=4ff217ec, started=true, initialised=true, name='jmsConnector', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[jms], serviceOverrides=null}, transformer=[JMSMessageToObject{this=4d74f02c, name='JMSMessageToObject', ignoreBadInput=false, returnClass=class java.lang.Object, sourceTypes=[interface javax.jms.Message, interface javax.jms.TextMessage, interface javax.jms.ObjectMessage, interface javax.jms.BytesMessage, interface javax.jms.MapMessage, interface javax.jms.StreamMessage]}, ScriptTransformer{this=3844006e, name='ScriptTransformer', ignoreBadInput=false, returnClass=class java.lang.Object, sourceTypes=[]}], name='endpoint.jms.jms.queue.jreport.response', properties={}, transactionConfig=Transaction{factory=null, action=NEVER, timeout=0}, filter=null, deleteUnacceptedMessages=false, securityFilter=null, synchronous=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8}
DEBUG 2010-10-28 17:06:38,944 [mailAttachmentService.1] org.mule.model.seda.SedaService: Service: mailAttachmentService dequeued event on: jms://jms.queue.jreport.response
DEBUG 2010-10-28 17:06:38,957 [mailAttachmentService.2] org.mule.DefaultMuleMessage: new copy of message for Thread[mailAttachmentService.2,5,main]
DEBUG 2010-10-28 17:06:38,996 [mailAttachmentService.2] org.mule.registry.MuleRegistryHelper: Comparing transformers for best match: input = class org.apache.activemq.command.ActiveMQBytesMessage output = class java.lang.String Possible transformers = [JMSMessageToObject{this=5f873eb2, name='_JMSMessageToString', ignoreBadInput=false, returnClass=class java.lang.String, sourceTypes=[interface javax.jms.Message, interface javax.jms.TextMessage, interface javax.jms.ObjectMessage, interface javax.jms.BytesMessage, interface javax.jms.MapMessage, interface javax.jms.StreamMessage]}, ObjectToString{this=40be76c7, name='_ObjectToString', ignoreBadInput=false, returnClass=class java.lang.String, sourceTypes=[class java.lang.Object, class [B, class java.io.InputStream, interface org.mule.api.transport.OutputHandler]}]
INFO 2010-10-28 17:06:39,010 [mailAttachmentService.2] org.mule.component.simple.LogComponent:
********************************************************************************
* Message received in service: mailAttachmentService. Content is: '%PDF-1.4 *
* %&#65533;&#65533;&#65533;&#65533; *
* 1 0 obj <</Type/XObject/ColorSpace/DeviceRGB/Subtype/Image/BitsPerComponent *
* 8/Width 4...[100 of 5553]' *
********************************************************************************
DEBUG 2010-10-28 17:06:39,033 [mailAttachmentService.2] org.mule.module.scripting.transformer.ScriptTransformer: Applying transformer ScriptTransformer (org.mule.module.scripting.transformer.ScriptTransformer)
DEBUG 2010-10-28 17:06:39,034 [mailAttachmentService.2] org.mule.module.scripting.transformer.ScriptTransformer: Object before transform: org.mule.transport.DefaultMessageAdapter/org.mule.transport.DefaultMessageAdapter@3b947647{id=4181dd8b-e2d7-11df-8f1d-932c7b9d2629, payload=[B, properties=Properties{invocation:{}, inbound:{SsiReportF...
INFO 2010-10-28 17:06:39,128 [mailAttachmentService.2] org.mule.module.scripting.component.Scriptable: **** message,getPayloadAsBytes(): [37, 80, 68, 70, 45, 49, 46, 52, 10, 37, -30,

<NOTE: Long list of integers followed by...>

79, 70, 10]
INFO 2010-10-28 17:06:39,142 [mailAttachmentService.2] org.mule.module.scripting.component.Scriptable: **** message,getPayloadAsString(): %PDF-1.4
%&#65533;&#65533;&#65533;&#65533;
1 0 obj <</Type/XObject/ColorSpace/DeviceRGB/Subtype/Image/BitsPerComponent 8/Width 400/Length 3818/Height 46/Filter/DCTDecode>>stream
&#65533;&#65533;&#65533;&#65533;

<NOTE: Many unprintable characters followed by...>

endstream
endobj
5 0 obj<</Parent 4 0 R/Contents 3 0 R/Type/Page/Resources<</XObject<</img0 1 0 R>>/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</F1 2 0 R>>>>/MediaBox[0 0 1152 792]>>
endobj
2 0 obj<</BaseFont/Helvetica-Bold/Type/Font/Encoding/WinAnsiEncoding/Subtype/Type1>>
endobj
4 0 obj<</Type/Pages/Count 1/Kids[5 0 R]>>
endobj
6 0 obj<</Type/Catalog/Pages 4 0 R>>
endobj
7 0 obj<</Producer(iText1.2 by lowagie.com \(based on itext-paulo-148\))/ModDate(D:20101028170638-05'00')/CreationDate(D:20101028170638-05'00')>>
endobj
xref
0 8
0000000000 65535 f
0000000015 00000 n
0000005189 00000 n
0000003986 00000 n
0000005281 00000 n
0000005009 00000 n
0000005331 00000 n
0000005375 00000 n
trailer
<</Root 6 0 R/ID [<ac77e4178bdcd5ebd6b336d9ccd1e5db><ac77e4178bdcd5ebd6b336d9ccd1e5db>]/Info 7 0 R/Size 8>>
startxref
5528
%%EOF

DEBUG 2010-10-28 17:06:39,149 [mailAttachmentService.2] org.mule.module.scripting.transformer.ScriptTransformer: Object after transform: org.mule.transport.DefaultMessageAdapter/org.mule.transport.DefaultMessageAdapter@3b947647{id=4181dd8b-e2d7-11df-8f1d-932c7b9d2629, payload=java.lang.String, properties=Properties{invocation:{}, inbou...
DEBUG 2010-10-28 17:06:39,149 [mailAttachmentService.2] org.mule.module.scripting.transformer.ScriptTransformer: The transformed object is of expected type. Type is: DefaultMuleMessage
DEBUG 2010-10-28 17:06:39,150 [mailAttachmentService.2] org.mule.transformer.TransformerTemplate: Applying transformer TransformerTemplate (org.mule.transformer.TransformerTemplate)
DEBUG 2010-10-28 17:06:39,151 [mailAttachmentService.2] org.mule.transformer.TransformerTemplate: Object before transform: org.mule.transport.DefaultMessageAdapter/org.mule.transport.DefaultMessageAdapter@3b947647{id=4181dd8b-e2d7-11df-8f1d-932c7b9d2629, payload=java.lang.String, properties=Properties{invocation:{}, inbou...
DEBUG 2010-10-28 17:06:39,151 [mailAttachmentService.2] org.mule.transformer.TransformerTemplate: Object after transform: 3892579105716979577390414669.pdf
DEBUG 2010-10-28 17:06:39,151 [mailAttachmentService.2] org.mule.transformer.TransformerTemplate: The transformed object is of expected type. Type is: String
DEBUG 2010-10-28 17:06:39,151 [mailAttachmentService.2] org.mule.routing.outbound.OutboundPassThroughRouter: No CorrelationId is set on the message, will set a new Id
DEBUG 2010-10-28 17:06:39,152 [mailAttachmentService.2] org.mule.routing.outbound.OutboundPassThroughRouter: Extracted correlation Id as: 4181dd8b-e2d7-11df-8f1d-932c7b9d2629
DEBUG 2010-10-28 17:06:39,152 [mailAttachmentService.2] org.mule.routing.outbound.OutboundPassThroughRouter: Setting Correlation info on Outbound router for endpoint: smtp://kermit:25
Id=4181dd8b-e2d7-11df-8f1d-932c7b9d2629
DEBUG 2010-10-28 17:06:39,152 [mailAttachmentService.2] org.mule.routing.outbound.OutboundPassThroughRouter: Message being sent to: smtp://kermit:25 Message payload:
3892579105716979577390414669.pdf
outbound transformer is: [StringToEmailMessage{this=62029d75, name='stringToEmailTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]}, ObjectToMimeMessage{this=19af9e98, name='objectToMimeTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]}]
DEBUG 2010-10-28 17:06:39,153 [mailAttachmentService.2] org.mule.DefaultMuleSession: MuleSession has received asynchronous event on: DefaultOutboundEndpoint{endpointUri=smtp://kermit:25, connector=SmtpConnector{this=79a93f38, started=true, initialised=true, name='connector.smtp.0', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[smtp], serviceOverrides=null}, transformer=[StringToEmailMessage{this=62029d75, name='stringToEmailTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]}, ObjectToMimeMessage{this=19af9e98, name='objectToMimeTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]}], name='endpoint.smtp.kermit.25', properties={toAddresses=tpur...@storeroomsolutions.com, subject=mailAttachmentService, fromAddress=sup...@storeroomsolutions.com}, transactionConfig=Transaction{factory=null, action=NEVER, timeout=0}, filter=null, deleteUnacceptedMessages=false, securityFilter=null, synchronous=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8}
DEBUG 2010-10-28 17:06:39,153 [mailAttachmentService.2] org.mule.DefaultMuleSession: Creating event with data: java.lang.String, for endpoint: DefaultOutboundEndpoint{endpointUri=smtp://kermit:25, connector=SmtpConnector{this=79a93f38, started=true, initialised=true, name='connector.smtp.0', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[smtp], serviceOverrides=null}, transformer=[StringToEmailMessage{this=62029d75, name='stringToEmailTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]}, ObjectToMimeMessage{this=19af9e98, name='objectToMimeTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]}], name='endpoint.smtp.kermit.25', properties={toAddresses=tpur...@storeroomsolutions.com, subject=mailAttachmentService, fromAddress=sup...@storeroomsolutions.com}, transactionConfig=Transaction{factory=null, action=NEVER, timeout=0}, filter=null, deleteUnacceptedMessages=false, securityFilter=null, synchronous=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8}
DEBUG 2010-10-28 17:06:39,153 [mailAttachmentService.2] org.mule.DefaultMuleSession: dispatching event: MuleEvent: 41a432a1-e2d7-11df-8f1d-932c7b9d2629, sync=false, stop processing=false, DefaultOutboundEndpoint{endpointUri=smtp://kermit:25, connector=SmtpConnector{this=79a93f38, started=true, initialised=true, name='connector.smtp.0', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[smtp], serviceOverrides=null}, transformer=[StringToEmailMessage{this=62029d75, name='stringToEmailTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]}, ObjectToMimeMessage{this=19af9e98, name='objectToMimeTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]}], name='endpoint.smtp.kermit.25', properties={toAddresses=tpur...@storeroomsolutions.com, subject=mailAttachmentService, fromAddress=sup...@storeroomsolutions.com}, transactionConfig=Transaction{factory=null, action=NEVER, timeout=0}, filter=null, deleteUnacceptedMessages=false, securityFilter=null, synchronous=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8}
DEBUG 2010-10-28 17:06:39,163 [mailAttachmentService.2] org.mule.MuleSessionHandler: Adding serialized and base64-encoded Session header to message: rO0ABXNyABtvcmcubXVsZS5EZWZhdWx0TXVsZVNlc3Npb24u63bRFuxhigMABFoABXZhbGlkTAACaWR0ABJMamF2YS9sYW5nL1N0cmluZztMAApwcm9wZXJ0aWVzdAAPTGphdmEvdXRpbC9NYXA7TAAPc2VjdXJpdHlDb250ZXh0dAAnTG9yZy9tdWxlL2FwaS9zZWN1cml0eS9TZWN1cml0eUNvbnRleHQ7eHABdAAkNDE4M2IyNGQtZTJkNy0xMWRmLThmMWQtOTMyYzdiOWQyNjI5c3IAEWphdmEudXRpbC5IYXNoTWFwBQfawcMWYNEDAAJGAApsb2FkRmFjdG9ySQAJdGhyZXNob2xkeHA/QAAAAAAADHcIAAAAEAAAAAB4cHQAFW1haWxBdHRhY2htZW50U2VydmljZXg=
INFO 2010-10-28 17:06:39,279 [AgentServlet-JmDNS-CreateServices] /mmc-support: AgentServlet: Broadcasting MMC Agent on 10.0.1.75:7777
DEBUG 2010-10-28 17:06:39,291 [connector.smtp.0.dispatcher.1] org.mule.DefaultMuleMessage: new copy of message for Thread[connector.smtp.0.dispatcher.1,5,main]
INFO 2010-10-28 17:06:39,461 [connector.smtp.0.dispatcher.1] org.mule.transport.email.SmtpMessageDispatcher: Connected: endpoint.outbound.smtp://kermit:25
DEBUG 2010-10-28 17:06:39,462 [connector.smtp.0.dispatcher.1] org.mule.retry.notifiers.ConnectNotifier: Successfully connected to endpoint.outbound.smtp://kermit:25
DEBUG 2010-10-28 17:06:39,481 [connector.smtp.0.dispatcher.1] org.mule.DefaultMuleMessage: Transformer ObjectToMimeMessage{this=19af9e98, name='objectToMimeTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]} doesn't support the source payload: class javax.mail.internet.MimeMessage
DEBUG 2010-10-28 17:06:39,482 [connector.smtp.0.dispatcher.1] org.mule.DefaultMuleMessage: Exiting from transformer chain (ignoreBadInput = false)
{code}

Any thoughts would be appreciated.

David Dossot

unread,
Oct 28, 2010, 6:18:51 PM10/28/10
to us...@mule.codehaus.org
You don't need both stringToEmailTransformer and objectToMimeTransformer, you just need objectToMimeTransformer.

Actually, you're probably hit by: http://www.mulesoft.org/jira/browse/MULE-4601

You can either use the fixed ObjectToMimeTransformer from SVN and patch your Mule, or subclass the existing one, fix it and use it as a custom transformer:

public class FixedObjectToMimeMessage extends ObjectToMimeMessage {
   @Override
    protected BodyPart getBodyPartForAttachment(final DataHandler handler, final String name) throws MessagingException {
        final BodyPart part = new MimeBodyPart();
        part.setDataHandler(handler);
        part.setDescription(name);

        final DataSource source = handler.getDataSource();
        part.setFileName(StringUtils.defaultString(StringUtils.defaultString(source.getName(), handler.getName()), name));
        return part;
    }
}

HTH
D.

Tom Purcell

unread,
Oct 28, 2010, 6:42:14 PM10/28/10
to us...@mule.codehaus.org
David

I'll give that a try but the jira ticket ([MULE-4601|http://www.mulesoft.org/jira/browse/MULE-4601]) says it was fixed in 2.2.2(EE only). I'm running 2.2.5 EE. Shouldn't I have the fix?

David Dossot

unread,
Oct 28, 2010, 9:43:14 PM10/28/10
to us...@mule.codehaus.org
I'm doing the exact same thing as you do (generating emails with PDF attached, using Groovy to create the attachment) but with 2.1.1CE, which is why I needed the patch.

But in your case, you have the fix in place as you're using 2.2.5EE, thus your issue is due to some other cause: maybe just remove the useless stringToEmailTransformer?

Cheers,
D.

Tom Purcell

unread,
Oct 29, 2010, 10:31:18 AM10/29/10
to us...@mule.codehaus.org
David

Without the stringToEmailTransformer I the mail is not delivered and I get the following exception in the log:
{code}
DEBUG 2010-10-29 09:37:54,337 [mailAttachmentService.2] org.mule.module.scripting.transformer.ScriptTransformer: Object after transform: org.mule.transport.DefaultMessageAdapter/org.mule.transport.DefaultMessageAdapter@3aa42c31{id=bb7516f9-e361-11df-aa05-cf91fe32646c, payload=java.lang.String, properties=Properties{invocation:{}, inbou...
DEBUG 2010-10-29 09:37:54,337 [mailAttachmentService.2] org.mule.module.scripting.transformer.ScriptTransformer: The transformed object is of expected type. Type is: DefaultMuleMessage
DEBUG 2010-10-29 09:37:54,339 [mailAttachmentService.2] org.mule.transformer.TransformerTemplate: Applying transformer TransformerTemplate (org.mule.transformer.TransformerTemplate)
DEBUG 2010-10-29 09:37:54,339 [mailAttachmentService.2] org.mule.transformer.TransformerTemplate: Object before transform: org.mule.transport.DefaultMessageAdapter/org.mule.transport.DefaultMessageAdapter@3aa42c31{id=bb7516f9-e361-11df-aa05-cf91fe32646c, payload=java.lang.String, properties=Properties{invocation:{}, inbou...
DEBUG 2010-10-29 09:37:54,339 [mailAttachmentService.2] org.mule.transformer.TransformerTemplate: Object after transform: 14472006313907940832176766839.pdf
DEBUG 2010-10-29 09:37:54,340 [mailAttachmentService.2] org.mule.transformer.TransformerTemplate: The transformed object is of expected type. Type is: String
DEBUG 2010-10-29 09:37:54,340 [mailAttachmentService.2] org.mule.routing.outbound.OutboundPassThroughRouter: No CorrelationId is set on the message, will set a new Id
DEBUG 2010-10-29 09:37:54,340 [mailAttachmentService.2] org.mule.routing.outbound.OutboundPassThroughRouter: Extracted correlation Id as: bb7516f9-e361-11df-aa05-cf91fe32646c
DEBUG 2010-10-29 09:37:54,341 [mailAttachmentService.2] org.mule.routing.outbound.OutboundPassThroughRouter: Setting Correlation info on Outbound router for endpoint: smtp://kermit:25
Id=bb7516f9-e361-11df-aa05-cf91fe32646c
DEBUG 2010-10-29 09:37:54,341 [mailAttachmentService.2] org.mule.routing.outbound.OutboundPassThroughRouter: Message being sent to: smtp://kermit:25 Message payload:
14472006313907940832176766839.pdf
outbound transformer is: [ObjectToMimeMessage{this=7f1fc4b8, name='objectToMimeTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]}]
DEBUG 2010-10-29 09:37:54,342 [mailAttachmentService.2] org.mule.DefaultMuleSession: MuleSession has received asynchronous event on: DefaultOutboundEndpoint{endpointUri=smtp://kermit:25, connector=SmtpConnector{this=3fcac3fa, started=true, initialised=true, name='connector.smtp.0', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[smtp], serviceOverrides=null}, transformer=[ObjectToMimeMessage{this=7f1fc4b8, name='objectToMimeTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]}], name='endpoint.smtp.kermit.25', properties={toAddresses=tpur...@storeroomsolutions.com, subject=mailAttachmentService, fromAddress=sup...@storeroomsolutions.com}, transactionConfig=Transaction{factory=null, action=NEVER, timeout=0}, filter=null, deleteUnacceptedMessages=false, securityFilter=null, synchronous=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8}
DEBUG 2010-10-29 09:37:54,342 [mailAttachmentService.2] org.mule.DefaultMuleSession: Creating event with data: java.lang.String, for endpoint: DefaultOutboundEndpoint{endpointUri=smtp://kermit:25, connector=SmtpConnector{this=3fcac3fa, started=true, initialised=true, name='connector.smtp.0', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[smtp], serviceOverrides=null}, transformer=[ObjectToMimeMessage{this=7f1fc4b8, name='objectToMimeTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]}], name='endpoint.smtp.kermit.25', properties={toAddresses=tpur...@storeroomsolutions.com, subject=mailAttachmentService, fromAddress=sup...@storeroomsolutions.com}, transactionConfig=Transaction{factory=null, action=NEVER, timeout=0}, filter=null, deleteUnacceptedMessages=false, securityFilter=null, synchronous=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8}
DEBUG 2010-10-29 09:37:54,342 [mailAttachmentService.2] org.mule.DefaultMuleSession: dispatching event: MuleEvent: bb9dd4af-e361-11df-aa05-cf91fe32646c, sync=false, stop processing=false, DefaultOutboundEndpoint{endpointUri=smtp://kermit:25, connector=SmtpConnector{this=3fcac3fa, started=true, initialised=true, name='connector.smtp.0', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[smtp], serviceOverrides=null}, transformer=[ObjectToMimeMessage{this=7f1fc4b8, name='objectToMimeTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]}], name='endpoint.smtp.kermit.25', properties={toAddresses=tpur...@storeroomsolutions.com, subject=mailAttachmentService, fromAddress=sup...@storeroomsolutions.com}, transactionConfig=Transaction{factory=null, action=NEVER, timeout=0}, filter=null, deleteUnacceptedMessages=false, securityFilter=null, synchronous=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8}
DEBUG 2010-10-29 09:37:54,352 [mailAttachmentService.2] org.mule.MuleSessionHandler: Adding serialized and base64-encoded Session header to message: rO0ABXNyABtvcmcubXVsZS5EZWZhdWx0TXVsZVNlc3Npb24u63bRFuxhigMABFoABXZhbGlkTAACaWR0ABJMamF2YS9sYW5nL1N0cmluZztMAApwcm9wZXJ0aWVzdAAPTGphdmEvdXRpbC9NYXA7TAAPc2VjdXJpdHlDb250ZXh0dAAnTG9yZy9tdWxlL2FwaS9zZWN1cml0eS9TZWN1cml0eUNvbnRleHQ7eHABdAAkYmI3NmM0YWItZTM2MS0xMWRmLWFhMDUtY2Y5MWZlMzI2NDZjc3IAEWphdmEudXRpbC5IYXNoTWFwBQfawcMWYNEDAAJGAApsb2FkRmFjdG9ySQAJdGhyZXNob2xkeHA/QAAAAAAADHcIAAAAEAAAAAB4cHQAFW1haWxBdHRhY2htZW50U2VydmljZXg=
DEBUG 2010-10-29 09:37:54,356 [connector.smtp.0.dispatcher.1] org.mule.DefaultMuleMessage: new copy of message for Thread[connector.smtp.0.dispatcher.1,5,main]
INFO 2010-10-29 09:37:54,542 [connector.smtp.0.dispatcher.1] org.mule.transport.email.SmtpMessageDispatcher: Connected: endpoint.outbound.smtp://kermit:25
DEBUG 2010-10-29 09:37:54,542 [connector.smtp.0.dispatcher.1] org.mule.retry.notifiers.ConnectNotifier: Successfully connected to endpoint.outbound.smtp://kermit:25
ERROR 2010-10-29 09:37:54,623 [connector.smtp.0.dispatcher.1] org.mule.transport.email.SmtpConnector: Work caused exception on 'workCompleted'. Work being executed was: org.mule.transport.AbstractMessageDispatcher$Worker@173dcf55
Exception in thread "connector.smtp.0.dispatcher.1" java.lang.NullPointerException
at org.mule.context.notification.ExceptionNotification.getExceptionCause(ExceptionNotification.java:52)
at org.mule.context.notification.ExceptionNotification.<init>(ExceptionNotification.java:38)
at org.mule.AbstractExceptionListener.exceptionThrown(AbstractExceptionListener.java:142)
at org.mule.transport.AbstractConnector.handleException(AbstractConnector.java:819)
at org.mule.transport.AbstractConnector.handleException(AbstractConnector.java:744)
at org.mule.transport.AbstractConnector.handleWorkException(AbstractConnector.java:1965)
at org.mule.transport.AbstractConnector.workCompleted(AbstractConnector.java:1938)
at org.mule.work.WorkerContext.run(WorkerContext.java:367)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
at java.lang.Thread.run(Thread.java:619)
{code}

Again, any thoughts...

Thanks,

David Dossot

unread,
Oct 29, 2010, 10:58:15 AM10/29/10
to us...@mule.codehaus.org
Mmmh, since you use EE you're best move at this point is to contact support and open a trouble ticket with them.

D.

Tom Purcell

unread,
Oct 29, 2010, 11:07:25 AM10/29/10
to us...@mule.codehaus.org
Hello

There appears to be a similar discussion going on in currently the Developer Forum: [Problem sending pdf as attachment using smtp outbound endpoint|http://forums.mulesoft.org/thread.jspa?messageID=11955#11955]

Tom Purcell

unread,
Nov 1, 2010, 12:49:10 PM11/1/10
to us...@mule.codehaus.org
Okay

I've done some debugging and I think I know what is going on but: 1) I'm not sure I'm right and 2) If I'm right I don't know what to do about it.

When the email:string-to-email-transformer gets invoked the message gets transformed to email format before the email:object-to-mime-transformer gets to see it so the email:object-to-mime-transformer just says:
{code}
DEBUG 2010-10-29 15:35:39,753 [connector.smtp.0.dispatcher.1] org.mule.DefaultMuleMessage: Transformer ObjectToMimeMessage{this=78a974c7, name='objectToMimeTransformer', ignoreBadInput=false, returnClass=class javax.mail.Message, sourceTypes=[class java.lang.String]} doesn't support the source payload: class javax.mail.internet.MimeMessage
{code}
The message gets sent with the payload as the message body and no attachments.

When the email:object-to-mime-transformer alone gets invoked the message gets turned into a multipart/mixed message. In SmtpMessageDispatcher.doDispatch() at the point where sendMailMessage() gets called the message is in the following state:
{code}
data MimeMessage (id=464)
content null
contentStream null
dh DataHandler (id=466)
currentCommandMap null
dataContentHandler null
dataSource null
factoryDCH null
objDataSource null
object MimeMultipart (id=470)
complete true
contentType "multipart/mixed; \r\n\tboundary="----=_Part_1_555720467.1288620887567"" (id=471)
ds null
parent null
parsed true
parts Vector<E> (id=473)
capacityIncrement 0
elementCount 2
elementData Object[10] (id=474)
[0] MimeBodyPart (id=475)
content null
contentStream null
dh DataHandler (id=477)
currentCommandMap null
dataContentHandler null
dataSource ByteArrayDataSource (id=480)
data (id=481)
name "" (id=140)
type "text/plain" (id=116)
factoryDCH null
objDataSource null
object null
objectMimeType null
oldFactory null
shortType null
transferFlavors DataFlavor[0] (id=138)
headers InternetHeaders (id=478)
parent MimeMultipart (id=470)
[1] MimeBodyPart (id=476)
content null
contentStream null
dh DataHandler (id=490)
currentCommandMap null
dataContentHandler null
dataSource ByteArrayDataSource (id=492)
data (id=493)
name "" (id=140)
type "application/pdf" (id=494)
factoryDCH null
objDataSource null
object null
objectMimeType null
oldFactory null
shortType null
transferFlavors DataFlavor[0] (id=138)
headers InternetHeaders (id=491)
parent MimeMultipart (id=470)
[2] null
[3] null
[4] null
[5] null
[6] null
[7] null
[8] null
[9] null
modCount 2
preamble null
objectMimeType "multipart/mixed; \r\n\tboundary="----=_Part_1_555720467.1288620887567"" (id=471)
oldFactory null
shortType null
transferFlavors DataFlavor[0] (id=138)
expunged false
flags Flags (id=467)
folder null
headers InternetHeaders (id=468)
modified true
msgnum 0
saved false
session Session (id=257)
strict true
{code}

The ultimate exception appears to be:
{code}
javax.mail.internet.ParseException: Expected parameter value, got "null"
{code}

I notice that the name fields on both of the MimeBodyPart's DataHandlers is a null string. Could this be the issue?

Tom Purcell

unread,
Nov 5, 2010, 10:29:21 AM11/5/10
to us...@mule.codehaus.org
Hello
I believe this is the result of a bug in ObjectToMimeMessage. See the jira ticket for details([MULE-5182|http://www.mulesoft.org/jira/browse/MULE-5182]. There is a workaround in the groovy script below:

import javax.mail.util.ByteArrayDataSource
import javax.activation.DataHandler

String fileName = message.getProperty("originalFilename")

ByteArrayDataSource attachment = new ByteArrayDataSource(message.getPayloadAsBytes(), "application/pdf")

attachment.setName(fileName)

message.addAttachment(fileName, new DataHandler(attachment))
message.setPayload("The original filename is: " + fileName)

return message

The key is the statement "attachment.setName(fileName)" This avoids the problem because it explicitly sets the name on the DataSource. As a result the existing code will work because DataHandler.getName() will no longer return an empty string.

Michael Weber

unread,
Feb 16, 2011, 6:32:30 PM2/16/11
to us...@mule.codehaus.org
Hi,

I know that this thread is old, but maybe my solution is useful. I'm using mule 3.1. My solution consists of an AbstractMessageTransformer for setting the outboundAttachement and the object-to-mime-Transformer that attaches really the outboundAttachement to the email as mimePart. I defined the following outbound for sending an email with a pdf document as attachement:

<custom-transformer name="orderAttachementTransformer"
class="com.demo.esb.OrderAttachementTransformer">
<spring:property name="templateURL" value="test.pdf" />
</custom-transformer>
......
<smtp:outbound-endpoint host="${smtp.host}"
user="${smtp.user}" password="${smtp.password}" port="${smtp.port}"
from="${smtp.from}" subject="My Message">
<transformer ref="orderAttachementTransformer"/>
<email:object-to-mime-transformer mimeType="*/*" useOutboundAttachments="true"/>
<email:string-to-email-transformer />
</smtp:outbound-endpoint>

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

My orderAttachementTransformer looks like this:

public class OrderAttachementTransformer extends AbstractMessageTransformer{

private String templateURL;

@Override
public Object transformMessage(MuleMessage message, String outputEncoding)
throws TransformerException {
File f = FileUtils.newFile(templateURL);
InputStream s = null;
try {
s = new FileInputStream(f);
ByteArrayDataSource document = new ByteArrayDataSource(s, "application/pdf");
// TODO: Generate the pdf content here
document.setName("bestellung.pdf");
DataHandler attachement = new DataHandler(document);
message.addOutboundAttachment(outputEncoding, attachement);
} catch (Exception e) {
e.printStackTrace();
}
return message;
}

public String getTemplateURL() {
return templateURL;
}

public void setTemplateURL(final String templateURL) {
this.templateURL = templateURL;
}
}

Hope, it helps ;-).

Regards,
Michael

Reply all
Reply to author
Forward
0 new messages