List of usage examples for javax.jms MapMessage setBytes
void setBytes(String name, byte[] value) throws JMSException;
From source file:eu.domibus.submission.transformer.impl.JMSMessageTransformer.java
/** * Transforms {@link eu.domibus.submission.Submission} to {@link javax.jms.MapMessage} * * @param submission the message to be transformed * * @return result of the transformation as {@link javax.jms.MapMessage} *//*from www.j a va 2 s . c o m*/ @Override public MapMessage transformFromSubmission(final Submission submission, final MapMessage messageOut) { try { messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_ACTION, submission.getAction()); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_SERVICE, submission.getService()); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_CONVERSATION_ID, submission.getConversationId()); for (final Submission.Party fromParty : submission.getFromParties()) { messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_FROM_PARTY_ID, fromParty.getPartyId()); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_FROM_PARTY_TYPE, fromParty.getPartyIdType()); } for (final Submission.Party toParty : submission.getToParties()) { messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_TO_PARTY_ID, toParty.getPartyId()); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_TO_PARTY_TYPE, toParty.getPartyIdType()); } messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_FROM_ROLE, submission.getFromRole()); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_TO_ROLE, submission.getToRole()); for (final Map.Entry p : submission.getMessageProperties().entrySet()) { if (p.getKey().equals(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_ORIGINAL_SENDER)) { messageOut.setStringProperty( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_ORIGINAL_SENDER, p.getValue().toString()); } if (p.getKey().equals(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_ENDPOINT)) { messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_ENDPOINT, p.getValue().toString()); } if (p.getKey().equals(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_FINAL_RECIPIENT)) { messageOut.setStringProperty( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_FINAL_RECIPIENT, p.getValue().toString()); } } messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROTOCOL, "AS4"); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_AGREEMENT_REF, submission.getAgreementRef()); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_REF_TO_MESSAGE_ID, submission.getRefToMessageId()); int counter = 2; for (final Submission.Payload p : submission.getPayloads()) { if (p.isInBody()) { messageOut.setBytes( MessageFormat .format(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_NAME_FORMAT, 1), p.getPayloadData()); messageOut.setStringProperty( MessageFormat.format( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_MIME_TYPE_FORMAT, 1), p.getPayloadProperties().getProperty(Property.MIME_TYPE)); messageOut.setStringProperty(MessageFormat.format( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_MIME_CONTENT_ID_FORMAT, 1), p.getContentId()); if (p.getDescription() != null) { messageOut.setStringProperty(MessageFormat.format( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_DESCRIPTION_FORMAT, 1), p.getDescription()); } } else { final String payContID = String.valueOf(MessageFormat.format( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_MIME_CONTENT_ID_FORMAT, counter)); final String payDescrip = String.valueOf(MessageFormat.format( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_DESCRIPTION_FORMAT, counter)); final String propPayload = String.valueOf(MessageFormat .format(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_NAME_FORMAT, counter)); final String payMimeTypeProp = String.valueOf(MessageFormat.format( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_MIME_TYPE_FORMAT, counter)); messageOut.setBytes(propPayload, p.getPayloadData()); messageOut.setStringProperty(payMimeTypeProp, p.getPayloadProperties().getProperty(Property.MIME_TYPE)); messageOut.setStringProperty(payContID, p.getContentId()); if (p.getDescription() != null) { messageOut.setStringProperty(payDescrip, p.getDescription()); } counter++; } } messageOut.setInt(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_TOTAL_NUMBER_OF_PAYLOADS, submission.getPayloads().size()); } catch (final JMSException ex) { JMSMessageTransformer.LOG.error("Error while filling the MapMessage", ex); } return messageOut; }
From source file:org.egov.infra.notification.service.NotificationService.java
public void sendEmailWithAttachment(String email, String subject, String message, String fileType, String fileName, byte[] attachment) { if (mailEnabled && isNoneBlank(email, subject, message)) jmsTemplate.send(emailQueue, session -> { MapMessage mapMessage = session.createMapMessage(); mapMessage.setString(EMAIL, email); mapMessage.setString(MESSAGE, message); mapMessage.setString(SUBJECT, subject); mapMessage.setString(FILETYPE, fileType); mapMessage.setString(FILENAME, fileName); mapMessage.setBytes(ATTACHMENT, attachment); return mapMessage; });/* w w w . j av a2s . c o m*/ }