List of usage examples for javax.jms Message setJMSDestination
void setJMSDestination(Destination destination) throws JMSException;
From source file:hermes.store.jdbc.MessageResultSetHandler.java
public Message getNextMessage() throws JMSException, SQLException, NamingException { if (cachedMessages.size() > 0) { return cachedMessages.remove(0); } else {/* w w w . j a v a2s .c om*/ if (resultSet.next()) { final Collection<Message> c = xmlHelper.fromXML(messageFactory, resultSet.getClob(3).getAsciiStream()); for (Message m : c) { if (headerPolicy != MessageStore.HeaderPolicy.NO_HEADER) { Destination d = messageFactory.getDestination(resultSet.getString(1), Domain.getDomain(resultSet.getInt(2))); if (headerPolicy == MessageStore.HeaderPolicy.DESTINATION_ONLY) { m.setJMSDestination(d); } else if (headerPolicy == MessageStore.HeaderPolicy.MESSAGEID_ONLY) { m.setJMSMessageID(resultSet.getString(4)); } else if (headerPolicy == MessageStore.HeaderPolicy.MESSAGEID_AND_DESTINATION) { m.setJMSDestination(d); m.setJMSMessageID(resultSet.getString(4)); } } cachedMessages.add(m); } if (cachedMessages.size() > 0) { return cachedMessages.remove(0); } else { return null; } } else { resultSetEmpty = true; close(); return null; } } }
From source file:com.amazon.sqs.javamessaging.SQSMessageProducer.java
void sendInternal(Queue queue, Message message) throws JMSException { checkClosed();//w w w . ja va2 s.c om String sqsMessageBody = null; String messageType = null; if (message instanceof SQSMessage) { message.setJMSDestination(queue); if (message instanceof SQSBytesMessage) { sqsMessageBody = Base64.encodeAsString(((SQSBytesMessage) message).getBodyAsBytes()); messageType = SQSMessage.BYTE_MESSAGE_TYPE; } else if (message instanceof SQSObjectMessage) { sqsMessageBody = ((SQSObjectMessage) message).getMessageBody(); messageType = SQSMessage.OBJECT_MESSAGE_TYPE; } else if (message instanceof SQSTextMessage) { sqsMessageBody = ((SQSTextMessage) message).getText(); messageType = SQSMessage.TEXT_MESSAGE_TYPE; } } else { throw new MessageFormatException( "Unrecognized message type. Messages have to be one of: SQSBytesMessage, SQSObjectMessage, or SQSTextMessage"); } if (sqsMessageBody == null || sqsMessageBody.isEmpty()) { throw new JMSException("Message body cannot be null or empty"); } Map<String, MessageAttributeValue> messageAttributes = propertyToMessageAttribute((SQSMessage) message); addMessageTypeReservedAttribute(messageAttributes, (SQSMessage) message, messageType); SendMessageRequest sendMessageRequest = new SendMessageRequest(((SQSQueueDestination) queue).getQueueUrl(), sqsMessageBody); sendMessageRequest.setMessageAttributes(messageAttributes); String messageId = amazonSQSClient.sendMessage(sendMessageRequest).getMessageId(); LOG.info("Message sent to SQS with SQS-assigned messageId: " + messageId); /** TODO: Do not support disableMessageID for now.*/ message.setJMSMessageID(String.format(SQSMessagingClientConstants.MESSAGE_ID_FORMAT, messageId)); ((SQSMessage) message).setSQSMessageId(messageId); }
From source file:hermes.impl.DefaultXMLHelper.java
public Message createMessage(MessageFactory hermes, XMLMessage message) throws JMSException, IOException, ClassNotFoundException, DecoderException { try {// ww w. j a v a 2s . c om Message rval = hermes.createMessage(); if (message instanceof XMLTextMessage) { rval = hermes.createTextMessage(); XMLTextMessage textMessage = (XMLTextMessage) message; TextMessage textRval = (TextMessage) rval; if (BASE64_CODEC.equals(textMessage.getCodec())) { byte[] bytes = base64EncoderTL.get().decode(textMessage.getText().getBytes()); textRval.setText(new String(bytes, "ASCII")); } else { textRval.setText(textMessage.getText()); } } else if (message instanceof XMLMapMessage) { rval = hermes.createMapMessage(); XMLMapMessage mapMessage = (XMLMapMessage) message; MapMessage mapRval = (MapMessage) rval; for (Iterator iter = mapMessage.getBodyProperty().iterator(); iter.hasNext();) { final Property property = (Property) iter.next(); if (property.getValue() == null) { mapRval.setObject(property.getName(), null); } else if (property.getType().equals(String.class.getName())) { mapRval.setString(property.getName(), property.getValue()); } else if (property.getType().equals(Long.class.getName())) { mapRval.setLong(property.getName(), Long.parseLong(property.getValue())); } else if (property.getType().equals(Double.class.getName())) { mapRval.setDouble(property.getName(), Double.parseDouble(property.getValue())); } else if (property.getType().equals(Boolean.class.getName())) { mapRval.setBoolean(property.getName(), Boolean.getBoolean(property.getValue())); } else if (property.getType().equals(Character.class.getName())) { mapRval.setChar(property.getName(), property.getValue().charAt(0)); } else if (property.getType().equals(Short.class.getName())) { mapRval.setShort(property.getName(), Short.parseShort(property.getValue())); } else if (property.getType().equals(Integer.class.getName())) { mapRval.setInt(property.getName(), Integer.parseInt(property.getValue())); } } } else if (message instanceof XMLBytesMessage) { rval = hermes.createBytesMessage(); XMLBytesMessage bytesMessage = (XMLBytesMessage) message; BytesMessage bytesRval = (BytesMessage) rval; bytesRval.writeBytes(base64EncoderTL.get().decode(bytesMessage.getBytes().getBytes())); } else if (message instanceof XMLObjectMessage) { rval = hermes.createObjectMessage(); XMLObjectMessage objectMessage = (XMLObjectMessage) message; ObjectMessage objectRval = (ObjectMessage) rval; ByteArrayInputStream bistream = new ByteArrayInputStream( base64EncoderTL.get().decode(objectMessage.getObject().getBytes())); ObjectInputStream oistream = new ObjectInputStream(bistream); objectRval.setObject((Serializable) oistream.readObject()); } // // JMS Header properties try { rval.setJMSDeliveryMode(message.getJMSDeliveryMode()); } catch (JMSException ex) { log.error("unable to set JMSDeliveryMode to " + message.getJMSDeliveryMode() + ": " + ex.getMessage()); } try { rval.setJMSMessageID(message.getJMSMessageID()); } catch (JMSException ex) { log.error("unable to set JMSMessageID: " + ex.getMessage(), ex); } try { if (message.getJMSExpiration() != null) { rval.setJMSExpiration(message.getJMSExpiration()); } } catch (JMSException ex) { log.error("unable to set JMSExpiration: " + ex.getMessage(), ex); } try { if (message.getJMSPriority() != null) { rval.setJMSPriority(message.getJMSPriority()); } } catch (JMSException ex) { log.error("unable to set JMSPriority: " + ex.getMessage(), ex); } try { if (message.getJMSTimestamp() != null) { rval.setJMSTimestamp(message.getJMSTimestamp()); } } catch (JMSException ex) { log.error("unable to set JMSTimestamp:" + ex.getMessage(), ex); } if (message.getJMSCorrelationID() != null) { rval.setJMSCorrelationID(message.getJMSCorrelationID()); } if (message.getJMSReplyTo() != null && !message.getJMSReplyTo().equals("null")) { rval.setJMSReplyTo(hermes.getDestination(message.getJMSReplyTo(), Domain.getDomain(message.getJMSReplyToDomain()))); } if (message.getJMSType() != null) { rval.setJMSType(message.getJMSType()); } if (message.getJMSDestination() != null) { if (message.isFromQueue()) { rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.QUEUE)); } else { rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.TOPIC)); } } for (Iterator iter = message.getHeaderProperty().iterator(); iter.hasNext();) { Property property = (Property) iter.next(); if (property.getValue() == null) { rval.setObjectProperty(property.getName(), null); } else if (property.getType().equals(String.class.getName())) { rval.setStringProperty(property.getName(), StringEscapeUtils.unescapeXml(property.getValue())); } else if (property.getType().equals(Long.class.getName())) { rval.setLongProperty(property.getName(), Long.parseLong(property.getValue())); } else if (property.getType().equals(Double.class.getName())) { rval.setDoubleProperty(property.getName(), Double.parseDouble(property.getValue())); } else if (property.getType().equals(Boolean.class.getName())) { rval.setBooleanProperty(property.getName(), Boolean.parseBoolean(property.getValue())); } else if (property.getType().equals(Short.class.getName())) { rval.setShortProperty(property.getName(), Short.parseShort(property.getValue())); } else if (property.getType().equals(Integer.class.getName())) { rval.setIntProperty(property.getName(), Integer.parseInt(property.getValue())); } } return rval; } catch (NamingException e) { throw new HermesException(e); } }
From source file:org.mule.transport.jms.JmsMessageUtils.java
public static Message copyJMSProperties(Message from, Message to, JmsConnector connector) throws JMSException { if (connector.supportsProperty(JmsConstants.JMS_CORRELATION_ID)) { to.setJMSCorrelationID(from.getJMSCorrelationID()); }//from w ww . ja va2s. c o m if (connector.supportsProperty(JmsConstants.JMS_DELIVERY_MODE)) { to.setJMSDeliveryMode(from.getJMSDeliveryMode()); } if (connector.supportsProperty(JmsConstants.JMS_DESTINATION)) { to.setJMSDestination(from.getJMSDestination()); } if (connector.supportsProperty(JmsConstants.JMS_EXPIRATION)) { to.setJMSExpiration(from.getJMSExpiration()); } if (connector.supportsProperty(JmsConstants.JMS_MESSAGE_ID)) { to.setJMSMessageID(from.getJMSMessageID()); } if (connector.supportsProperty(JmsConstants.JMS_PRIORITY)) { to.setJMSPriority(from.getJMSPriority()); } if (connector.supportsProperty(JmsConstants.JMS_REDELIVERED)) { to.setJMSRedelivered(from.getJMSRedelivered()); } if (connector.supportsProperty(JmsConstants.JMS_REPLY_TO)) { to.setJMSReplyTo(from.getJMSReplyTo()); } if (connector.supportsProperty(JmsConstants.JMS_TIMESTAMP)) { to.setJMSTimestamp(from.getJMSTimestamp()); } if (connector.supportsProperty(JmsConstants.JMS_TYPE)) { to.setJMSType(from.getJMSType()); } return to; }