List of usage examples for javax.jms Message getStringProperty
String getStringProperty(String name) throws JMSException;
From source file:nl.knaw.huygens.timbuctoo.messages.Action.java
public static Action fromMessage(Message message, TypeRegistry typeRegistry) throws JMSException { ActionType actionType = getActionType(message); String requestId = message.getStringProperty(PROP_REQUEST_ID); boolean forMultiEntities = message.getBooleanProperty(PROP_FOR_MULTI_ENTITIES); String typeString = message.getStringProperty(PROP_ENTITY_TYPE); Class<? extends DomainEntity> type = typeRegistry.getDomainEntityType(typeString); if (forMultiEntities) { return forMultiEntities(actionType, type); }//w w w . j a va 2 s . com String id = message.getStringProperty(PROP_ENTITY_ID); return new Action(actionType, type, id); }
From source file:nl.knaw.huygens.timbuctoo.messages.Action.java
private static ActionType getActionType(Message message) throws JMSException { String actionString = message.getStringProperty(PROP_ACTION); return ActionType.getFromString(actionString); }
From source file:org.ala.jms.service.JmsMessageListener.java
public Method getMethod(Message message) { try {/*from w w w .ja v a2s .co m*/ logger.debug("Message type: " + message.getClass().getName() + ", TextMessage: " + (message instanceof TextMessage)); if (message.getStringProperty(MESSAGE_METHOD) != null && !"".equals(message.getStringProperty(MESSAGE_METHOD))) { return Method.valueOf(message.getStringProperty(MESSAGE_METHOD)); } if (message instanceof TextMessage) { //parse the message TextMessage tm = (TextMessage) message; String json = tm.getText(); if (StringUtils.isNotEmpty(json)) { Map<String, Object> omap = mapper.readValue(json, new TypeReference<HashMap<String, Object>>() { }); String messageMethod = (String) omap.get("messageMethod"); if (StringUtils.isNotEmpty(messageMethod)) { return Method.valueOf(messageMethod); } } } } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage(), e); } return null; }
From source file:org.ala.jms.service.JmsMessageListener.java
/** * Implementation of <code>MessageListener</code>. * * JSON Message:/*from w w w.j av a 2 s. co m*/ * ============== * { * "guid" : "urn:lsid:cs.ala.org.au:Record:51", * "dataResourceUid" : "dr364", * "scientificName" : "Trichoglossus haematodus eyrei", * "vernacularName" : "Rainbow Lorikeet", * "locality" : "Emmet Yaraka Rd, Isisford QLD 4731, Australia", * "decimalLatitude" : "-24.729292", * "decimalLongitude" : "144.234375", * "individualCount" : "345", * "coordinateUncertaintyInMeters" : "222.0", * "occurrenceRemarks" : "rwe", * "eventDate" : "2011-07-11", * "eventTime" : "13:50:00EST", * "taxonID" : "urn:lsid:biodiversity.org.au:afd.taxon:13a00712-95cb-475b-88a5-f1c7917e10e3", * "family" : "Psittacidae", * "kingdom" : "Animalia", * "associatedMedia" : ["http://cs.ala.org.au/bdrs-ala/files/download.htm?className=au.com.gaiaresources.bdrs.model.taxa.AttributeValue&id=63&fileName=Argentina.gif"] * } */ public void onMessage(Message message) { String occId = ""; String json = ""; Method messageMethod = getMethod(message); logger.info("Message received from the queue..." + messageMethod); logger.debug(message.toString()); try { if (messageMethod != null) { Map<String, String> map = new java.util.HashMap<String, String>(); if (message instanceof TextMessage) { lastMessage = System.currentTimeMillis(); // prepare data TextMessage tm = (TextMessage) message; json = tm.getText(); if (json != null && !"".equals(json)) { logger.debug("creating map : " + json); try { Map<String, Object> omap = mapper.readValue(json, new TypeReference<HashMap<String, Object>>() { }); for (String key : omap.keySet()) { Object value = omap.get(key); if ("associatedMedia".equalsIgnoreCase(key)) { if (hasAssociatedMedia && value != null) { String newValue = org.apache.commons.lang.StringUtils.join((List) value, ";"); map.put("associatedMedia", newValue); } } // else if("userID".equalsIgnoreCase(key)){ // if(value != null) // map.put("recordedBy", value.toString()); // } else if ("guid".equalsIgnoreCase(key)) { if (value != null) map.put("occurrenceID", value.toString()); } else if (value != null) { map.put(key, omap.get(key).toString()); } } } catch (Exception e) { logger.error(e.getMessage(), e); } catch (Throwable e) { e.printStackTrace(); logger.error(e.getMessage(), e); } logger.debug("finished creating map " + map); } else { logger.error("Empty Json Message! Method: " + message.getStringProperty(MESSAGE_METHOD)); return; } if (map.get(TEST_MESSAGE) != null) { //log it and return. logger.info("Test message received. Will not proceed with commit to biocache"); return; } //remove transport info from payload if supplied map.remove("messageMethod"); //process request switch (messageMethod) { case CREATE: createOrUpdate(map); break; case UPDATE: createOrUpdate(map); break; case DELETE: if (map != null) { //TODO deletes for when the data resource UID is supplied occId = getDefaultDataResourceUid() + "|" + map.get("occurrenceID"); logger.info("Delete request received for ID: " + occId); synchronized (deleteList) { deleteList.add(occId); } } break; default: logger.error("Invalid method! Method: " + message.getStringProperty(MESSAGE_METHOD) + ". json= " + json); break; } logger.debug("Method = " + messageMethod + " : Processed message " + json); } } else { logger.error("Invalid method! Method: " + messageMethod); } } catch (Exception e) { logger.error("Error processing message: " + json + " Method :" + messageMethod); logger.error(e.getMessage(), e); } }
From source file:org.apache.activemq.usecases.RequestReplyToTopicViaThreeNetworkHopsTest.java
public static String fmtMsgInfo(Message msg) throws Exception { StringBuilder msg_desc;/* w ww. j a v a 2 s .c om*/ 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.apache.axis2.transport.jms.JMSUtils.java
/** * Get a String property from the JMS message * * @param message JMS message//from w ww . j ava 2 s. c om * @param property property name * @return property value */ public static String getProperty(Message message, String property) { try { return message.getStringProperty(property); } catch (JMSException e) { return null; } }
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//from ww w .j av a 2 s . c om * @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; }
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 w ww. j a v a 2 s . com 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.apache.axis2.transport.jms.MockEchoEndpoint.java
@Setup @SuppressWarnings("unused") private void setUp(JMSTestEnvironment env, JMSRequestResponseChannel channel) throws Exception { Destination destination = channel.getDestination(); Destination replyDestination = channel.getReplyDestination(); connection = env.getConnectionFactory().createConnection(); connection.setExceptionListener(this); connection.start();//from w w w . j a v a 2s .co m replyConnection = env.getConnectionFactory().createConnection(); replyConnection.setExceptionListener(this); final Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); final MessageProducer producer = replySession.createProducer(replyDestination); MessageConsumer consumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE) .createConsumer(destination); consumer.setMessageListener(new MessageListener() { public void onMessage(Message message) { try { log.info("Message received: ID = " + message.getJMSMessageID()); Message reply; if (message instanceof BytesMessage) { reply = replySession.createBytesMessage(); IOUtils.copy(new BytesMessageInputStream((BytesMessage) message), new BytesMessageOutputStream((BytesMessage) reply)); } else if (message instanceof TextMessage) { reply = replySession.createTextMessage(); ((TextMessage) reply).setText(((TextMessage) message).getText()); } else { // TODO throw new UnsupportedOperationException("Unsupported message type"); } reply.setJMSCorrelationID(message.getJMSMessageID()); reply.setStringProperty(BaseConstants.CONTENT_TYPE, message.getStringProperty(BaseConstants.CONTENT_TYPE)); producer.send(reply); log.info("Message sent: ID = " + reply.getJMSMessageID()); } catch (Throwable ex) { fireEndpointError(ex); } } }); }
From source file:org.apache.cactus.internal.server.MessageDrivenBeanTestController.java
/** * @param theRequest the JMS message/*from w w w. jav a 2s . c om*/ * @return the service name of the service to call (there are 2 services * "do test" and "get results"), extracted from the JMS message * @exception JMSException if the service to execute is missing from * the JMS message */ private String getServiceName(Message theRequest) throws JMSException { // Call the correct Service method String serviceName = theRequest.getStringProperty(HttpServiceDefinition.SERVICE_NAME_PARAM); //String serviceName = ServletUtil.getQueryStringParameter(queueName, // HttpServiceDefinition.SERVICE_NAME_PARAM); if (serviceName == null) { String message = "Missing service name parameter [" + HttpServiceDefinition.SERVICE_NAME_PARAM + "] in HTTP request. Received query string is [" + serviceName + "]."; LOGGER.debug(message); throw new JMSException(message); } LOGGER.debug("Service to call = " + serviceName); return serviceName; }