/**
* Produce the mail to the JMS Queue
*/
protected void produceMail(Session session, Map<String, Object> props, int msgPrio, Mail mail) throws JMSException, MessagingException, IOException {
MessageProducer producer = null;
BlobMessage blobMessage = null;
boolean reuse = false;
try {
// check if we should use a blob message here
if (useBlob) {
ActiveMQSession amqSession = getAMQSession(session);
/*
* Remove this optimization as it could lead to problems when the same blob content
* is shared across different messages.
*
* I still think it would be a good idea to somehow do this but at the moment it's just
* safer to disable it.
*
* TODO: Re-Enable it again once it works!
*
* See JAMES-1240
if (wrapper instanceof MimeMessageCopyOnWriteProxy) {
wrapper = ((MimeMessageCopyOnWriteProxy) mm).getWrappedMessage();
}
if (wrapper instanceof MimeMessageWrapper) {
URL blobUrl = (URL) mail.getAttribute(JAMES_BLOB_URL);
String fromQueue = (String) mail.getAttribute(JAMES_QUEUE_NAME);
MimeMessageWrapper mwrapper = (MimeMessageWrapper) wrapper;
if (blobUrl != null && fromQueue != null && mwrapper.isModified() == false) {
// the message content was not changed so don't need to
// upload it again and can just point to the url
blobMessage = amqSession.createBlobMessage(blobUrl);
reuse = true;
}
}*/
if (blobMessage == null) {
// just use the MimeMessageInputStream which can read every
// MimeMessage implementation
blobMessage = amqSession.createBlobMessage(new MimeMessageInputStream(mail.getMessage()));
}
// store the queue name in the props
props.put(JAMES_QUEUE_NAME, queueName);
Queue queue = session.createQueue(queueName);
producer = session.createProducer(queue);
for (Map.Entry<String, Object> entry : props.entrySet()) {
blobMessage.setObjectProperty(entry.getKey(), entry.getValue());
}
producer.send(blobMessage, Message.DEFAULT_DELIVERY_MODE, msgPrio, Message.DEFAULT_TIME_TO_LIVE);