List of usage examples for javax.jms Message getJMSRedelivered
boolean getJMSRedelivered() throws JMSException;
From source file:org.apache.camel.component.jms.JmsBinding.java
public Map<String, Object> extractHeadersFromJms(Message jmsMessage, Exchange exchange) { Map<String, Object> map = new HashMap<String, Object>(); if (jmsMessage != null) { // lets populate the standard JMS message headers try {// w ww. jav a 2 s.com map.put("JMSCorrelationID", jmsMessage.getJMSCorrelationID()); map.put("JMSDeliveryMode", jmsMessage.getJMSDeliveryMode()); map.put("JMSDestination", jmsMessage.getJMSDestination()); map.put("JMSExpiration", jmsMessage.getJMSExpiration()); map.put("JMSMessageID", jmsMessage.getJMSMessageID()); map.put("JMSPriority", jmsMessage.getJMSPriority()); map.put("JMSRedelivered", jmsMessage.getJMSRedelivered()); map.put("JMSTimestamp", jmsMessage.getJMSTimestamp()); // to work around OracleAQ not supporting the JMSReplyTo header (CAMEL-2909) try { map.put("JMSReplyTo", jmsMessage.getJMSReplyTo()); } catch (JMSException e) { LOG.trace("Cannot read JMSReplyTo header. Will ignore this exception.", e); } // to work around OracleAQ not supporting the JMSType header (CAMEL-2909) try { map.put("JMSType", jmsMessage.getJMSType()); } catch (JMSException e) { LOG.trace("Cannot read JMSType header. Will ignore this exception.", e); } // this works around a bug in the ActiveMQ property handling map.put("JMSXGroupID", jmsMessage.getStringProperty("JMSXGroupID")); } catch (JMSException e) { throw new RuntimeCamelException(e); } Enumeration names; try { names = jmsMessage.getPropertyNames(); } catch (JMSException e) { throw new RuntimeCamelException(e); } while (names.hasMoreElements()) { String name = names.nextElement().toString(); try { Object value = jmsMessage.getObjectProperty(name); if (headerFilterStrategy != null && headerFilterStrategy.applyFilterToExternalHeaders(name, value, exchange)) { continue; } // must decode back from safe JMS header name to original header name // when storing on this Camel JmsMessage object. String key = jmsKeyFormatStrategy.decodeKey(name); map.put(key, value); } catch (JMSException e) { throw new RuntimeCamelException(name, e); } } } return map; }
From source file:org.apache.synapse.transport.jms.JMSUtils.java
/** * Extract transport level headers for JMS from the given message into a Map * * @param message the JMS message//www. j ava 2s.co m * @return a Map of the transport headers */ public static Map getTransportHeaders(Message message) { // create a Map to hold transport headers Map map = new HashMap(); // correlation ID try { if (message.getJMSCorrelationID() != null) { map.put(JMSConstants.JMS_COORELATION_ID, message.getJMSCorrelationID()); } } catch (JMSException ignore) { } // set the delivery mode as persistent or not try { map.put(JMSConstants.JMS_DELIVERY_MODE, Integer.toString(message.getJMSDeliveryMode())); } catch (JMSException ignore) { } // destination name try { if (message.getJMSDestination() != null) { Destination dest = message.getJMSDestination(); map.put(JMSConstants.JMS_DESTINATION, dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName()); } } catch (JMSException ignore) { } // expiration try { map.put(JMSConstants.JMS_EXPIRATION, Long.toString(message.getJMSExpiration())); } catch (JMSException ignore) { } // if a JMS message ID is found try { if (message.getJMSMessageID() != null) { map.put(JMSConstants.JMS_MESSAGE_ID, message.getJMSMessageID()); } } catch (JMSException ignore) { } // priority try { map.put(JMSConstants.JMS_PRIORITY, Long.toString(message.getJMSPriority())); } catch (JMSException ignore) { } // redelivered try { map.put(JMSConstants.JMS_REDELIVERED, Boolean.toString(message.getJMSRedelivered())); } catch (JMSException ignore) { } // replyto destination name try { if (message.getJMSReplyTo() != null) { Destination dest = message.getJMSReplyTo(); map.put(JMSConstants.JMS_REPLY_TO, dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName()); } } catch (JMSException ignore) { } // priority try { map.put(JMSConstants.JMS_TIMESTAMP, Long.toString(message.getJMSTimestamp())); } catch (JMSException ignore) { } // message type try { if (message.getJMSType() != null) { map.put(JMSConstants.JMS_TYPE, message.getJMSType()); } } catch (JMSException ignore) { } // any other transport properties / headers Enumeration e = null; try { e = message.getPropertyNames(); } catch (JMSException ignore) { } if (e != null) { while (e.hasMoreElements()) { String headerName = (String) e.nextElement(); try { map.put(headerName, message.getStringProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, Boolean.valueOf(message.getBooleanProperty(headerName))); continue; } catch (JMSException ignore) { } try { map.put(headerName, new Integer(message.getIntProperty(headerName))); continue; } catch (JMSException ignore) { } try { map.put(headerName, new Long(message.getLongProperty(headerName))); continue; } catch (JMSException ignore) { } try { map.put(headerName, new Double(message.getDoubleProperty(headerName))); continue; } catch (JMSException ignore) { } try { map.put(headerName, new Float(message.getFloatProperty(headerName))); continue; } catch (JMSException ignore) { } } } return map; }
From source file:org.codehaus.stomp.jms.StompSession.java
protected void copyStandardHeadersFromMessageToFrame(Message message, StompFrame command) throws JMSException { final Map headers = command.getHeaders(); headers.put(Stomp.Headers.Message.DESTINATION, convertDestination(message.getJMSDestination())); headers.put(Stomp.Headers.Message.MESSAGE_ID, message.getJMSMessageID()); if (message.getJMSCorrelationID() != null) { headers.put(Stomp.Headers.Message.CORRELATION_ID, message.getJMSCorrelationID()); }//from w w w.j a va 2 s .com headers.put(Stomp.Headers.Message.EXPIRATION_TIME, "" + message.getJMSExpiration()); if (message.getJMSRedelivered()) { headers.put(Stomp.Headers.Message.REDELIVERED, "true"); } headers.put(Stomp.Headers.Message.PRORITY, "" + message.getJMSPriority()); if (message.getJMSReplyTo() != null) { headers.put(Stomp.Headers.Message.REPLY_TO, convertDestination(message.getJMSReplyTo())); } headers.put(Stomp.Headers.Message.TIMESTAMP, "" + message.getJMSTimestamp()); if (message.getJMSType() != null) { headers.put(Stomp.Headers.Message.TYPE, message.getJMSType()); } // now lets add all the message headers Enumeration names = message.getPropertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); Object value = message.getObjectProperty(name); headers.put(name, value); } }
From source file:org.codehaus.stomp.StompTest.java
public void testRedeliveryWithClientAck() throws Exception { String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL; sendFrame(frame);/* w w w .jav a2 s.c om*/ frame = receiveFrame(10000); Assert.assertTrue(frame.startsWith("CONNECTED")); frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "ack:client\n\n" + Stomp.NULL; sendFrame(frame); sendMessage(getName()); frame = receiveFrame(10000); Assert.assertTrue(frame.startsWith("MESSAGE")); frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL; sendFrame(frame); // message should be received since message was not acknowledged MessageConsumer consumer = session.createConsumer(queue); Message message = consumer.receive(1000); Assert.assertNotNull(message); Assert.assertTrue(message.getJMSRedelivered()); }
From source file:org.hyperic.hq.bizapp.server.mdb.RegisteredDispatcherImpl.java
/** * The onMessage method/*w w w. ja v a 2 s .c om*/ * */ @SuppressWarnings("unchecked") public void onMessage(Message inMessage) { if (!(inMessage instanceof ObjectMessage)) { return; } final boolean debug = log.isDebugEnabled(); Object obj; try { ObjectMessage om = (ObjectMessage) inMessage; if (debug) { log.debug("Redelivering message=" + inMessage.getJMSRedelivered()); } obj = om.getObject(); } catch (JMSException e) { log.error("Cannot open message object", e); return; } if (obj instanceof HeartBeatEvent) { final HeartBeatEvent event = (HeartBeatEvent) obj; final long timestamp = event.getTimestamp(); if (debug) log.debug("setting heartbeat timestamp to " + TimeUtil.toString(timestamp)); heartbeatTime.set(timestamp); } if (obj instanceof AbstractEvent) { AbstractEvent event = (AbstractEvent) obj; if (debug) { log.debug("1 event in the message"); } dispatchEvent(event); } else if (obj instanceof Collection<?>) { Collection<AbstractEvent> events = (Collection<AbstractEvent>) obj; if (debug) { log.debug(events.size() + " events in the message"); } for (AbstractEvent event : events) { dispatchEvent(event); } } }
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()); }// w ww. j ava 2 s . c om 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.springframework.integration.jms.DefaultJmsHeaderMapper.java
public Map<String, Object> toHeaders(javax.jms.Message jmsMessage) { Map<String, Object> headers = new HashMap<String, Object>(); try {//w w w . ja v a2 s. c o m try { String messageId = jmsMessage.getJMSMessageID(); if (messageId != null) { headers.put(JmsHeaders.MESSAGE_ID, messageId); } } catch (Exception e) { logger.info("failed to read JMSMessageID property, skipping", e); } try { String correlationId = jmsMessage.getJMSCorrelationID(); if (correlationId != null) { headers.put(JmsHeaders.CORRELATION_ID, correlationId); } } catch (Exception e) { logger.info("failed to read JMSCorrelationID property, skipping", e); } try { Destination replyTo = jmsMessage.getJMSReplyTo(); if (replyTo != null) { headers.put(JmsHeaders.REPLY_TO, replyTo); } } catch (Exception e) { logger.info("failed to read JMSReplyTo property, skipping", e); } try { headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered()); } catch (Exception e) { logger.info("failed to read JMSRedelivered property, skipping", e); } try { String type = jmsMessage.getJMSType(); if (type != null) { headers.put(JmsHeaders.TYPE, type); } } catch (Exception e) { logger.info("failed to read JMSType property, skipping", e); } try { headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp()); } catch (Exception e) { logger.info("failed to read JMSTimestamp property, skipping", e); } Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames(); if (jmsPropertyNames != null) { while (jmsPropertyNames.hasMoreElements()) { String propertyName = jmsPropertyNames.nextElement().toString(); try { String headerName = this.toHeaderName(propertyName); headers.put(headerName, jmsMessage.getObjectProperty(propertyName)); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("error occurred while mapping JMS property '" + propertyName + "' to Message header", e); } } } } } catch (JMSException e) { if (logger.isWarnEnabled()) { logger.warn("error occurred while mapping from JMS properties to MessageHeaders", e); } } return headers; }
From source file:org.springframework.jms.support.converter.SimpleJmsHeaderMapper.java
@Override public Map<String, Object> toHeaders(javax.jms.Message jmsMessage) { Map<String, Object> headers = new HashMap<String, Object>(); try {/* w ww . j a v a2 s. co m*/ try { String correlationId = jmsMessage.getJMSCorrelationID(); if (correlationId != null) { headers.put(JmsHeaders.CORRELATION_ID, correlationId); } } catch (Exception e) { logger.info("failed to read JMSCorrelationID property, skipping", e); } try { Destination destination = jmsMessage.getJMSDestination(); if (destination != null) { headers.put(JmsHeaders.DESTINATION, destination); } } catch (Exception e) { logger.info("failed to read JMSDestination property, skipping", e); } try { int deliveryMode = jmsMessage.getJMSDeliveryMode(); headers.put(JmsHeaders.DELIVERY_MODE, deliveryMode); } catch (Exception e) { logger.info("failed to read JMSDeliveryMode property, skipping", e); } try { long expiration = jmsMessage.getJMSExpiration(); headers.put(JmsHeaders.EXPIRATION, expiration); } catch (Exception e) { logger.info("failed to read JMSExpiration property, skipping", e); } try { String messageId = jmsMessage.getJMSMessageID(); if (messageId != null) { headers.put(JmsHeaders.MESSAGE_ID, messageId); } } catch (Exception e) { logger.info("failed to read JMSMessageID property, skipping", e); } try { headers.put(JmsHeaders.PRIORITY, jmsMessage.getJMSPriority()); } catch (Exception e) { logger.info("failed to read JMSPriority property, skipping", e); } try { Destination replyTo = jmsMessage.getJMSReplyTo(); if (replyTo != null) { headers.put(JmsHeaders.REPLY_TO, replyTo); } } catch (Exception e) { logger.info("failed to read JMSReplyTo property, skipping", e); } try { headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered()); } catch (Exception e) { logger.info("failed to read JMSRedelivered property, skipping", e); } try { String type = jmsMessage.getJMSType(); if (type != null) { headers.put(JmsHeaders.TYPE, type); } } catch (Exception e) { logger.info("failed to read JMSType property, skipping", e); } try { headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp()); } catch (Exception e) { logger.info("failed to read JMSTimestamp property, skipping", e); } Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames(); if (jmsPropertyNames != null) { while (jmsPropertyNames.hasMoreElements()) { String propertyName = jmsPropertyNames.nextElement().toString(); try { String headerName = this.toHeaderName(propertyName); headers.put(headerName, jmsMessage.getObjectProperty(propertyName)); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("error occurred while mapping JMS property '" + propertyName + "' to Message header", e); } } } } } catch (JMSException e) { if (logger.isWarnEnabled()) { logger.warn("error occurred while mapping from JMS properties to MessageHeaders", e); } } return headers; }
From source file:org.springframework.jms.support.SimpleJmsHeaderMapper.java
@Override public MessageHeaders toHeaders(javax.jms.Message jmsMessage) { Map<String, Object> headers = new HashMap<String, Object>(); try {/*from w ww . j a va 2 s. c o m*/ try { String correlationId = jmsMessage.getJMSCorrelationID(); if (correlationId != null) { headers.put(JmsHeaders.CORRELATION_ID, correlationId); } } catch (Exception ex) { logger.info("failed to read JMSCorrelationID property, skipping", ex); } try { Destination destination = jmsMessage.getJMSDestination(); if (destination != null) { headers.put(JmsHeaders.DESTINATION, destination); } } catch (Exception ex) { logger.info("failed to read JMSDestination property, skipping", ex); } try { int deliveryMode = jmsMessage.getJMSDeliveryMode(); headers.put(JmsHeaders.DELIVERY_MODE, deliveryMode); } catch (Exception ex) { logger.info("failed to read JMSDeliveryMode property, skipping", ex); } try { long expiration = jmsMessage.getJMSExpiration(); headers.put(JmsHeaders.EXPIRATION, expiration); } catch (Exception ex) { logger.info("failed to read JMSExpiration property, skipping", ex); } try { String messageId = jmsMessage.getJMSMessageID(); if (messageId != null) { headers.put(JmsHeaders.MESSAGE_ID, messageId); } } catch (Exception ex) { logger.info("failed to read JMSMessageID property, skipping", ex); } try { headers.put(JmsHeaders.PRIORITY, jmsMessage.getJMSPriority()); } catch (Exception ex) { logger.info("failed to read JMSPriority property, skipping", ex); } try { Destination replyTo = jmsMessage.getJMSReplyTo(); if (replyTo != null) { headers.put(JmsHeaders.REPLY_TO, replyTo); } } catch (Exception ex) { logger.info("failed to read JMSReplyTo property, skipping", ex); } try { headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered()); } catch (Exception ex) { logger.info("failed to read JMSRedelivered property, skipping", ex); } try { String type = jmsMessage.getJMSType(); if (type != null) { headers.put(JmsHeaders.TYPE, type); } } catch (Exception ex) { logger.info("failed to read JMSType property, skipping", ex); } try { headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp()); } catch (Exception ex) { logger.info("failed to read JMSTimestamp property, skipping", ex); } Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames(); if (jmsPropertyNames != null) { while (jmsPropertyNames.hasMoreElements()) { String propertyName = jmsPropertyNames.nextElement().toString(); try { String headerName = this.toHeaderName(propertyName); headers.put(headerName, jmsMessage.getObjectProperty(propertyName)); } catch (Exception ex) { if (logger.isWarnEnabled()) { logger.warn("Error occurred while mapping JMS property '" + propertyName + "' to Message header", ex); } } } } } catch (JMSException ex) { if (logger.isWarnEnabled()) { logger.warn("Error occurred while mapping from JMS properties to MessageHeaders", ex); } } return new MessageHeaders(headers); }
From source file:org.wso2.mb.integration.common.clients.operations.queue.QueueMessageListener.java
public void onMessage(Message message) { messageCount.incrementAndGet();//w w w.ja v a 2 s .c o m localMessageCount++; Message receivedMessage = message; try { String redelivery = ""; if (message.getJMSRedelivered()) { redelivery = "REDELIVERED"; } else { redelivery = "ORIGINAL"; } if (messageCount.get() % printNumberOfMessagesPer == 0) { log.info("[QUEUE RECEIVE] ThreadID:" + Thread.currentThread().getId() + " queue:" + queueName + " " + "localMessageCount:" + localMessageCount + " totalMessageCount:" + messageCount.get() + " max" + " count:" + stopMessageCount); } if (receivedMessage instanceof TextMessage) { TextMessage textMessage = (TextMessage) receivedMessage; if (isToPrintEachMessage) { log.info("(count:" + messageCount.get() + "/threadID:" + Thread.currentThread().getId() + "/queue:" + queueName + ") " + redelivery + " >> " + textMessage.getText()); AndesClientUtils.writeToFile(textMessage.getText(), fileToWriteReceivedMessages); } } if (messageCount.get() % ackAfterEach == 0) { if (queueSession.getAcknowledgeMode() == QueueSession.CLIENT_ACKNOWLEDGE) { receivedMessage.acknowledge(); log.info("Acked message : " + receivedMessage.getJMSMessageID()); } } //commit get priority if (messageCount.get() % commitPerMessageCount == 0) { queueSession.commit(); log.info("Committed Queue Session"); } else if (messageCount.get() % rollbackPerMessagecount == 0) { queueSession.rollback(); log.info("Rollbacked Queue Session"); } if (messageCount.get() >= stopMessageCount) { stopMessageListener(); AndesClientUtils.sleepForInterval(200); } if (delayBetweenMessages != 0) { try { Thread.sleep(delayBetweenMessages); } catch (InterruptedException e) { //silently ignore } } } catch (NumberFormatException e) { log.error("Wrong inputs.", e); } catch (JMSException e) { log.error("JMS Exception", e); } }