List of usage examples for javax.jms Message setLongProperty
void setLongProperty(String name, long value) throws JMSException;
From source file:org.apache.qpid.disttest.client.MessageProvider.java
protected void setCustomProperty(Message message, String propertyName, Object propertyValue) throws JMSException { if (propertyValue instanceof Integer) { message.setIntProperty(propertyName, ((Integer) propertyValue).intValue()); } else if (propertyValue instanceof Long) { message.setLongProperty(propertyName, ((Long) propertyValue).longValue()); } else if (propertyValue instanceof Boolean) { message.setBooleanProperty(propertyName, ((Boolean) propertyValue).booleanValue()); } else if (propertyValue instanceof Byte) { message.setByteProperty(propertyName, ((Byte) propertyValue).byteValue()); } else if (propertyValue instanceof Double) { message.setDoubleProperty(propertyName, ((Double) propertyValue).doubleValue()); } else if (propertyValue instanceof Float) { message.setFloatProperty(propertyName, ((Float) propertyValue).floatValue()); } else if (propertyValue instanceof Short) { message.setShortProperty(propertyName, ((Short) propertyValue).shortValue()); } else if (propertyValue instanceof String) { message.setStringProperty(propertyName, (String) propertyValue); } else {//from w w w.j av a2s . com message.setObjectProperty(propertyName, propertyValue); } }
From source file:org.apache.synapse.message.store.impl.jms.JmsProducer.java
private void setJmsMessageProperties(Message message, MessageContext synCtx) { Set<String> properties = synCtx.getPropertyKeySet(); for (String prop : properties) { if (prop.startsWith(JMS_MSG_P)) { Object value = synCtx.getProperty(prop); String key = prop.substring(JMS_MSG_P.length()); try { if (value instanceof String) { message.setStringProperty(key, (String) value); } else if (value instanceof Long) { message.setLongProperty(key, (Long) value); } else if (value instanceof Integer) { message.setIntProperty(key, (Integer) value); } else if (value instanceof Boolean) { message.setBooleanProperty(key, (Boolean) value); } else if (value instanceof Double) { message.setDoubleProperty(key, (Double) value); } else if (value instanceof Float) { message.setFloatProperty(key, (Float) value); } else if (value instanceof Short) { message.setShortProperty(key, (Short) value); }// w ww . ja va 2 s . co m } catch (JMSException e) { if (logger.isDebugEnabled()) { logger.debug("Could not save Message property: " + e.getLocalizedMessage()); } } } } }
From source file:org.apache.synapse.message.store.impl.jms.JmsProducer.java
private void setTransportHeaders(Message message, MessageContext synCtx) { //Set transport headers to the message Map<?, ?> headerMap = (Map<?, ?>) ((Axis2MessageContext) synCtx).getAxis2MessageContext() .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headerMap != null) { for (Object headerName : headerMap.keySet()) { String name = (String) headerName; Object value = headerMap.get(name); try { if (value instanceof String) { message.setStringProperty(name, (String) value); } else if (value instanceof Boolean) { message.setBooleanProperty(name, (Boolean) value); } else if (value instanceof Integer) { message.setIntProperty(name, (Integer) value); } else if (value instanceof Long) { message.setLongProperty(name, (Long) value); } else if (value instanceof Double) { message.setDoubleProperty(name, (Double) value); } else if (value instanceof Float) { message.setFloatProperty(name, (Float) value); }/* w w w . j a va 2 s .com*/ } catch (JMSException ex) { if (logger.isDebugEnabled()) { logger.debug("Could not save Message property: " + ex.getLocalizedMessage()); } } } } }
From source file:org.apache.synapse.transport.jms.JMSUtils.java
/** * Set transport headers from the axis message context, into the JMS message * * @param msgContext the axis message context * @param message the JMS Message// www . j av a 2 s .c om * @throws JMSException on exception */ public static void setTransportHeaders(MessageContext msgContext, Message message) throws JMSException { Map headerMap = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS); if (headerMap == null) { return; } Iterator iter = headerMap.keySet().iterator(); while (iter.hasNext()) { String name = (String) iter.next(); if (JMSConstants.JMS_COORELATION_ID.equals(name)) { message.setJMSCorrelationID((String) headerMap.get(JMSConstants.JMS_COORELATION_ID)); } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) { Object o = headerMap.get(JMSConstants.JMS_DELIVERY_MODE); if (o instanceof Integer) { message.setJMSDeliveryMode(((Integer) o).intValue()); } else if (o instanceof String) { try { message.setJMSDeliveryMode(Integer.parseInt((String) o)); } catch (NumberFormatException nfe) { log.warn("Invalid delivery mode ignored : " + o, nfe); } } else { log.warn("Invalid delivery mode ignored : " + o); } } else if (JMSConstants.JMS_EXPIRATION.equals(name)) { message.setJMSExpiration(Long.parseLong((String) headerMap.get(JMSConstants.JMS_EXPIRATION))); } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) { message.setJMSMessageID((String) headerMap.get(JMSConstants.JMS_MESSAGE_ID)); } else if (JMSConstants.JMS_PRIORITY.equals(name)) { message.setJMSPriority(Integer.parseInt((String) headerMap.get(JMSConstants.JMS_PRIORITY))); } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) { message.setJMSTimestamp(Long.parseLong((String) headerMap.get(JMSConstants.JMS_TIMESTAMP))); } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) { message.setJMSType((String) headerMap.get(JMSConstants.JMS_MESSAGE_TYPE)); } else { Object value = headerMap.get(name); if (value instanceof String) { message.setStringProperty(name, (String) value); } else if (value instanceof Boolean) { message.setBooleanProperty(name, ((Boolean) value).booleanValue()); } else if (value instanceof Integer) { message.setIntProperty(name, ((Integer) value).intValue()); } else if (value instanceof Long) { message.setLongProperty(name, ((Long) value).longValue()); } else if (value instanceof Double) { message.setDoubleProperty(name, ((Double) value).doubleValue()); } else if (value instanceof Float) { message.setFloatProperty(name, ((Float) value).floatValue()); } } } }
From source file:org.fcrepo.jms.headers.DefaultMessageFactory.java
@Override public Message getMessage(final FedoraEvent jcrEvent, final javax.jms.Session jmsSession) throws JMSException { final Message message = jmsSession.createMessage(); message.setLongProperty(TIMESTAMP_HEADER_NAME, jcrEvent.getDate()); String path = jcrEvent.getPath(); if (path.endsWith("/" + JCR_CONTENT)) { path = path.replaceAll("/" + JCR_CONTENT, ""); }//from w w w.ja v a 2 s . c o m // extract baseURL and userAgent from event UserData try { final String userdata = jcrEvent.getUserData(); if (!StringUtils.isBlank(userdata)) { final ObjectMapper mapper = new ObjectMapper(); final JsonNode json = mapper.readTree(userdata); String url = json.get("baseURL").asText(); while (url.endsWith("/")) { url = url.substring(0, url.length() - 1); } this.baseURL = url; this.userAgent = json.get("userAgent").asText(); LOGGER.debug("MessageFactory baseURL: {}, userAgent: {}", baseURL, userAgent); } else { LOGGER.warn("MessageFactory event UserData is empty!"); } } catch (final IOException ex) { LOGGER.warn("Error setting baseURL or userAgent", ex); } message.setStringProperty(IDENTIFIER_HEADER_NAME, path); message.setStringProperty(EVENT_TYPE_HEADER_NAME, getEventURIs(jcrEvent.getTypes())); message.setStringProperty(BASE_URL_HEADER_NAME, baseURL); message.setStringProperty(USER_HEADER_NAME, jcrEvent.getUserID()); message.setStringProperty(USER_AGENT_HEADER_NAME, userAgent); message.setStringProperty(PROPERTIES_HEADER_NAME, String.join(",", jcrEvent.getProperties())); message.setStringProperty(EVENT_ID_HEADER_NAME, jcrEvent.getEventID()); LOGGER.trace("getMessage() returning: {}", message); return message; }
From source file:org.jbpm.jms.JmsConnectorService.java
protected void populateMessage(Message message, Job job) throws JMSException { message.setLongProperty("jobId", job.getId()); if (job instanceof Timer) { Timer timer = (Timer) job; if (log.isDebugEnabled()) { log.debug("scheduling " + timer + " to execute at " + timer.getDueDate()); }/*from ww w . j a va2 s. c om*/ message.setLongProperty(SCHEDULED_DELIVERY_PROP, timer.getDueDate().getTime()); // raise timer priority message.setJMSPriority(9); } if (job.isExclusive()) { message.setStringProperty(GROUP_ID_PROP, GROUP_PREFIX + job.getProcessInstance().getId()); } }
From source file:org.openanzo.combus.realtime.RealtimeUpdatePublisher.java
private void setMessageProperties(Message message, Map<String, Object> properties) throws JMSException { // How can we do this more efficiently? for (Map.Entry<String, Object> entry : properties.entrySet()) { String name = entry.getKey(); Object value = entry.getValue(); if (value instanceof String) { message.setStringProperty(name, (String) value); } else if (value instanceof Integer) { message.setIntProperty(name, ((Integer) value).intValue()); } else if (value instanceof Long) { message.setLongProperty(name, ((Long) value).longValue()); } else if (value instanceof Float) { message.setFloatProperty(name, ((Float) value).floatValue()); } else if (value instanceof Double) { message.setDoubleProperty(name, ((Double) value).doubleValue()); } else if (value instanceof Short) { message.setShortProperty(name, ((Short) value).shortValue()); } else if (value instanceof Byte) { message.setByteProperty(name, ((Byte) value).byteValue()); } else if (value instanceof Boolean) { message.setBooleanProperty(name, ((Boolean) value).booleanValue()); }/*from w w w . j a va 2 s. c om*/ } }
From source file:org.springframework.flex.messaging.jms.FlexMessageConverter.java
/** * //from ww w. j a v a 2s .co m * {@inheritDoc} */ public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { Assert.state(object instanceof flex.messaging.messages.Message, "FlexMessageConverter can only handle Flex Messages"); flex.messaging.messages.Message flexMessage = (flex.messaging.messages.Message) object; Object messageBody = flexMessage.getBody(); Message jmsMessage = this.targetConverter.toMessage(messageBody, session); jmsMessage.setObjectProperty(FLEX_CLIENT_ID, flexMessage.getClientId()); jmsMessage.setLongProperty(FLEX_TIME_TO_LIVE, flexMessage.getTimeToLive()); Map<String, Object> headers = this.getFlexMessageHeaderMap(flexMessage); for (String key : headers.keySet()) { Object value = flexMessage.getHeader(key); try { jmsMessage.setObjectProperty(key, value); } catch (Exception e) { if (this.logger.isWarnEnabled()) { this.logger.warn("failed to copy Flex header '" + key + "'", e); } } } return jmsMessage; }
From source file:org.wso2.carbon.apimgt.jms.listener.utils.JMSUtils.java
/** * Set transport headers from the axis message context, into the JMS message * * @param messageConfiguration the adaptor message context * @param message the JMS Message * @throws JMSException on exception// w w w. j a v a 2s . c o m */ public static void setTransportHeaders(Map<String, String> messageConfiguration, Message message) throws JMSException { if (messageConfiguration == null) { return; } for (String name : messageConfiguration.keySet()) { if (name.startsWith(JMSConstants.JMSX_PREFIX) && !(name.equals(JMSConstants.JMSX_GROUP_ID) || name.equals(JMSConstants.JMSX_GROUP_SEQ))) { continue; } if (JMSConstants.JMS_COORELATION_ID.equals(name)) { message.setJMSCorrelationID(messageConfiguration.get(JMSConstants.JMS_COORELATION_ID)); } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) { String mode = messageConfiguration.get(JMSConstants.JMS_DELIVERY_MODE); try { message.setJMSDeliveryMode(Integer.parseInt(mode)); } catch (NumberFormatException nfe) { log.warn("Invalid delivery mode ignored : " + mode, nfe); } } else if (JMSConstants.JMS_EXPIRATION.equals(name)) { message.setJMSExpiration(Long.parseLong(messageConfiguration.get(JMSConstants.JMS_EXPIRATION))); } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) { message.setJMSMessageID(messageConfiguration.get(JMSConstants.JMS_MESSAGE_ID)); } else if (JMSConstants.JMS_PRIORITY.equals(name)) { message.setJMSPriority(Integer.parseInt(messageConfiguration.get(JMSConstants.JMS_PRIORITY))); } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) { message.setJMSTimestamp(Long.parseLong(messageConfiguration.get(JMSConstants.JMS_TIMESTAMP))); } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) { message.setJMSType(messageConfiguration.get(JMSConstants.JMS_MESSAGE_TYPE)); } else { //TODO currently only string is supported in messageConfiguration Object value = messageConfiguration.get(name); if (value instanceof String) { message.setStringProperty(name, (String) value); } else if (value instanceof Boolean) { message.setBooleanProperty(name, (Boolean) value); } else if (value instanceof Integer) { message.setIntProperty(name, (Integer) value); } else if (value instanceof Long) { message.setLongProperty(name, (Long) value); } else if (value instanceof Double) { message.setDoubleProperty(name, (Double) value); } else if (value instanceof Float) { message.setFloatProperty(name, (Float) value); } } } }
From source file:org.wso2.carbon.event.output.adapter.jms.internal.util.JMSUtils.java
/** * Set transport headers from the axis message context, into the JMS message * * @param messageConfiguration the adaptor message context * @param message the JMS Message * @throws javax.jms.JMSException on exception *//*w w w.j a v a2 s . c o m*/ public static Message setTransportHeaders(Map<String, String> messageConfiguration, Message message) throws JMSException { if (messageConfiguration == null) { return message; } for (String name : messageConfiguration.keySet()) { if (name.startsWith(JMSConstants.JMSX_PREFIX) && !(name.equals(JMSConstants.JMSX_GROUP_ID) || name.equals(JMSConstants.JMSX_GROUP_SEQ))) { continue; } if (JMSConstants.JMS_COORELATION_ID.equals(name)) { message.setJMSCorrelationID(messageConfiguration.get(JMSConstants.JMS_COORELATION_ID)); } else if (JMSConstants.JMS_DELIVERY_MODE.equals(name)) { String mode = messageConfiguration.get(JMSConstants.JMS_DELIVERY_MODE); try { message.setJMSDeliveryMode(Integer.parseInt(mode)); } catch (NumberFormatException nfe) { log.warn("Invalid delivery mode ignored : " + mode, nfe); } } else if (JMSConstants.JMS_EXPIRATION.equals(name)) { message.setJMSExpiration(Long.parseLong(messageConfiguration.get(JMSConstants.JMS_EXPIRATION))); } else if (JMSConstants.JMS_MESSAGE_ID.equals(name)) { message.setJMSMessageID(messageConfiguration.get(JMSConstants.JMS_MESSAGE_ID)); } else if (JMSConstants.JMS_PRIORITY.equals(name)) { message.setJMSPriority(Integer.parseInt(messageConfiguration.get(JMSConstants.JMS_PRIORITY))); } else if (JMSConstants.JMS_TIMESTAMP.equals(name)) { message.setJMSTimestamp(Long.parseLong(messageConfiguration.get(JMSConstants.JMS_TIMESTAMP))); } else if (JMSConstants.JMS_MESSAGE_TYPE.equals(name)) { message.setJMSType(messageConfiguration.get(JMSConstants.JMS_MESSAGE_TYPE)); } else { //TODO currently only string is supported in messageConfiguration Object value = messageConfiguration.get(name); if (value instanceof String) { message.setStringProperty(name, (String) value); } else if (value instanceof Boolean) { message.setBooleanProperty(name, (Boolean) value); } else if (value instanceof Integer) { message.setIntProperty(name, (Integer) value); } else if (value instanceof Long) { message.setLongProperty(name, (Long) value); } else if (value instanceof Double) { message.setDoubleProperty(name, (Double) value); } else if (value instanceof Float) { message.setFloatProperty(name, (Float) value); } } } return message; }