List of usage examples for javax.jms Message getPropertyNames
Enumeration getPropertyNames() throws JMSException;
From source file:org.apache.activemq.usecases.RequestReplyToTopicViaThreeNetworkHopsTest.java
public static String fmtMsgInfo(Message msg) throws Exception { StringBuilder msg_desc;/*from www . ja v a2 s . c o m*/ String prop; Enumeration<?> prop_enum; msg_desc = new StringBuilder(); msg_desc = new StringBuilder(); if (msg instanceof TextMessage) { msg_desc.append(((TextMessage) msg).getText()); } else { msg_desc.append("["); msg_desc.append(msg.getClass().getName()); msg_desc.append("]"); } prop_enum = msg.getPropertyNames(); while (prop_enum.hasMoreElements()) { prop = (String) prop_enum.nextElement(); msg_desc.append("; "); msg_desc.append(prop); msg_desc.append("="); msg_desc.append(msg.getStringProperty(prop)); } return msg_desc.toString(); }
From source file:org.exist.replication.jms.obsolete.FileSystemListener.java
@Override public void onMessage(Message message) { try {// ww w .ja v a2 s .c o m LOG.info("JMSMessageID=" + message.getJMSMessageID()); StringBuilder sb = new StringBuilder(); // Write properties Enumeration names = message.getPropertyNames(); for (Enumeration<?> e = names; e.hasMoreElements();) { String key = (String) e.nextElement(); sb.append("'" + key + "='" + message.getStringProperty(key) + "' "); } LOG.info(sb.toString()); // Handle message if (message instanceof TextMessage) { LOG.info(((TextMessage) message).getText()); } else if (message instanceof BytesMessage) { BytesMessage bm = (BytesMessage) message; eXistMessage em = convertMessage(bm); switch (em.getResourceType()) { case DOCUMENT: handleDocument(em); break; case COLLECTION: handleCollection(em); break; default: LOG.error("Unknown resource type"); break; } } } catch (JMSException ex) { LOG.error(ex); } }
From source file:org.openadaptor.auxil.connector.jms.JMSReadConnector.java
/** * Copy any JMS Message Properties into the metadata. * /*from w ww .ja v a 2 s. c o m*/ * @param msg * @throws JMSException */ protected void readMetadataFromMessageProperties(Message msg) throws JMSException { Map addToMetadata = new HashMap(); Enumeration names = msg.getPropertyNames(); while (names.hasMoreElements()) { String nextName = (String) names.nextElement(); addToMetadata.put(nextName, msg.getObjectProperty(nextName)); } metadata.putAll(addToMetadata); }
From source file:com.fusesource.forge.jmstest.tests.AsyncConsumer.java
public void onMessage(Message msg) { if (receiveCount != null) { receiveCount.incrementAndGet();//from w w w . j av a 2 s . c o m } MessageProducer producer = null; try { Destination replyDest = msg.getJMSReplyTo(); if (replyDest != null) { Message response = getSession().createTextMessage("Response"); response.setStringProperty("ServedBy", getName()); response.setJMSCorrelationID(msg.getJMSCorrelationID()); for (Enumeration<?> en = msg.getPropertyNames(); en.hasMoreElements();) { String key = (String) en.nextElement(); Object value = msg.getObjectProperty(key); if (key.equals("BrokerStamp")) { value = value.toString() + " --"; } response.setObjectProperty(key, value); } producer = getSession().createProducer(replyDest); producer.send(response); } } catch (Exception e) { LOG.error(e); } finally { if (producer != null) { try { producer.close(); } catch (Exception e) { } } } }
From source file:org.apache.axis2.transport.jms.LogAspect.java
@Before("(call(void javax.jms.MessageProducer.send(javax.jms.Message)) ||" + " call(void javax.jms.TopicPublisher.publish(javax.jms.Message))) && args(message)") public void beforeSend(Message message) { try {/*from www . j a va 2s . c o m*/ OutputStream out = LogManager.INSTANCE.createLog("jms"); try { PrintWriter pw = new PrintWriter(new OutputStreamWriter(out), false); pw.println("Type: " + message.getClass().getName()); pw.println("JMS message ID: " + message.getJMSMessageID()); pw.println("JMS correlation ID: " + message.getJMSCorrelationID()); pw.println("JMS reply to: " + message.getJMSReplyTo()); for (Enumeration<?> e = message.getPropertyNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); pw.print(name); pw.print(": "); pw.println(message.getStringProperty(name)); } pw.println(); pw.flush(); if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; bytesMessage.reset(); IOUtils.copy(new BytesMessageInputStream(bytesMessage), out); } else if (message instanceof TextMessage) { pw.print(((TextMessage) message).getText()); pw.flush(); } } finally { out.close(); } } catch (Throwable ex) { log.error("Failed to dump JMS message", ex); } }
From source file:org.jwebsocket.jms.endpoint.JMSEndPointSender.java
/** * * @param aTargetId//from ww w . j a v a 2s.com * @param aCorrelationID * @param aText * @param aResponseListener * @param aTimeout */ public synchronized void sendText(String aTargetId, final String aCorrelationID, final String aText, IJMSResponseListener aResponseListener, long aTimeout) { Message lMsg; try { lMsg = mSession.createTextMessage(aText); if (null != aCorrelationID) { lMsg.setJMSCorrelationID(aCorrelationID); } lMsg.setStringProperty("targetId", aTargetId); lMsg.setStringProperty("sourceId", mEndPointId); if (mLog.isDebugEnabled()) { StringBuilder lPropStr = new StringBuilder(); Enumeration lPropNames = lMsg.getPropertyNames(); while (lPropNames.hasMoreElements()) { String lPropName = (String) lPropNames.nextElement(); Object lValue = lMsg.getObjectProperty(lPropName); lPropStr.append(lPropName).append("=").append(lValue); if (lPropNames.hasMoreElements()) { lPropStr.append(", "); } } mLog.debug("Sending text to '" + aTargetId + "': " + (JMSLogging.isFullTextLogging() ? aText : "[content suppressed, length: " + aText.length() + " bytes]") + ", props: " + lPropStr + "..."); } // processing callbacks if (null != aResponseListener) { Assert.notNull(aCorrelationID, "The 'correlationID' argument cannot be null!"); Assert.isTrue(aTimeout > 0, "Invalid 'timeout' argument. Expecting 'timeout' > 0"); // setting the expiration time lMsg.setJMSExpiration(aTimeout); // saving the callback mResponseListeners.put(aCorrelationID, aResponseListener); // schedule the timer task Tools.getTimer().schedule(new JWSTimerTask() { @Override public void runTask() { Thread lThread = new Thread() { @Override public void run() { IJMSResponseListener lListener = mResponseListeners.remove(aCorrelationID); if (null != lListener) { lListener.onTimeout(); } } }; lThread.setName("JMSEndPointSender Timeout Thread"); Tools.getThreadPool().submit(lThread); } }, aTimeout); } mProducer.send(lMsg); } catch (JMSException lEx) { mLog.error(lEx.getClass().getSimpleName() + " sending message: " + lEx.getMessage() + " " + ExceptionUtils.getStackTrace(lEx)); } }
From source file:org.springframework.flex.messaging.jms.FlexMessageConverter.java
/** * //from w w w . j av a 2s.co m * {@inheritDoc} */ public Object fromMessage(Message message) throws JMSException, MessageConversionException { Object messageBody = this.targetConverter.fromMessage(message); AsyncMessage flexMessage = new AsyncMessage(); flexMessage.setBody(messageBody); flexMessage.setMessageId(message.getJMSMessageID()); flexMessage.setClientId(message.getObjectProperty(FLEX_CLIENT_ID)); flexMessage.setTimestamp(message.getJMSTimestamp()); Object timeToLive = message.getObjectProperty(FLEX_TIME_TO_LIVE); if (timeToLive != null && long.class.isAssignableFrom(timeToLive.getClass())) { flexMessage.setTimeToLive(Long.parseLong(timeToLive.toString())); } Enumeration<?> propertyNames = message.getPropertyNames(); while (propertyNames.hasMoreElements()) { String name = (String) propertyNames.nextElement(); if (!name.startsWith(HEADER_PREFIX)) { flexMessage.setHeader(name, message.getObjectProperty(name)); } } return flexMessage; }
From source file:org.wso2.carbon.andes.event.core.internal.delivery.jms.JMSMessageListener.java
/** * Fire when message receive and send notification to carbon notification manager * * @param message message// ww w . jav a 2 s.c o m */ public void onMessage(Message message) { try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(this.subscription.getTenantId()); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(this.subscription.getOwner()); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; org.wso2.carbon.andes.event.core.Message messageToSend = new org.wso2.carbon.andes.event.core.Message(); messageToSend.setMessage(textMessage.getText()); // set the properties Enumeration propertyNames = message.getPropertyNames(); String key = null; while (propertyNames.hasMoreElements()) { key = (String) propertyNames.nextElement(); messageToSend.addProperty(key, message.getStringProperty(key)); } this.notificationManager.sendNotification(messageToSend, this.subscription); } else { log.warn("Non text message received"); } } catch (JMSException e) { log.error("Can not read the text message ", e); } catch (EventBrokerException e) { log.error("Can not send the notification ", e); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java
private void process(String jobname, Message message) { try {// www . j a va2 s . c o m Map<String, String> params = new HashMap<String, String>(); params.put("CI_MESSAGE", getMessageBody(message)); @SuppressWarnings("unchecked") Enumeration<String> e = message.getPropertyNames(); while (e.hasMoreElements()) { String s = e.nextElement(); if (message.getStringProperty(s) != null) { params.put(s, message.getObjectProperty(s).toString()); } } super.trigger(jobname, formatMessage(message), params); } catch (Exception e) { log.log(Level.SEVERE, "Unhandled exception processing message:\n" + formatMessage(message), e); } }
From source file:org.wso2.carbon.event.core.internal.delivery.jms.JMSMessageListener.java
public void onMessage(Message message) { try {//from w ww . j av a 2 s . c om PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(this.subscription.getTenantId()); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(this.subscription.getOwner()); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; StAXOMBuilder stAXOMBuilder = new StAXOMBuilder( new ByteArrayInputStream(textMessage.getText().getBytes())); org.wso2.carbon.event.core.Message messageToSend = new org.wso2.carbon.event.core.Message(); messageToSend.setMessage(stAXOMBuilder.getDocumentElement()); // set the properties Enumeration propertyNames = message.getPropertyNames(); String key = null; while (propertyNames.hasMoreElements()) { key = (String) propertyNames.nextElement(); messageToSend.addProperty(key, message.getStringProperty(key)); } this.notificationManager.sendNotification(messageToSend, this.subscription); } else { log.warn("Non text message received"); } } catch (JMSException e) { log.error("Can not read the text message ", e); } catch (XMLStreamException e) { log.error("Can not build the xml string", e); } catch (EventBrokerException e) { log.error("Can not send the notification ", e); } finally { PrivilegedCarbonContext.endTenantFlow(); } }