List of usage examples for javax.jms Message getLongProperty
long getLongProperty(String name) throws JMSException;
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 w w w. j av a 2s . co 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.fcrepo.jms.headers.DefaultMessageFactoryTest.java
private Message doTestBuildMessage(final String baseUrl, final String userAgent, final String id) throws RepositoryException, JMSException { final Long testDate = 46647758568747L; when(mockEvent.getDate()).thenReturn(testDate); String url = null;/*from w w w .j ava2s . c om*/ if (!StringUtils.isBlank(baseUrl) || !StringUtils.isBlank(userAgent)) { url = "{\"baseURL\":\"" + baseUrl + "\",\"userAgent\":\"" + userAgent + "\"}"; } when(mockEvent.getUserData()).thenReturn(url); final String testUser = "testUser"; when(mockEvent.getUserID()).thenReturn(testUser); when(mockEvent.getPath()).thenReturn(id); final Set<Integer> testTypes = singleton(NODE_ADDED); final String testReturnType = REPOSITORY_NAMESPACE + EventType.valueOf(NODE_ADDED).toString(); when(mockEvent.getTypes()).thenReturn(testTypes); final String prop = "test-property"; when(mockEvent.getProperties()).thenReturn(singleton(prop)); final String eventID = "abcdefg12345678"; when(mockEvent.getEventID()).thenReturn(eventID); final Message msg = testDefaultMessageFactory.getMessage(mockEvent, mockSession); String trimmedBaseUrl = baseUrl; while (!StringUtils.isBlank(trimmedBaseUrl) && trimmedBaseUrl.endsWith("/")) { trimmedBaseUrl = trimmedBaseUrl.substring(0, trimmedBaseUrl.length() - 1); } assertEquals("Got wrong date in message!", testDate, (Long) msg.getLongProperty(TIMESTAMP_HEADER_NAME)); assertEquals("Got wrong type in message!", testReturnType, msg.getStringProperty(EVENT_TYPE_HEADER_NAME)); assertEquals("Got wrong base-url in message", trimmedBaseUrl, msg.getStringProperty(BASE_URL_HEADER_NAME)); assertEquals("Got wrong property in message", prop, msg.getStringProperty(PROPERTIES_HEADER_NAME)); assertEquals("Got wrong userID in message", testUser, msg.getStringProperty(USER_HEADER_NAME)); assertEquals("Got wrong userAgent in message", userAgent, msg.getStringProperty(USER_AGENT_HEADER_NAME)); assertEquals("Got wrong eventID in message", eventID, msg.getStringProperty(EVENT_ID_HEADER_NAME)); return msg; }
From source file:org.openanzo.client.RealtimeUpdateManager.java
protected void handleTransactionMessage(Message message) throws AnzoException { // Extract method and transactionId. String transactionContextString = null; try {/* ww w.j ava 2 s .c om*/ transactionContextString = message.propertyExists(SerializationConstants.transactionContext) ? message.getStringProperty(SerializationConstants.transactionContext) : null; } catch (JMSException e) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, e); } String updatedNamedGraphs = null; try { updatedNamedGraphs = message.propertyExists(SerializationConstants.namedGraphUpdates) ? message.getStringProperty(SerializationConstants.namedGraphUpdates) : null; } catch (JMSException e) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, e); } long timestamp = -1; try { timestamp = Long.valueOf(message.getLongProperty(SerializationConstants.transactionTimestamp)); } catch (JMSException e) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, e); } String transactionUri = null; try { transactionUri = message.propertyExists(SerializationConstants.transactionURI) ? message.getStringProperty(SerializationConstants.transactionURI) : null; } catch (JMSException e) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, e); } URI transactionURI = (transactionUri != null) ? MemURI.create(transactionUri) : null; transactionLock.writeLock().lock(); try { Collection<Statement> context = null; if (transactionContextString != null) { context = ReadWriteUtils.readStatements(transactionContextString, RDFFormat.JSON); } Map<URI, Long> updatedGraphs = null; if (updatedNamedGraphs != null) { updatedGraphs = CommonSerializationUtils.readNamedGraphRevisions(updatedNamedGraphs); } UpdateTransaction transaction = new UpdateTransaction(transactionURI, timestamp, context, updatedGraphs); notifyTransactionListeners(transaction); } finally { transactionLock.writeLock().unlock(); } }
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 ww . ja v a 2 s. co m*/ * @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; }