List of usage examples for javax.jms Message getStringProperty
String getStringProperty(String name) 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 {//from ww w . j a va2 s. c om 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.hcatalog.messaging.jms.MessagingUtils.java
/** * Method to return HCatEventMessage contained in the JMS message. * @param message The JMS Message instance * @return The contained HCatEventMessage */// w w w. ja va2s . com public static HCatEventMessage getMessage(Message message) { try { String messageBody = ((TextMessage) message).getText(); String eventType = message.getStringProperty(HCatConstants.HCAT_EVENT); String messageVersion = message.getStringProperty(HCatConstants.HCAT_MESSAGE_VERSION); String messageFormat = message.getStringProperty(HCatConstants.HCAT_MESSAGE_FORMAT); if (StringUtils.isEmpty(messageBody) || StringUtils.isEmpty(eventType)) throw new IllegalArgumentException( "Could not extract HCatEventMessage. " + "EventType and/or MessageBody is null/empty."); return MessageFactory.getDeserializer(messageFormat, messageVersion).getHCatEventMessage(eventType, messageBody); } catch (JMSException exception) { throw new IllegalArgumentException("Could not extract HCatEventMessage. ", exception); } }
From source file:org.apache.james.queue.jms.JMSMailQueue.java
/** * Populate Mail with values from Message. This exclude the * {@link MimeMessage}//w w w . j av a 2 s . c om * * @param message * @param mail * @throws JMSException */ protected void populateMail(Message message, MailImpl mail) throws JMSException { mail.setErrorMessage(message.getStringProperty(JAMES_MAIL_ERROR_MESSAGE)); mail.setLastUpdated(new Date(message.getLongProperty(JAMES_MAIL_LAST_UPDATED))); mail.setName(message.getStringProperty(JAMES_MAIL_NAME)); Optional.ofNullable(SerializationUtil .<PerRecipientHeaders>deserialize(message.getStringProperty(JAMES_MAIL_PER_RECIPIENT_HEADERS))) .ifPresent(mail::addAllSpecificHeaderForRecipient); List<MailAddress> rcpts = new ArrayList<>(); String recipients = message.getStringProperty(JAMES_MAIL_RECIPIENTS); StringTokenizer recipientTokenizer = new StringTokenizer(recipients, JAMES_MAIL_SEPARATOR); while (recipientTokenizer.hasMoreTokens()) { String token = recipientTokenizer.nextToken(); try { MailAddress rcpt = new MailAddress(token); rcpts.add(rcpt); } catch (AddressException e) { // Should never happen as long as the user does not modify the // the header by himself LOGGER.error("Unable to parse the recipient address {} for mail {}, so we ignore it", token, mail.getName(), e); } } mail.setRecipients(rcpts); mail.setRemoteAddr(message.getStringProperty(JAMES_MAIL_REMOTEADDR)); mail.setRemoteHost(message.getStringProperty(JAMES_MAIL_REMOTEHOST)); String attributeNames = message.getStringProperty(JAMES_MAIL_ATTRIBUTE_NAMES); splitter.split(attributeNames).forEach(name -> setMailAttribute(message, mail, name)); MaybeSender.getMailSender(message.getStringProperty(JAMES_MAIL_SENDER)).asOptional() .ifPresent(mail::setSender); mail.setState(message.getStringProperty(JAMES_MAIL_STATE)); }
From source file:org.apache.stratos.manager.listener.InstanceStatusListener.java
@Override public void onMessage(Message message) { TextMessage receivedMessage = (TextMessage) message; if (log.isInfoEnabled()) { log.info("Instance status message received"); }// w w w . j a va 2 s. c o m try { String type = message.getStringProperty(Constants.EVENT_CLASS_NAME); if (log.isInfoEnabled()) { log.info(String.format("Event class name: %s ", type)); } // If member started event is received publish artifact update message // To do a git clone if (InstanceStartedEvent.class.getName().equals(type)) { String json = receivedMessage.getText(); InstanceStartedEvent event = (InstanceStartedEvent) Util.jsonToObject(json, InstanceStartedEvent.class); String clusterId = event.getClusterId(); if (log.isInfoEnabled()) { log.info("Cluster id: " + clusterId); } Set<CartridgeSubscription> cartridgeSubscriptions = new DataInsertionAndRetrievalManager() .getCartridgeSubscriptionForCluster(clusterId); if (cartridgeSubscriptions == null || cartridgeSubscriptions.isEmpty()) { // No subscriptions, return if (log.isDebugEnabled()) { log.debug("No subscription information found for cluster id " + clusterId); } return; } for (CartridgeSubscription cartridgeSubscription : cartridgeSubscriptions) { // We need to send this event for all types, single tenant and multi tenant. // In an autoscaling scenario, we need to send this event for all existing subscriptions for the newly spawned instance // Also in a case of restarting the agent, this event needs to be sent for all subscriptions for the existing instance if (cartridgeSubscription.getRepository() != null) { InstanceNotificationPublisher publisher = new InstanceNotificationPublisher(); publisher.sendArtifactUpdateEvent(cartridgeSubscription.getRepository(), clusterId, String.valueOf(cartridgeSubscription.getSubscriber().getTenantId())); } else { if (log.isDebugEnabled()) { log.debug("No repository found for subscription with alias: " + cartridgeSubscription.getAlias() + ", type: " + cartridgeSubscription.getType() + ". Not sending the Artifact Updated event"); } } } } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Could not process instance status message", e); } } }
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//from www.j a va 2s. c o 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.exist.replication.jms.obsolete.FileSystemListener.java
@Override public void onMessage(Message message) { try {/*from w w w. j av 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.fcrepo.indexer.IndexerGroup.java
/** * Handle a JMS message representing an object update or deletion event. **//* ww w.j a v a 2s .co m*/ @Override public void onMessage(final Message message) { try { LOGGER.debug("Received message: {}", message.getJMSMessageID()); } catch (final JMSException e) { LOGGER.error("Received unintelligible message: {}", e); propagate(e); } try { // get id and eventType from message final String eventType = message.getStringProperty(EVENT_TYPE_HEADER_NAME); final String id = message.getStringProperty(IDENTIFIER_HEADER_NAME); String baseURL = message.getStringProperty(BASE_URL_HEADER_NAME); LOGGER.debug("Discovered id: {} in message.", id); LOGGER.debug("Discovered event type: {} in message.", eventType); LOGGER.debug("Discovered baseURL: {} in message.", baseURL); LOGGER.debug("Discovered properties: {} in message.", message.getStringProperty(PROPERTIES_HEADER_NAME)); // Trim trailing '/' while (!Strings.isNullOrEmpty(baseURL) && baseURL.endsWith("/")) { baseURL = baseURL.substring(0, baseURL.length() - 1); } index(new URI(baseURL + id), eventType); } catch (final URISyntaxException e) { LOGGER.error("Error creating URI", e); } catch (final JMSException e) { LOGGER.error("Error processing JMS event!", e); } }
From source file:org.fcrepo.jms.headers.DefaultMessageFactoryTest.java
@Test public void testBuildMessage() throws RepositoryException, JMSException { final String testPath = "/path/to/resource"; final String userAgent = "Test UserAgent (Like Mozilla)"; final Message msg = doTestBuildMessage("base-url", "Test UserAgent", testPath); assertEquals("Got wrong identifier in message!", testPath, msg.getStringProperty(IDENTIFIER_HEADER_NAME)); }
From source file:org.fcrepo.jms.headers.DefaultMessageFactoryTest.java
@Test public void testBuildMessageNullUrl() throws RepositoryException, JMSException { final String testPath = "/path/to/resource"; final Message msg = doTestBuildMessage(null, null, testPath); assertEquals("Got wrong identifier in message!", testPath, msg.getStringProperty(IDENTIFIER_HEADER_NAME)); }
From source file:org.fcrepo.jms.headers.DefaultMessageFactoryTest.java
@Test public void testBuildMessageContent() throws RepositoryException, JMSException { final String testPath = "/path/to/resource"; final Message msg = doTestBuildMessage("base-url/", "Test UserAgent", testPath + "/" + JCR_CONTENT); assertEquals("Got wrong identifier in message!", testPath, msg.getStringProperty(IDENTIFIER_HEADER_NAME)); }