List of usage examples for javax.jms Message setJMSTimestamp
void setJMSTimestamp(long timestamp) throws JMSException;
From source file:com.adaptris.core.jms.activemq.BlobMessageTranslatorTest.java
public void testMoveJmsHeadersJmsMessageToAdaptrisMessage() throws Exception { MessageTypeTranslatorImp trans = new BlobMessageTranslator(); EmbeddedActiveMq activeMqBroker = new EmbeddedActiveMq(); JmsConnection conn = null;/*from w w w .ja v a 2 s .c o m*/ try { activeMqBroker.start(); conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation()); start(conn); Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); Message jmsMsg = createMessage(session); jmsMsg.setJMSCorrelationID("ABC"); jmsMsg.setJMSDeliveryMode(1); jmsMsg.setJMSPriority(4); addProperties(jmsMsg); long timestamp = System.currentTimeMillis(); jmsMsg.setJMSTimestamp(timestamp); trans.registerSession(session); trans.registerMessageFactory(new DefaultMessageFactory()); trans.setMoveJmsHeaders(true); start(trans); AdaptrisMessage msg = trans.translate(jmsMsg); assertMetadata(msg); assertEquals("ABC", msg.getMetadataValue(JmsConstants.JMS_CORRELATION_ID)); assertEquals("1", msg.getMetadataValue(JmsConstants.JMS_DELIVERY_MODE)); assertEquals("4", msg.getMetadataValue(JmsConstants.JMS_PRIORITY)); assertEquals(String.valueOf(timestamp), msg.getMetadataValue(JmsConstants.JMS_TIMESTAMP)); } finally { stop(trans); stop(conn); activeMqBroker.destroy(); } }
From source file:com.adaptris.core.jms.MessageTypeTranslatorCase.java
public void testMoveJmsHeadersJmsMessageToAdaptrisMessage() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); MessageTypeTranslatorImp trans = createTranslator(); try {//from ww w . j ava 2 s . c o m Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE); Message jmsMsg = createMessage(session); jmsMsg.setJMSCorrelationID("ABC"); jmsMsg.setJMSDeliveryMode(1); jmsMsg.setJMSPriority(4); addProperties(jmsMsg); long timestamp = System.currentTimeMillis(); jmsMsg.setJMSTimestamp(timestamp); trans.setMoveJmsHeaders(true); start(trans, session); AdaptrisMessage msg = trans.translate(jmsMsg); assertMetadata(msg); assertEquals("ABC", msg.getMetadataValue(JmsConstants.JMS_CORRELATION_ID)); assertEquals("1", msg.getMetadataValue(JmsConstants.JMS_DELIVERY_MODE)); assertEquals("4", msg.getMetadataValue(JmsConstants.JMS_PRIORITY)); assertEquals(String.valueOf(timestamp), msg.getMetadataValue(JmsConstants.JMS_TIMESTAMP)); } finally { stop(trans); broker.destroy(); } }
From source file:hermes.impl.DefaultXMLHelper.java
public Message createMessage(MessageFactory hermes, XMLMessage message) throws JMSException, IOException, ClassNotFoundException, DecoderException { try {/*from w w w . j a va 2 s . c o m*/ 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.apache.axis2.transport.jms.JMSUtils.java
/** * Set transport headers from the axis message context, into the JMS message * * @param msgContext the axis message context * @param message the JMS Message//from ww w . j a v a2s. c o m * @throws JMSException on exception */ public static void setTransportHeaders(MessageContext msgContext, Message message) throws JMSException { Map<?, ?> headerMap = (Map<?, ?>) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS); if (headerMap == null) { return; } for (Object headerName : headerMap.keySet()) { String name = (String) headerName; if (name.startsWith(JMSConstants.JMSX_PREFIX) && !(name.equals(JMSConstants.JMSX_GROUP_ID) || name.equals(JMSConstants.JMSX_GROUP_SEQ))) { continue; } if (JMSConstants.JMS_COORELATION_ID.equals(name)) { message.setJMSCorrelationID((String) headerMap.get(JMSConstants.JMS_COORELATION_ID)); } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) { Object o = headerMap.get(JMSConstants.JMS_DELIVERY_MODE); if (o instanceof Integer) { message.setJMSDeliveryMode((Integer) o); } else if (o instanceof String) { try { message.setJMSDeliveryMode(Integer.parseInt((String) o)); } catch (NumberFormatException nfe) { log.warn("Invalid delivery mode ignored : " + o, nfe); } } else { log.warn("Invalid delivery mode ignored : " + o); } } else if (JMSConstants.JMS_EXPIRATION.equals(name)) { message.setJMSExpiration(Long.parseLong((String) headerMap.get(JMSConstants.JMS_EXPIRATION))); } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) { message.setJMSMessageID((String) headerMap.get(JMSConstants.JMS_MESSAGE_ID)); } else if (JMSConstants.JMS_PRIORITY.equals(name)) { message.setJMSPriority(Integer.parseInt((String) headerMap.get(JMSConstants.JMS_PRIORITY))); } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) { message.setJMSTimestamp(Long.parseLong((String) headerMap.get(JMSConstants.JMS_TIMESTAMP))); } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) { message.setJMSType((String) headerMap.get(JMSConstants.JMS_MESSAGE_TYPE)); } else { Object value = headerMap.get(name); if (value instanceof String) { message.setStringProperty(name, (String) value); } else if (value instanceof Boolean) { message.setBooleanProperty(name, (Boolean) value); } else if (value instanceof Integer) { message.setIntProperty(name, (Integer) value); } else if (value instanceof Long) { message.setLongProperty(name, (Long) value); } else if (value instanceof Double) { message.setDoubleProperty(name, (Double) value); } else if (value instanceof Float) { message.setFloatProperty(name, (Float) value); } } } }
From source file:org.apache.synapse.transport.jms.JMSUtils.java
/** * Set transport headers from the axis message context, into the JMS message * * @param msgContext the axis message context * @param message the JMS Message//from www. ja v a2 s . c o m * @throws JMSException on exception */ public static void setTransportHeaders(MessageContext msgContext, Message message) throws JMSException { Map headerMap = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS); if (headerMap == null) { return; } Iterator iter = headerMap.keySet().iterator(); while (iter.hasNext()) { String name = (String) iter.next(); if (JMSConstants.JMS_COORELATION_ID.equals(name)) { message.setJMSCorrelationID((String) headerMap.get(JMSConstants.JMS_COORELATION_ID)); } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) { Object o = headerMap.get(JMSConstants.JMS_DELIVERY_MODE); if (o instanceof Integer) { message.setJMSDeliveryMode(((Integer) o).intValue()); } else if (o instanceof String) { try { message.setJMSDeliveryMode(Integer.parseInt((String) o)); } catch (NumberFormatException nfe) { log.warn("Invalid delivery mode ignored : " + o, nfe); } } else { log.warn("Invalid delivery mode ignored : " + o); } } else if (JMSConstants.JMS_EXPIRATION.equals(name)) { message.setJMSExpiration(Long.parseLong((String) headerMap.get(JMSConstants.JMS_EXPIRATION))); } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) { message.setJMSMessageID((String) headerMap.get(JMSConstants.JMS_MESSAGE_ID)); } else if (JMSConstants.JMS_PRIORITY.equals(name)) { message.setJMSPriority(Integer.parseInt((String) headerMap.get(JMSConstants.JMS_PRIORITY))); } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) { message.setJMSTimestamp(Long.parseLong((String) headerMap.get(JMSConstants.JMS_TIMESTAMP))); } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) { message.setJMSType((String) headerMap.get(JMSConstants.JMS_MESSAGE_TYPE)); } else { Object value = headerMap.get(name); if (value instanceof String) { message.setStringProperty(name, (String) value); } else if (value instanceof Boolean) { message.setBooleanProperty(name, ((Boolean) value).booleanValue()); } else if (value instanceof Integer) { message.setIntProperty(name, ((Integer) value).intValue()); } else if (value instanceof Long) { message.setLongProperty(name, ((Long) value).longValue()); } else if (value instanceof Double) { message.setDoubleProperty(name, ((Double) value).doubleValue()); } else if (value instanceof Float) { message.setFloatProperty(name, ((Float) value).floatValue()); } } } }
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. j a v a 2s .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; }
From source file:org.wso2.carbon.apimgt.jms.listener.utils.JMSUtils.java
/** * Set transport headers from the axis message context, into the JMS message * * @param messageConfiguration the adaptor message context * @param message the JMS Message * @throws JMSException on exception//w ww . ja v a2s . c o m */ public static void setTransportHeaders(Map<String, String> messageConfiguration, Message message) throws JMSException { if (messageConfiguration == null) { return; } for (String name : messageConfiguration.keySet()) { if (name.startsWith(JMSConstants.JMSX_PREFIX) && !(name.equals(JMSConstants.JMSX_GROUP_ID) || name.equals(JMSConstants.JMSX_GROUP_SEQ))) { continue; } if (JMSConstants.JMS_COORELATION_ID.equals(name)) { message.setJMSCorrelationID(messageConfiguration.get(JMSConstants.JMS_COORELATION_ID)); } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) { String mode = messageConfiguration.get(JMSConstants.JMS_DELIVERY_MODE); try { message.setJMSDeliveryMode(Integer.parseInt(mode)); } catch (NumberFormatException nfe) { log.warn("Invalid delivery mode ignored : " + mode, nfe); } } else if (JMSConstants.JMS_EXPIRATION.equals(name)) { message.setJMSExpiration(Long.parseLong(messageConfiguration.get(JMSConstants.JMS_EXPIRATION))); } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) { message.setJMSMessageID(messageConfiguration.get(JMSConstants.JMS_MESSAGE_ID)); } else if (JMSConstants.JMS_PRIORITY.equals(name)) { message.setJMSPriority(Integer.parseInt(messageConfiguration.get(JMSConstants.JMS_PRIORITY))); } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) { message.setJMSTimestamp(Long.parseLong(messageConfiguration.get(JMSConstants.JMS_TIMESTAMP))); } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) { message.setJMSType(messageConfiguration.get(JMSConstants.JMS_MESSAGE_TYPE)); } else { //TODO currently only string is supported in messageConfiguration Object value = messageConfiguration.get(name); if (value instanceof String) { message.setStringProperty(name, (String) value); } else if (value instanceof Boolean) { message.setBooleanProperty(name, (Boolean) value); } else if (value instanceof Integer) { message.setIntProperty(name, (Integer) value); } else if (value instanceof Long) { message.setLongProperty(name, (Long) value); } else if (value instanceof Double) { message.setDoubleProperty(name, (Double) value); } else if (value instanceof Float) { message.setFloatProperty(name, (Float) value); } } } }
From source file:org.wso2.carbon.event.output.adapter.jms.internal.util.JMSUtils.java
/** * Set transport headers from the axis message context, into the JMS message * * @param messageConfiguration the adaptor message context * @param message the JMS Message * @throws javax.jms.JMSException on exception *//*www .j ava2 s .c o m*/ public static Message setTransportHeaders(Map<String, String> messageConfiguration, Message message) throws JMSException { if (messageConfiguration == null) { return message; } for (String name : messageConfiguration.keySet()) { if (name.startsWith(JMSConstants.JMSX_PREFIX) && !(name.equals(JMSConstants.JMSX_GROUP_ID) || name.equals(JMSConstants.JMSX_GROUP_SEQ))) { continue; } if (JMSConstants.JMS_COORELATION_ID.equals(name)) { message.setJMSCorrelationID(messageConfiguration.get(JMSConstants.JMS_COORELATION_ID)); } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) { String mode = messageConfiguration.get(JMSConstants.JMS_DELIVERY_MODE); try { message.setJMSDeliveryMode(Integer.parseInt(mode)); } catch (NumberFormatException nfe) { log.warn("Invalid delivery mode ignored : " + mode, nfe); } } else if (JMSConstants.JMS_EXPIRATION.equals(name)) { message.setJMSExpiration(Long.parseLong(messageConfiguration.get(JMSConstants.JMS_EXPIRATION))); } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) { message.setJMSMessageID(messageConfiguration.get(JMSConstants.JMS_MESSAGE_ID)); } else if (JMSConstants.JMS_PRIORITY.equals(name)) { message.setJMSPriority(Integer.parseInt(messageConfiguration.get(JMSConstants.JMS_PRIORITY))); } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) { message.setJMSTimestamp(Long.parseLong(messageConfiguration.get(JMSConstants.JMS_TIMESTAMP))); } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) { message.setJMSType(messageConfiguration.get(JMSConstants.JMS_MESSAGE_TYPE)); } else { //TODO currently only string is supported in messageConfiguration Object value = messageConfiguration.get(name); if (value instanceof String) { message.setStringProperty(name, (String) value); } else if (value instanceof Boolean) { message.setBooleanProperty(name, (Boolean) value); } else if (value instanceof Integer) { message.setIntProperty(name, (Integer) value); } else if (value instanceof Long) { message.setLongProperty(name, (Long) value); } else if (value instanceof Double) { message.setDoubleProperty(name, (Double) value); } else if (value instanceof Float) { message.setFloatProperty(name, (Float) value); } } } return message; }
From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.JMSUtils.java
/** * Set transport headers from the axis message context, into the JMS message * * @param msgContext the axis message context * @param message the JMS Message/*from w w w . ja v a 2 s .com*/ * @throws JMSException on exception */ public static void setTransportHeaders(MessageContext msgContext, Message message) throws JMSException { Map<?, ?> headerMap = (Map<?, ?>) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS); if (headerMap == null) { return; } for (Object headerName : headerMap.keySet()) { String name = (String) headerName; if (name.startsWith(JMSConstants.JMSX_PREFIX) && !(name.equals(JMSConstants.JMSX_GROUP_ID) || name.equals(JMSConstants.JMSX_GROUP_SEQ))) { continue; } if (JMSConstants.JMS_COORELATION_ID.equals(name)) { message.setJMSCorrelationID((String) headerMap.get(JMSConstants.JMS_COORELATION_ID)); } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) { Object o = headerMap.get(JMSConstants.JMS_DELIVERY_MODE); if (o instanceof Integer) { message.setJMSDeliveryMode((Integer) o); } else if (o instanceof String) { try { message.setJMSDeliveryMode(Integer.parseInt((String) o)); } catch (NumberFormatException nfe) { log.warn("Invalid delivery mode ignored : " + o, nfe); } } else { log.warn("Invalid delivery mode ignored : " + o); } } else if (JMSConstants.JMS_EXPIRATION.equals(name)) { message.setJMSExpiration(Long.parseLong((String) headerMap.get(JMSConstants.JMS_EXPIRATION))); } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) { message.setJMSMessageID((String) headerMap.get(JMSConstants.JMS_MESSAGE_ID)); } else if (JMSConstants.JMS_PRIORITY.equals(name)) { message.setJMSPriority(Integer.parseInt((String) headerMap.get(JMSConstants.JMS_PRIORITY))); } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) { message.setJMSTimestamp(Long.parseLong((String) headerMap.get(JMSConstants.JMS_TIMESTAMP))); } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) { message.setJMSType((String) headerMap.get(JMSConstants.JMS_MESSAGE_TYPE)); } else { Object value = headerMap.get(name); if (value instanceof String) { if (name.contains("-")) { if (isHyphenReplaceMode(msgContext)) { // we replace message.setStringProperty(transformHyphenatedString(name), (String) value); } else if (isHyphenDeleteMode(msgContext)) { // we skip continue; } else { message.setStringProperty(name, (String) value); } } else { message.setStringProperty(name, (String) value); } } else if (value instanceof Boolean) { message.setBooleanProperty(name, (Boolean) value); } else if (value instanceof Integer) { message.setIntProperty(name, (Integer) value); } else if (value instanceof Long) { message.setLongProperty(name, (Long) value); } else if (value instanceof Double) { message.setDoubleProperty(name, (Double) value); } else if (value instanceof Float) { message.setFloatProperty(name, (Float) value); } } } }