List of usage examples for javax.jms Message getPropertyNames
Enumeration getPropertyNames() throws JMSException;
From source file:org.sdnmq.jms_demoapps.FilteringPacketInSubscriber.java
private static void printMsgProperties(Message msg) { try {//from w w w . j a v a2 s. c o m Enumeration keys = msg.getPropertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); Object value = msg.getObjectProperty(key); System.out.println(key + " " + value.toString()); } } catch (JMSException e) { System.err.println(e.getMessage()); } }
From source file:com.icesoft.net.messaging.jms.AbstractJMSConnection.java
protected static String toString(final javax.jms.Message message) { StringBuffer _messageString = new StringBuffer(); try {/*from ww w. j a v a 2s. c o m*/ Enumeration _propertyNames = message.getPropertyNames(); while (_propertyNames.hasMoreElements()) { String _propertyName = (String) _propertyNames.nextElement(); _messageString.append(_propertyName); _messageString.append(": "); _messageString.append(message.getObjectProperty(_propertyName)); _messageString.append("\r\n"); } _messageString.append("\r\n"); if (message instanceof javax.jms.ObjectMessage) { _messageString.append(((javax.jms.ObjectMessage) message).getObject()); } else if (message instanceof javax.jms.TextMessage) { _messageString.append(((javax.jms.TextMessage) message).getText()); } _messageString.append("\r\n"); } catch (JMSException exception) { // do nothing (this is just a toString() method) } return _messageString.toString(); }
From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.JMSUtils.java
/** * Extract transport level headers from JMS message into a Map * @param message JMS message/*from w w w. ja v a 2 s. c om*/ * @param msgContext axis2 message context * @return a Map of the transport headers */ public static Map<String, Object> getTransportHeaders(Message message, MessageContext msgContext) { // create a Map to hold transport headers Map<String, Object> map = new HashMap<>(); try { Enumeration<?> propertyNamesEnm = message.getPropertyNames(); while (propertyNamesEnm.hasMoreElements()) { String headerName = (String) propertyNamesEnm.nextElement(); Object headerValue = message.getObjectProperty(headerName); if (headerValue instanceof String) { if (isHyphenReplaceMode(msgContext)) { map.put(inverseTransformHyphenatedString(headerName), message.getStringProperty(headerName)); } else { map.put(headerName, message.getStringProperty(headerName)); } } else if (headerValue instanceof Integer) { map.put(headerName, message.getIntProperty(headerName)); } else if (headerValue instanceof Boolean) { map.put(headerName, message.getBooleanProperty(headerName)); } else if (headerValue instanceof Long) { map.put(headerName, message.getLongProperty(headerName)); } else if (headerValue instanceof Double) { map.put(headerName, message.getDoubleProperty(headerName)); } else if (headerValue instanceof Float) { map.put(headerName, message.getFloatProperty(headerName)); } else { map.put(headerName, headerValue); } } } catch (JMSException e) { log.error("Error while reading the Transport Headers from JMS Message", e); } return map; }
From source file:org.wso2.carbon.andes.core.internal.util.Utils.java
/** * Gets properties of a JMS message// w w w.j a va2 s. com * * @param message message object * @return String value of all the properties of the message * @throws JMSException */ public static String getMsgProperties(Message message) throws JMSException { Enumeration propertiesEnu = message.getPropertyNames(); StringBuilder sb = new StringBuilder(""); if (propertiesEnu != null) { while (propertiesEnu.hasMoreElements()) { String propName = (String) propertiesEnu.nextElement(); sb.append(propName).append(" = ").append(message.getStringProperty(propName)); sb.append(", "); } } return sb.toString(); }
From source file:org.jbpm.bpel.integration.jms.RequestListener.java
public static String messageToString(Message message) throws JMSException { StringBuffer result = new StringBuffer(); // ID & destination result.append("id=").append(message.getJMSMessageID()).append(", destination=") .append(message.getJMSDestination()); // replyTo & correlationID Destination replyTo = message.getJMSReplyTo(); if (replyTo != null) { result.append(", replyTo=").append(replyTo).append(", correlationId=") .append(message.getJMSCorrelationID()); }//from w w w. j a va 2s . com // properties Enumeration propertyNames = message.getPropertyNames(); while (propertyNames.hasMoreElements()) { String propertyName = (String) propertyNames.nextElement(); result.append(", ").append(propertyName).append('=').append(message.getObjectProperty(propertyName)); } return result.toString(); }
From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java
public static String formatMessage(Message message) { StringBuilder sb = new StringBuilder(); try {/*from w w w .j a va 2 s. c o m*/ String headers = formatHeaders(message); if (headers.length() > 0) { sb.append("Message Headers:\n"); sb.append(headers); } sb.append("Message Properties:\n"); @SuppressWarnings("unchecked") Enumeration<String> propNames = message.getPropertyNames(); while (propNames.hasMoreElements()) { String propertyName = propNames.nextElement(); sb.append(" "); sb.append(propertyName); sb.append(": "); if (message.getObjectProperty(propertyName) != null) { sb.append(message.getObjectProperty(propertyName).toString()); } sb.append("\n"); } sb.append("Message Content:\n"); if (message instanceof TextMessage) { sb.append(((TextMessage) message).getText()); } else if (message instanceof MapMessage) { MapMessage mm = (MapMessage) message; ObjectMapper mapper = new ObjectMapper(); ObjectNode root = mapper.createObjectNode(); @SuppressWarnings("unchecked") Enumeration<String> e = mm.getMapNames(); while (e.hasMoreElements()) { String field = e.nextElement(); root.put(field, mapper.convertValue(mm.getObject(field), JsonNode.class)); } sb.append(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root)); } else if (message instanceof BytesMessage) { BytesMessage bm = (BytesMessage) message; bm.reset(); byte[] bytes = new byte[(int) bm.getBodyLength()]; if (bm.readBytes(bytes) == bm.getBodyLength()) { sb.append(new String(bytes)); } } else { sb.append(" Unhandled message type: " + message.getJMSType()); } } catch (Exception e) { log.log(Level.SEVERE, "Unable to format message:", e); } return sb.toString(); }
From source file:com.atlantbh.jmeter.plugins.jmstools.BinaryMessageConverter.java
@Override public Object fromMessage(Message message) throws JMSException, MessageConversionException { Enumeration<String> names = message.getPropertyNames(); messageProperties = new HashMap<String, String>(); while (names.hasMoreElements()) { String name = names.nextElement(); messageProperties.put(name, message.getStringProperty(name)); }/*from w w w . j av a 2 s .c o m*/ BytesMessage bm = (BytesMessage) message; byte[] transfer = new byte[(int) bm.getBodyLength()]; bm.readBytes(transfer); return new String(transfer); }
From source file:org.wso2.carbon.andes.ui.client.QueueBrowserClient.java
/** * Get message details of the input javax.jms.Message object. * @param queueMessage javax.jms.Message (ideally fetched through the Queue Browser Enumeration) * @return String representation of the message * @throws JMSException/*ww w .ja v a 2s. co m*/ */ public String getMsgProperties(Message queueMessage) throws JMSException { Enumeration propertiesEnu = queueMessage.getPropertyNames(); StringBuilder sb = new StringBuilder(""); if (propertiesEnu != null) { while (propertiesEnu.hasMoreElements()) { String propName = (String) propertiesEnu.nextElement(); sb.append(propName).append(" = ").append(queueMessage.getStringProperty(propName)); sb.append(", "); } } return sb.toString(); }
From source file:com.adaptris.core.jms.MetadataHandler.java
private MetadataCollection createMetadataCollection(Message in) throws JMSException { MetadataCollection result = new MetadataCollection(); Enumeration props = in.getPropertyNames(); while (props.hasMoreElements()) { String key = (String) props.nextElement(); String value = in.getStringProperty(key); // converts all to Strings if (!isEmpty(value)) { result.add(new MetadataElement(key, value)); } else {/*ww w. j a v a 2 s . co m*/ log.debug("ignoring null or empty metadata value against key [" + key + "]"); } } return result; }
From source file:net.timewalker.ffmq4.admin.RemoteAdministrationThread.java
private Settings createSettings(Message msg) throws JMSException { // Fill settings from message headers Settings queueSettings = new Settings(); Enumeration<?> headers = msg.getPropertyNames(); while (headers.hasMoreElements()) { String propName = (String) headers.nextElement(); if (propName.startsWith(FFMQAdminConstants.ADM_HEADER_PREFIX)) continue; String propValue = msg.getStringProperty(propName); queueSettings.setStringProperty(propName, propValue); }/*from w w w.java2 s .c om*/ return queueSettings; }