List of usage examples for javax.jms Message getStringProperty
String getStringProperty(String name) throws JMSException;
From source file:gov.nih.nci.cabig.caaers.esb.client.impl.CtmsCaaersMessageConsumer.java
/** * This is the Callback method which gets invoked whenever there is a message on the InputQueue. * Once it receives a message this method delegates the processing to different methods. *//* w w w . j a va2 s .c o m*/ public void onMessage(Message message) { String identity = SecurityManager.getManager().getCaller(); if (identity == null) { identity = "ctms-caaers.inputQueue"; } logger.debug("Auditing request from " + identity); String info = null; info = configuration.get(Configuration.ESB_URL); gov.nih.nci.cabig.ctms.audit.domain.DataAuditInfo .setLocal(new DataAuditInfo(identity, info, new Date(), info)); try { if (message instanceof TextMessage) { String messageType = message.getStringProperty("MESSAGE_TYPE"); String jmsCorelationID = message.getJMSCorrelationID(); String responseXml = ""; StringBuffer sb = new StringBuffer(); boolean messageValid = false; logger.debug("JMSCorelationID=" + jmsCorelationID); logger.debug("MESSAGE_TYPE=" + messageType); //Step 1 messageValid = validateMessage(message, messageType, sb); //Step 2 if (messageValid) { responseXml = processMessage(message, messageType); } else { CaaersServiceResponse caaersResponse = Helper.createResponse(); caaersResponse.getServiceResponse().setResponsecode("1"); Helper.populateError(caaersResponse, "WS_GEN_001", messageSource.getMessage("WS_GEN_001", new String[] {}, "", Locale.getDefault())); jaxbContext = JAXBContext.newInstance("gov.nih.nci.cabig.caaers.integration.schema.common"); marshaller = jaxbContext.createMarshaller(); responseXml = responseAsString(caaersResponse, marshaller); } //Step 3 sendResponse(responseXml, jmsCorelationID, messageType); } } catch (JMSException je) { logger.error("onMessage caught ", je); } catch (JAXBException e) { logger.error("onMessage caught ", e); } }
From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java
private void process(String jobname, Message message) { try {//from w w w .ja v a 2 s . co 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:it.geosolutions.geoserver.jms.client.JMSQueueListener.java
@Override public void onMessage(Message message, Session session) throws JMSException { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message event for session: " + session.toString()); }//from w ww . j av a 2s .co m // CHECKING LISTENER STATUS if (!isEnabled()) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message is swallowed since this component is disabled"); } return; } // FILTERING INCOMING MESSAGE if (!message.propertyExists(JMSConfiguration.INSTANCE_NAME_KEY)) { throw new JMSException("Unable to handle incoming message, property \'" + JMSConfiguration.INSTANCE_NAME_KEY + "\' not set."); } // FILTERING INCOMING MESSAGE if (!message.propertyExists(JMSConfiguration.GROUP_KEY)) { throw new JMSException( "Unable to handle incoming message, property \'" + JMSConfiguration.GROUP_KEY + "\' not set."); } // check if message comes from a master with the same name of this slave if (message.getStringProperty(JMSConfiguration.INSTANCE_NAME_KEY) .equals(config.getConfiguration(JMSConfiguration.INSTANCE_NAME_KEY))) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message discarded: source is equal to destination"); } // if so discard the message return; } // check if message comes from a different group final String group = message.getStringProperty(JMSConfiguration.GROUP_KEY); final String localGroup = config.getConfiguration(JMSConfiguration.GROUP_KEY); if (!group.equals(localGroup)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message discarded: incoming group-->" + group + " is different from the local one-->" + localGroup); } // if so discard the message return; } // check the property which define the SPI used (to serialize on the // server side). if (!message.propertyExists(JMSEventHandlerSPI.getKeyName())) throw new JMSException("Unable to handle incoming message, property \'" + JMSEventHandlerSPI.getKeyName() + "\' not set."); // END -> FILTERING INCOMING MESSAGE // get the name of the SPI used to serialize the message final String generatorClass = message.getStringProperty(JMSEventHandlerSPI.getKeyName()); if (generatorClass == null || generatorClass.isEmpty()) { throw new IllegalArgumentException("Unable to handle a message without a generator class name"); } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine( "Incoming message was serialized using an handler generated by: \'" + generatorClass + "\'"); } // USING INCOMING MESSAGE if (message instanceof ObjectMessage) { final ObjectMessage objMessage = (ObjectMessage) (message); final Serializable obj = objMessage.getObject(); try { // lookup the SPI handler, search is performed using the // name final JMSEventHandler<Serializable, Object> handler = jmsManager .getHandlerByClassName(generatorClass); if (handler == null) { throw new JMSException("Unable to find SPI named \'" + generatorClass + "\', be shure to load that SPI into your context."); } final Enumeration<String> keys = message.getPropertyNames(); final Properties options = new Properties(); while (keys.hasMoreElements()) { String key = keys.nextElement(); options.put(key, message.getObjectProperty(key)); } handler.setProperties(options); // try to synchronize object locally if (!handler.synchronize(handler.deserialize(obj))) { throw new JMSException("Unable to synchronize message locally.\n SPI: " + generatorClass); } } catch (Exception e) { final JMSException jmsE = new JMSException(e.getLocalizedMessage()); jmsE.initCause(e); throw jmsE; } } else throw new JMSException("Unrecognized message type for catalog incoming event"); }
From source file:com.jmstoolkit.beans.MessageTableModel.java
/** * * @param message/*from w w w . ja va 2 s . c o 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:net.timewalker.ffmq4.admin.RemoteAdministrationThread.java
private String process(Message msg) { try {//w w w . ja v a2s . c om String command = msg.getStringProperty(FFMQAdminConstants.ADM_HEADER_COMMAND); if (StringTools.isEmpty(command)) return "Administration command not set in message header"; // Dispatch if (command.equals(FFMQAdminConstants.ADM_COMMAND_CREATE_QUEUE)) return processCreateQueue(msg); if (command.equals(FFMQAdminConstants.ADM_COMMAND_CREATE_TOPIC)) return processCreateTopic(msg); if (command.equals(FFMQAdminConstants.ADM_COMMAND_DELETE_QUEUE)) return processDeleteQueue(msg); if (command.equals(FFMQAdminConstants.ADM_COMMAND_DELETE_TOPIC)) return processDeleteTopic(msg); if (command.equals(FFMQAdminConstants.ADM_COMMAND_PURGE_QUEUE)) return processPurgeQueue(msg); if (command.equals(FFMQAdminConstants.ADM_COMMAND_SHUTDOWN)) return processShutdown(); log.error("Invalid administration command : " + command); return "Invalid administration command : " + command; } catch (JMSException e) { ErrorTools.log(e, log); return "Error processing administration command : " + e.getMessage(); } catch (Exception e) { ErrorTools.log(new FFMQException("Cannot process admin message", "INVALID_ADMIN_MESSAGE", e), log); return "Error processing administration command : " + e.getMessage(); } }
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 .ja v a 2s.c o m*/ return queueSettings; }
From source file:net.timewalker.ffmq4.admin.RemoteAdministrationThread.java
private String processDeleteQueue(Message msg) throws JMSException { String destName = msg.getStringProperty("name"); if (StringTools.isEmpty(destName)) return "Destination name not specified"; if (!engine.localQueueExists(destName)) return "Queue " + destName + " does not exist"; engine.deleteQueue(destName);/*from w w w . ja v a2s. co m*/ return null; }
From source file:net.timewalker.ffmq4.admin.RemoteAdministrationThread.java
private String processDeleteTopic(Message msg) throws JMSException { String destName = msg.getStringProperty("name"); if (StringTools.isEmpty(destName)) return "Destination name not specified"; if (!engine.localTopicExists(destName)) return "Topic " + destName + " does not exist"; engine.deleteTopic(destName);//from w w w. j av a2 s . co m return null; }
From source file:net.timewalker.ffmq4.admin.RemoteAdministrationThread.java
private String processPurgeQueue(Message msg) throws JMSException { String destName = msg.getStringProperty("name"); if (StringTools.isEmpty(destName)) return "Destination name not specified"; if (!engine.localQueueExists(destName)) return "Queue " + destName + " does not exist"; LocalQueue queue = engine.getLocalQueue(destName); queue.purge(null);//from ww w.j a v a 2 s.c o m return null; }