List of usage examples for javax.jms Message setObjectProperty
void setObjectProperty(String name, Object value) throws JMSException;
From source file:com.fusesource.forge.jmstest.tests.AsyncConsumer.java
public void onMessage(Message msg) { if (receiveCount != null) { receiveCount.incrementAndGet();//from w w w . j a va2s . c o m } MessageProducer producer = null; try { Destination replyDest = msg.getJMSReplyTo(); if (replyDest != null) { Message response = getSession().createTextMessage("Response"); response.setStringProperty("ServedBy", getName()); response.setJMSCorrelationID(msg.getJMSCorrelationID()); for (Enumeration<?> en = msg.getPropertyNames(); en.hasMoreElements();) { String key = (String) en.nextElement(); Object value = msg.getObjectProperty(key); if (key.equals("BrokerStamp")) { value = value.toString() + " --"; } response.setObjectProperty(key, value); } producer = getSession().createProducer(replyDest); producer.send(response); } } catch (Exception e) { LOG.error(e); } finally { if (producer != null) { try { producer.close(); } catch (Exception e) { } } } }
From source file:cherry.foundation.async.PropertyMessagePostProcessor.java
@Override public Message postProcessMessage(Message message) throws JMSException { for (Map.Entry<String, Object> entry : properties.entrySet()) { String name = entry.getKey(); Object v = entry.getValue(); if (v instanceof String) { message.setStringProperty(name, (String) v); } else if (v instanceof Integer) { message.setIntProperty(name, ((Integer) v).intValue()); } else if (v instanceof Long) { message.setLongProperty(name, ((Long) v).longValue()); } else if (v instanceof Short) { message.setShortProperty(name, ((Short) v).shortValue()); } else if (v instanceof Byte) { message.setByteProperty(name, ((Byte) v).byteValue()); } else if (v instanceof Boolean) { message.setBooleanProperty(name, ((Boolean) v).booleanValue()); } else if (v instanceof Double) { message.setDoubleProperty(name, ((Double) v).doubleValue()); } else if (v instanceof Float) { message.setFloatProperty(name, ((Float) v).floatValue()); } else {//from ww w .j av a 2 s.c o m message.setObjectProperty(name, v); } } return message; }
From source file:org.logicblaze.lingo.jms.JmsClientInterceptor.java
protected void populateHeaders(Message requestMessage) throws JMSException { if (correlationID != null) { requestMessage.setJMSCorrelationID(correlationID); }//w ww . jav a2s . c om if (jmsType != null) { requestMessage.setJMSType(jmsType); } if (jmsExpiration >= 0) { requestMessage.setJMSExpiration(jmsExpiration); } int jmsPriority = getJmsPriority(); if (jmsPriority >= 0) { requestMessage.setJMSPriority(jmsPriority); } if (messageProperties != null) { for (Iterator iter = messageProperties.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String name = entry.getKey().toString(); Object value = entry.getValue(); requestMessage.setObjectProperty(name, value); } } }
From source file:org.apache.servicemix.jms.endpoints.AbstractConsumerEndpoint.java
protected void send(Message msg, Session session, Destination dest) throws JMSException { MessageProducer producer;/* w ww . j a v a 2s .c o m*/ if (isJms102()) { if (isPubSubDomain()) { producer = ((TopicSession) session).createPublisher((Topic) dest); } else { producer = ((QueueSession) session).createSender((Queue) dest); } } else { producer = session.createProducer(dest); } try { if (replyProperties != null) { for (Map.Entry<String, Object> e : replyProperties.entrySet()) { msg.setObjectProperty(e.getKey(), e.getValue()); } } if (isJms102()) { if (isPubSubDomain()) { if (replyExplicitQosEnabled) { ((TopicPublisher) producer).publish(msg, replyDeliveryMode, replyPriority, replyTimeToLive); } else { ((TopicPublisher) producer).publish(msg); } } else { if (replyExplicitQosEnabled) { ((QueueSender) producer).send(msg, replyDeliveryMode, replyPriority, replyTimeToLive); } else { ((QueueSender) producer).send(msg); } } } else { if (replyExplicitQosEnabled) { producer.send(msg, replyDeliveryMode, replyPriority, replyTimeToLive); } else { producer.send(msg); } } } finally { JmsUtils.closeMessageProducer(producer); } }
From source file:com.mirth.connect.connectors.jms.transformers.AbstractJmsTransformer.java
/** * @param src The source data to compress * @return//from www .j a v a 2 s .c o m * @throws TransformerException */ protected Message transformToMessage(Object src) throws TransformerException { try { // The session can be closed by the dispatcher closing so its more // reliable to get it from the dispatcher each time if (requireNewSession || getEndpoint() != null) { session = (Session) getEndpoint().getConnector().getDispatcher("transformerSession") .getDelegateSession(); requireNewSession = session == null; } Message msg = null; if (src instanceof Message) { msg = (Message) src; msg.clearProperties(); } else { msg = JmsMessageUtils.getMessageForObject(src, session); } // set the event properties on the Message UMOEventContext ctx = RequestContext.getEventContext(); if (ctx == null) { logger.warn("There is no current event context"); return msg; } Map props = ctx.getProperties(); props = PropertiesHelper.getPropertiesWithoutPrefix(props, "JMS"); // FIXME: If we add the "destinations" property, then this message will be // ignored by channels that are not related to the original source // channel. // Bug: MIRTH-1689 props.remove("destinations"); Map.Entry entry; String key; for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext();) { entry = (Map.Entry) iterator.next(); key = entry.getKey().toString(); if (MuleProperties.MULE_CORRELATION_ID_PROPERTY.equals(key)) { msg.setJMSCorrelationID(entry.getValue().toString()); } //We dont want to set the ReplyTo property again as it will be set using JMSReplyTo if (!(MuleProperties.MULE_REPLY_TO_PROPERTY.equals(key) && entry.getValue() instanceof Destination)) { try { msg.setObjectProperty(encodeHeader(key), entry.getValue()); } catch (JMSException e) { //Various Jms servers have slightly different rules to what can be set as an object property on the message //As such we have to take a hit n' hope approach if (logger.isDebugEnabled()) logger.debug("Unable to set property '" + encodeHeader(key) + "' of type " + entry.getValue().getClass().getName() + "': " + e.getMessage()); } } } return msg; // } } catch (Exception e) { throw new TransformerException(this, e); } }
From source file:hermes.impl.DefaultXMLHelper.java
public Message createMessage(MessageFactory hermes, XMLMessage message) throws JMSException, IOException, ClassNotFoundException, DecoderException { try {//from ww w . j a v a2 s. c om Message rval = hermes.createMessage(); if (message instanceof XMLTextMessage) { rval = hermes.createTextMessage(); XMLTextMessage textMessage = (XMLTextMessage) message; TextMessage textRval = (TextMessage) rval; if (BASE64_CODEC.equals(textMessage.getCodec())) { byte[] bytes = base64EncoderTL.get().decode(textMessage.getText().getBytes()); textRval.setText(new String(bytes, "ASCII")); } else { textRval.setText(textMessage.getText()); } } else if (message instanceof XMLMapMessage) { rval = hermes.createMapMessage(); XMLMapMessage mapMessage = (XMLMapMessage) message; MapMessage mapRval = (MapMessage) rval; for (Iterator iter = mapMessage.getBodyProperty().iterator(); iter.hasNext();) { final Property property = (Property) iter.next(); if (property.getValue() == null) { mapRval.setObject(property.getName(), null); } else if (property.getType().equals(String.class.getName())) { mapRval.setString(property.getName(), property.getValue()); } else if (property.getType().equals(Long.class.getName())) { mapRval.setLong(property.getName(), Long.parseLong(property.getValue())); } else if (property.getType().equals(Double.class.getName())) { mapRval.setDouble(property.getName(), Double.parseDouble(property.getValue())); } else if (property.getType().equals(Boolean.class.getName())) { mapRval.setBoolean(property.getName(), Boolean.getBoolean(property.getValue())); } else if (property.getType().equals(Character.class.getName())) { mapRval.setChar(property.getName(), property.getValue().charAt(0)); } else if (property.getType().equals(Short.class.getName())) { mapRval.setShort(property.getName(), Short.parseShort(property.getValue())); } else if (property.getType().equals(Integer.class.getName())) { mapRval.setInt(property.getName(), Integer.parseInt(property.getValue())); } } } else if (message instanceof XMLBytesMessage) { rval = hermes.createBytesMessage(); XMLBytesMessage bytesMessage = (XMLBytesMessage) message; BytesMessage bytesRval = (BytesMessage) rval; bytesRval.writeBytes(base64EncoderTL.get().decode(bytesMessage.getBytes().getBytes())); } else if (message instanceof XMLObjectMessage) { rval = hermes.createObjectMessage(); XMLObjectMessage objectMessage = (XMLObjectMessage) message; ObjectMessage objectRval = (ObjectMessage) rval; ByteArrayInputStream bistream = new ByteArrayInputStream( base64EncoderTL.get().decode(objectMessage.getObject().getBytes())); ObjectInputStream oistream = new ObjectInputStream(bistream); objectRval.setObject((Serializable) oistream.readObject()); } // // JMS Header properties try { rval.setJMSDeliveryMode(message.getJMSDeliveryMode()); } catch (JMSException ex) { log.error("unable to set JMSDeliveryMode to " + message.getJMSDeliveryMode() + ": " + ex.getMessage()); } try { rval.setJMSMessageID(message.getJMSMessageID()); } catch (JMSException ex) { log.error("unable to set JMSMessageID: " + ex.getMessage(), ex); } try { if (message.getJMSExpiration() != null) { rval.setJMSExpiration(message.getJMSExpiration()); } } catch (JMSException ex) { log.error("unable to set JMSExpiration: " + ex.getMessage(), ex); } try { if (message.getJMSPriority() != null) { rval.setJMSPriority(message.getJMSPriority()); } } catch (JMSException ex) { log.error("unable to set JMSPriority: " + ex.getMessage(), ex); } try { if (message.getJMSTimestamp() != null) { rval.setJMSTimestamp(message.getJMSTimestamp()); } } catch (JMSException ex) { log.error("unable to set JMSTimestamp:" + ex.getMessage(), ex); } if (message.getJMSCorrelationID() != null) { rval.setJMSCorrelationID(message.getJMSCorrelationID()); } if (message.getJMSReplyTo() != null && !message.getJMSReplyTo().equals("null")) { rval.setJMSReplyTo(hermes.getDestination(message.getJMSReplyTo(), Domain.getDomain(message.getJMSReplyToDomain()))); } if (message.getJMSType() != null) { rval.setJMSType(message.getJMSType()); } if (message.getJMSDestination() != null) { if (message.isFromQueue()) { rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.QUEUE)); } else { rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.TOPIC)); } } for (Iterator iter = message.getHeaderProperty().iterator(); iter.hasNext();) { Property property = (Property) iter.next(); if (property.getValue() == null) { rval.setObjectProperty(property.getName(), null); } else if (property.getType().equals(String.class.getName())) { rval.setStringProperty(property.getName(), StringEscapeUtils.unescapeXml(property.getValue())); } else if (property.getType().equals(Long.class.getName())) { rval.setLongProperty(property.getName(), Long.parseLong(property.getValue())); } else if (property.getType().equals(Double.class.getName())) { rval.setDoubleProperty(property.getName(), Double.parseDouble(property.getValue())); } else if (property.getType().equals(Boolean.class.getName())) { rval.setBooleanProperty(property.getName(), Boolean.parseBoolean(property.getValue())); } else if (property.getType().equals(Short.class.getName())) { rval.setShortProperty(property.getName(), Short.parseShort(property.getValue())); } else if (property.getType().equals(Integer.class.getName())) { rval.setIntProperty(property.getName(), Integer.parseInt(property.getValue())); } } return rval; } catch (NamingException e) { throw new HermesException(e); } }
From source file:nl.nn.adapterframework.jms.JmsSender.java
/** * sets the JMS message properties as descriped in the msgProperties arraylist * @param msg/*from w ww .j a va2s . co m*/ * @param msgProperties * @throws JMSException */ private void setProperties(Message msg, ParameterValueList msgProperties) throws JMSException { for (int i = 0; i < msgProperties.size(); i++) { ParameterValue property = msgProperties.getParameterValue(i); String type = property.getDefinition().getType(); String name = property.getDefinition().getName(); if (!isSoap() || !name.equals(getSoapHeaderParam())) { if (log.isDebugEnabled()) { log.debug(getLogPrefix() + "setting [" + type + "] property from param [" + name + "] to value [" + property.getValue() + "]"); } if ("boolean".equalsIgnoreCase(type)) msg.setBooleanProperty(name, property.asBooleanValue(false)); else if ("byte".equalsIgnoreCase(type)) msg.setByteProperty(name, property.asByteValue((byte) 0)); else if ("double".equalsIgnoreCase(type)) msg.setDoubleProperty(name, property.asDoubleValue(0)); else if ("float".equalsIgnoreCase(type)) msg.setFloatProperty(name, property.asFloatValue(0)); else if ("int".equalsIgnoreCase(type)) msg.setIntProperty(name, property.asIntegerValue(0)); else if ("long".equalsIgnoreCase(type)) msg.setLongProperty(name, property.asLongValue(0L)); else if ("short".equalsIgnoreCase(type)) msg.setShortProperty(name, property.asShortValue((short) 0)); else if ("string".equalsIgnoreCase(type)) msg.setStringProperty(name, property.asStringValue("")); else // if ("object".equalsIgnoreCase(type)) msg.setObjectProperty(name, property.getValue()); } } }
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 {/* w w w . j av a2s . co m*/ message.setObjectProperty(propertyName, propertyValue); } }
From source file:org.codehaus.stomp.jms.StompSession.java
protected void copyStandardHeadersFromFrameToMessage(StompFrame command, Message msg) throws JMSException, ProtocolException, NamingException { final Map headers = new HashMap(command.getHeaders()); // the standard JMS headers msg.setJMSCorrelationID((String) headers.remove(Stomp.Headers.Send.CORRELATION_ID)); Object o = headers.remove(Stomp.Headers.Send.TYPE); if (o != null) { msg.setJMSType((String) o); }/*w w w .j av a 2s . com*/ o = headers.remove(Stomp.Headers.Send.REPLY_TO); if (o != null) { msg.setJMSReplyTo(convertDestination((String) o, false)); } // now the general headers for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String name = (String) entry.getKey(); Object value = entry.getValue(); msg.setObjectProperty(name, value); } }
From source file:org.openadaptor.auxil.connector.jms.DefaultMessageGenerator.java
private void setMessageProperties(Message msg) throws JMSException { if (metaData != null) { for (Iterator keys = metaData.keySet().iterator(); keys.hasNext();) { // Jboss Note: During testing we found that Jboss doesn't like having a space in the Key. // I.e while a key value of e.g. "TestKey" below is accepted "Test Key" causes an error. String key = (String) keys.next(); Object value = metaData.get(key); msg.setObjectProperty(key, value); }// w w w.j a v a 2 s. c o m } }