List of usage examples for javax.jms Message getJMSDeliveryMode
int getJMSDeliveryMode() throws JMSException;
From source file:com.jmstoolkit.beans.MessageTableModel.java
/** * * @param message/*w w w.j a v a2 s . co m*/ */ @Override public void onMessage(Message message) { LOGGER.log(Level.FINE, "Message Received"); messagesReceived++; try { MessageTableRecord qRecord = new MessageTableRecord(); qRecord.setJMSCorrelationID(message.getJMSCorrelationID()); qRecord.setJMSDeliveryMode(message.getJMSDeliveryMode()); qRecord.setJMSExpiration(message.getJMSExpiration()); qRecord.setJMSMessageID(message.getJMSMessageID()); qRecord.setJMSTimestamp(message.getJMSTimestamp()); qRecord.setJMSType(message.getJMSType()); qRecord.setJMSDestination(message.getJMSDestination()); qRecord.setJMSCorrelationIDAsBytes(message.getJMSCorrelationIDAsBytes()); qRecord.setJMSPriority(message.getJMSPriority()); qRecord.setJMSType(message.getJMSType()); qRecord.setJMSReplyTo(message.getJMSReplyTo()); qRecord.setJMSRedelivered(message.getJMSRedelivered()); Enumeration pEnumerator = message.getPropertyNames(); Properties props = new Properties(); while (pEnumerator.hasMoreElements()) { String pElement = (String) pEnumerator.nextElement(); props.put(pElement, message.getStringProperty(pElement)); } qRecord.setProperties(props); if (message instanceof TextMessage) { qRecord.setText(((TextMessage) message).getText()); } if (message instanceof ObjectMessage) { qRecord.setObject(((ObjectMessage) message).getObject()); } List newData = data; newData.add(qRecord); this.setData(newData); } catch (JMSException e) { LOGGER.log(Level.WARNING, "JMS problem", e); } }
From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java
private static String formatHeaders(Message message) { Destination dest = null;/*from ww w .jav a2s .c o m*/ int delMode = 0; long expiration = 0; Time expTime = null; int priority = 0; String msgID = null; long timestamp = 0; Time timestampTime = null; String correlID = null; Destination replyTo = null; boolean redelivered = false; String type = null; StringBuilder sb = new StringBuilder(); try { try { dest = message.getJMSDestination(); sb.append(" JMSDestination: "); sb.append(dest); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSDestination header\n", e); } try { delMode = message.getJMSDeliveryMode(); if (delMode == DeliveryMode.NON_PERSISTENT) { sb.append(" JMSDeliveryMode: non-persistent\n"); } else if (delMode == DeliveryMode.PERSISTENT) { sb.append(" JMSDeliveryMode: persistent\n"); } else { sb.append(" JMSDeliveryMode: neither persistent nor non-persistent; error\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSDeliveryMode header\n", e); } try { expiration = message.getJMSExpiration(); if (expiration != 0) { expTime = new Time(expiration); sb.append(" JMSExpiration: "); sb.append(expTime); sb.append("\n"); } else { sb.append(" JMSExpiration: 0\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSExpiration header\n", e); } try { priority = message.getJMSPriority(); sb.append(" JMSPriority: "); sb.append(priority); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSPriority header\n", e); } try { msgID = message.getJMSMessageID(); sb.append(" JMSMessageID: "); sb.append(msgID); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSMessageID header\n", e); } try { timestamp = message.getJMSTimestamp(); if (timestamp != 0) { timestampTime = new Time(timestamp); sb.append(" JMSTimestamp: "); sb.append(timestampTime); sb.append("\n"); } else { sb.append(" JMSTimestamp: 0\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSTimestamp header\n", e); } try { correlID = message.getJMSCorrelationID(); sb.append(" JMSCorrelationID: "); sb.append(correlID); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSCorrelationID header\n", e); } try { replyTo = message.getJMSReplyTo(); sb.append(" JMSReplyTo: "); sb.append(replyTo); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSReplyTo header\n", e); } try { redelivered = message.getJMSRedelivered(); sb.append(" JMSRedelivered: "); sb.append(redelivered); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSRedelivered header\n", e); } try { type = message.getJMSType(); sb.append(" JMSType: "); sb.append(type); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSType header\n", e); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMS headers\n", e); } return sb.toString(); }
From source file:com.eviware.soapui.impl.wsdl.submit.transports.jms.HermesJmsRequestTransport.java
private Message send(SubmitContext submitContext, Request request, Hermes hermes, MessageProducer messageProducer, Message message, Destination replyToDestination) throws JMSException { JMSHeader jmsHeader = createJMSHeader(submitContext, request, hermes, message, replyToDestination); messageProducer.send(message, message.getJMSDeliveryMode(), message.getJMSPriority(), jmsHeader.getTimeTolive());//w w w.jav a 2 s .c o m submitContext.setProperty(JMS_MESSAGE_SEND, message); return message; }
From source file:com.adaptris.core.jms.MessageTypeTranslatorCase.java
public void testMoveJmsHeadersAdaptrisMessageToJmsMessage() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); MessageTypeTranslatorImp trans = createTranslator(); try {/*from w ww . j a v a2s . c o m*/ broker.start(); Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); addMetadata(msg); addRedundantJmsHeaders(msg); trans.setMoveJmsHeaders(true); start(trans, session); Message jmsMsg = trans.translate(msg); assertEquals(msg.getMetadataValue(JMS_TYPE), jmsMsg.getJMSType()); assertNotSame(msg.getMetadataValue(JMS_CORRELATION_ID), jmsMsg.getJMSCorrelationID()); assertNotSame(msg.getMetadataValue(JMS_TIMESTAMP), jmsMsg.getJMSTimestamp()); assertNotSame(msg.getMetadataValue(JMS_REDELIVERED), jmsMsg.getJMSPriority()); assertNotSame(msg.getMetadataValue(JMS_MESSAGE_ID), jmsMsg.getJMSMessageID()); assertNotSame(msg.getMetadataValue(JMS_EXPIRATION), jmsMsg.getJMSExpiration()); assertNotSame(msg.getMetadataValue(JMS_DELIVERY_MODE), jmsMsg.getJMSDeliveryMode()); assertJmsProperties(jmsMsg); } finally { stop(trans); broker.destroy(); } }
From source file:hermes.impl.DefaultXMLHelper.java
public XMLMessage createXMLMessage(ObjectFactory factory, Message message) throws JMSException, IOException, EncoderException { try {/*from w w w .ja v a 2 s .com*/ XMLMessage rval = factory.createXMLMessage(); if (message instanceof TextMessage) { rval = factory.createXMLTextMessage(); XMLTextMessage textRval = (XMLTextMessage) rval; TextMessage textMessage = (TextMessage) message; if (isBase64EncodeTextMessages()) { byte[] bytes = base64EncoderTL.get().encode(textMessage.getText().getBytes()); textRval.setText(new String(bytes, "ASCII")); textRval.setCodec(BASE64_CODEC); } else { textRval.setText(textMessage.getText()); } } else if (message instanceof MapMessage) { rval = factory.createXMLMapMessage(); XMLMapMessage mapRval = (XMLMapMessage) rval; MapMessage mapMessage = (MapMessage) message; for (Enumeration iter = mapMessage.getMapNames(); iter.hasMoreElements();) { String propertyName = (String) iter.nextElement(); Object propertyValue = mapMessage.getObject(propertyName); Property xmlProperty = factory.createProperty(); if (propertyValue != null) { xmlProperty.setValue(propertyValue.toString()); xmlProperty.setType(propertyValue.getClass().getName()); } xmlProperty.setName(propertyName); mapRval.getBodyProperty().add(xmlProperty); } } else if (message instanceof BytesMessage) { rval = factory.createXMLBytesMessage(); XMLBytesMessage bytesRval = (XMLBytesMessage) rval; BytesMessage bytesMessage = (BytesMessage) message; ByteArrayOutputStream bosream = new ByteArrayOutputStream(); bytesMessage.reset(); try { for (;;) { bosream.write(bytesMessage.readByte()); } } catch (MessageEOFException ex) { // NOP } bytesRval.setBytes(new String(base64EncoderTL.get().encode(bosream.toByteArray()))); } else if (message instanceof ObjectMessage) { rval = factory.createXMLObjectMessage(); XMLObjectMessage objectRval = (XMLObjectMessage) rval; ObjectMessage objectMessage = (ObjectMessage) message; ByteArrayOutputStream bostream = new ByteArrayOutputStream(); ObjectOutputStream oostream = new ObjectOutputStream(bostream); oostream.writeObject(objectMessage.getObject()); oostream.flush(); byte b[] = base64EncoderTL.get().encode(bostream.toByteArray()); String s = new String(b, "ASCII"); objectRval.setObject(s); } if (message.getJMSReplyTo() != null) { rval.setJMSReplyTo(JMSUtils.getDestinationName(message.getJMSReplyTo())); rval.setJMSReplyToDomain(Domain.getDomain(message.getJMSReplyTo()).getId()); } // try/catch each individually as we sometime find some JMS // providers // can barf try { rval.setJMSDeliveryMode(message.getJMSDeliveryMode()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { rval.setJMSExpiration(message.getJMSExpiration()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { rval.setJMSMessageID(message.getJMSMessageID()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { rval.setJMSPriority(message.getJMSPriority()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { rval.setJMSRedelivered(message.getJMSRedelivered()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } catch (IllegalStateException ex) { // http://hermesjms.com/forum/viewtopic.php?f=4&t=346 log.error(ex.getMessage(), ex); } try { rval.setJMSTimestamp(message.getJMSTimestamp()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { rval.setJMSType(message.getJMSType()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { rval.setJMSCorrelationID(message.getJMSCorrelationID()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { if (message.getJMSDestination() != null) { rval.setJMSDestination(JMSUtils.getDestinationName(message.getJMSDestination())); rval.setFromQueue(JMSUtils.isQueue(message.getJMSDestination())); } } catch (JMSException ex) { log.error(ex.getMessage(), ex); } for (final Enumeration iter = message.getPropertyNames(); iter.hasMoreElements();) { String propertyName = (String) iter.nextElement(); if (!propertyName.startsWith("JMS")) { Object propertyValue = message.getObjectProperty(propertyName); Property property = factory.createProperty(); property.setName(propertyName); if (propertyValue != null) { property.setValue(StringEscapeUtils.escapeXml(propertyValue.toString())); property.setType(propertyValue.getClass().getName()); } rval.getHeaderProperty().add(property); } } return rval; } catch (Exception ex) { throw new HermesException(ex); } }
From source file:net.timewalker.ffmq4.remote.session.RemoteSession.java
protected final void dispatch(Message message) throws JMSException { if (debugEnabled) log.debug("#" + id + " Sending message " + message.getJMSMessageID()); boolean asyncDispatch = transacted || message.getJMSDeliveryMode() == DeliveryMode.NON_PERSISTENT; PutQuery query = new PutQuery(); query.setSessionId(id);/* w w w . j a v a2 s. c o m*/ if (asyncDispatch) { // Create a message copy to make sure the message is not modified concurrently Message msgCopy = MessageTools.makeInternalCopy(message); query.setMessage((AbstractMessage) msgCopy); } else query.setMessage((AbstractMessage) message); if (asyncDispatch) transportEndpoint.nonBlockingRequest(query); else { if (retryOnQueueFull) retriableBlockingQuery(query, retryTimeout); else transportEndpoint.blockingRequest(query); } }
From source file:nl.nn.adapterframework.jms.JMSFacade.java
public String send(MessageProducer messageProducer, Message message, boolean ignoreInvalidDestinationException) throws NamingException, JMSException { if (log.isDebugEnabled()) { log.debug(getLogPrefix() + "sender on [" + getDestinationName() + "] will send message with JMSDeliveryMode=[" + message.getJMSDeliveryMode() + "] \n JMSMessageID=[" + message.getJMSMessageID() + "] \n JMSCorrelationID=[" + message.getJMSCorrelationID() + "] \n JMSTimestamp=[" + DateUtils.format(message.getJMSTimestamp()) + "] \n JMSExpiration=[" + message.getJMSExpiration() + "] \n JMSPriority=[" + message.getJMSPriority() + "] \n Message=[" + message.toString() + "]"); }/*from w w w . j av a 2s . c o m*/ try { if (useJms102()) { if (messageProducer instanceof TopicPublisher) { ((TopicPublisher) messageProducer).publish(message); } else { ((QueueSender) messageProducer).send(message); } return message.getJMSMessageID(); } else { messageProducer.send(message); return message.getJMSMessageID(); } } catch (InvalidDestinationException e) { if (ignoreInvalidDestinationException) { log.warn("queue [" + messageProducer.getDestination() + "] doesn't exist"); return null; } else { throw e; } } }
From source file:nl.nn.adapterframework.jms.JmsListenerBase.java
protected String retrieveIdFromMessage(Message message, Map threadContext) throws ListenerException { String cid = "unset"; String mode = "unknown"; String id = "unset"; Date tsSent = null;/*from w ww .ja v a2s . co m*/ Destination replyTo = null; try { mode = deliveryModeToString(message.getJMSDeliveryMode()); } catch (JMSException ignore) { log.debug("ignoring JMSException in getJMSDeliveryMode()", ignore); } // -------------------------- // retrieve MessageID // -------------------------- try { id = message.getJMSMessageID(); } catch (JMSException ignore) { log.debug("ignoring JMSException in getJMSMessageID()", ignore); } // -------------------------- // retrieve CorrelationID // -------------------------- try { if (isForceMessageIdAsCorrelationId()) { if (log.isDebugEnabled()) log.debug("forcing the messageID to be the correlationID"); cid = id; } else { cid = message.getJMSCorrelationID(); if (cid == null) { cid = id; log.debug("Setting correlation ID to MessageId"); } } } catch (JMSException ignore) { log.debug("ignoring JMSException in getJMSCorrelationID()", ignore); } // -------------------------- // retrieve TimeStamp // -------------------------- try { long lTimeStamp = message.getJMSTimestamp(); tsSent = new Date(lTimeStamp); } catch (JMSException ignore) { log.debug("ignoring JMSException in getJMSTimestamp()", ignore); } // -------------------------- // retrieve ReplyTo address // -------------------------- try { replyTo = message.getJMSReplyTo(); } catch (JMSException ignore) { log.debug("ignoring JMSException in getJMSReplyTo()", ignore); } if (log.isDebugEnabled()) { log.debug(getLogPrefix() + "listener on [" + getDestinationName() + "] got message with JMSDeliveryMode=[" + mode + "] \n JMSMessageID=[" + id + "] \n JMSCorrelationID=[" + cid + "] \n Timestamp Sent=[" + DateUtils.format(tsSent) + "] \n ReplyTo=[" + ((replyTo == null) ? "none" : replyTo.toString()) + "] \n Message=[" + message.toString() + "]"); } PipeLineSessionBase.setListenerParameters(threadContext, id, cid, null, tsSent); threadContext.put("timestamp", tsSent); threadContext.put("replyTo", replyTo); try { if (getAckMode() == Session.CLIENT_ACKNOWLEDGE) { message.acknowledge(); log.debug("Listener on [" + getDestinationName() + "] acknowledged message"); } } catch (JMSException e) { log.error("Warning in ack", e); } return cid; }
From source file:org.apache.axis2.transport.jms.JMSMessageReceiver.java
/** * Process a new message received/*from w w w . jav a 2 s . c o m*/ * * @param message the JMS message received * @param ut UserTransaction which was used to receive the message * @return true if caller should commit */ public boolean onMessage(Message message, UserTransaction ut) { try { if (log.isDebugEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("Received new JMS message for service :").append(endpoint.getServiceName()); sb.append("\nDestination : ").append(message.getJMSDestination()); sb.append("\nMessage ID : ").append(message.getJMSMessageID()); sb.append("\nCorrelation ID : ").append(message.getJMSCorrelationID()); sb.append("\nReplyTo : ").append(message.getJMSReplyTo()); sb.append("\nRedelivery ? : ").append(message.getJMSRedelivered()); sb.append("\nPriority : ").append(message.getJMSPriority()); sb.append("\nExpiration : ").append(message.getJMSExpiration()); sb.append("\nTimestamp : ").append(message.getJMSTimestamp()); sb.append("\nMessage Type : ").append(message.getJMSType()); sb.append("\nPersistent ? : ").append(DeliveryMode.PERSISTENT == message.getJMSDeliveryMode()); log.debug(sb.toString()); if (log.isTraceEnabled() && message instanceof TextMessage) { log.trace("\nMessage : " + ((TextMessage) message).getText()); } } } catch (JMSException e) { if (log.isDebugEnabled()) { log.debug("Error reading JMS message headers for debug logging", e); } } // update transport level metrics try { metrics.incrementBytesReceived(JMSUtils.getMessageSize(message)); } catch (JMSException e) { log.warn("Error reading JMS message size to update transport metrics", e); } // has this message already expired? expiration time == 0 means never expires // TODO: explain why this is necessary; normally it is the responsibility of the provider to handle message expiration try { long expiryTime = message.getJMSExpiration(); if (expiryTime > 0 && System.currentTimeMillis() > expiryTime) { if (log.isDebugEnabled()) { log.debug("Discard expired message with ID : " + message.getJMSMessageID()); } return true; } } catch (JMSException ignore) { } boolean successful = false; try { successful = processThoughEngine(message, ut); } catch (JMSException e) { log.error("JMS Exception encountered while processing", e); } catch (AxisFault e) { log.error("Axis fault processing message", e); } catch (Exception e) { log.error("Unknown error processing message", e); } finally { if (successful) { metrics.incrementMessagesReceived(); } else { metrics.incrementFaultsReceiving(); } } return successful; }
From source file:org.apache.axis2.transport.jms.JMSUtils.java
/** * Extract transport level headers for JMS from the given message into a Map * * @param message the JMS message// w ww .j a va2 s.com * @return a Map of the transport headers */ public static Map<String, Object> getTransportHeaders(Message message) { // create a Map to hold transport headers Map<String, Object> map = new HashMap<String, Object>(); // 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, message.getBooleanProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getIntProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getLongProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getDoubleProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getFloatProperty(headerName)); } catch (JMSException ignore) { } } } return map; }