private javax.jms.Message createJmsMessage(QueueSession queueSession, Message msg, Address[] addresses) throws JMSException, MessagingException {
		BytesMessage jms = queueSession.createBytesMessage();
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		try {
			ObjectOutputStream oos = new ObjectOutputStream(baos);
			oos.writeUTF(protocolToUse);
			oos.writeObject(addresses == null ? new Address[0] : addresses);
			msg.writeTo(oos);
		} catch (IOException e) {
			String[] messageId = msg.getHeader("Message-ID");
			throw new MessagingException("Could not send JMS message with mail content for Message-ID:" + (messageId != null && messageId.length > 0 ? messageId[0] : "NOT_SET") , e);
		}
		jms.writeBytes(baos.toByteArray());
		Integer priority = jmsPriority(msg);
        if (priority != null && priority >= 0) {
            jms.setJMSPriority(priority);
        }
		return jms;
	}
private javax . jms . Message createJmsMessage ( QueueSession queueSession , Message msg , Address [ ] addresses ) throws JMSException , MessagingException { BytesMessage jms = queueSession . createBytesMessage ( ) ; ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; try { ObjectOutputStream oos = new ObjectOutputStream ( baos ) ; oos . writeUTF ( protocolToUse ) ; oos . writeObject ( addresses == null ? new Address [ 0 ] : addresses ) ; msg . writeTo ( oos ) ; } catch ( IOException e ) { String [ ] messageId = msg . getHeader ( "Message-ID" ) ; throw new MessagingException ( "Could not send JMS message with mail content for Message-ID:" + ( messageId != null && messageId . length > 0 ? messageId [ 0 ] : "NOT_SET" ) , e ) ; } jms . writeBytes ( baos . toByteArray ( ) ) ; Integer priority = jmsPriority ( msg ) ; if ( priority != null && priority >= 0 ) { jms . setJMSPriority ( priority ) ; } return jms ; }
Create javax.jms.Message for javax.mail.Message
JMS message contains:
<ul>
<li>protocolToUse (String) - destination / final Transport</li>
<li>addresses (array javax.mail.Address) - who to send to</li>
<li>message (object javax.mail.Message) - message content</li>
</ul>