Example usage for javax.jms ObjectMessage setObjectProperty

List of usage examples for javax.jms ObjectMessage setObjectProperty

Introduction

In this page you can find the example usage for javax.jms ObjectMessage setObjectProperty.

Prototype


void setObjectProperty(String name, Object value) throws JMSException;

Source Link

Document

Sets a Java object property value with the specified name into the message.

Usage

From source file:org.apache.servicemix.audit.async.AbstractJmsExchangeListener.java

public void exchangeSent(final ExchangeEvent event) {
    jmsTemplate.send(new MessageCreator() {

        public Message createMessage(Session session) throws JMSException {
            createConfigNodeForNamespace(event.getExchange());
            ObjectMessage message = session.createObjectMessage();
            message.setObjectProperty(EVENT, Event.Sent.name());
            message.setObject((Serializable) getSerializer(event.getExchange().getService().getNamespaceURI())
                    .serialize(event.getExchange()));
            return message;
        }/*from   ww  w .j  ava  2  s .c  o  m*/

    });
}

From source file:org.apache.james.queue.jms.JMSMailQueue.java

/**
 * Produce the mail to the JMS Queue/*ww  w.  j a  va 2  s.c o  m*/
 */
protected void produceMail(Map<String, Object> props, int msgPrio, Mail mail)
        throws JMSException, MessagingException, IOException {
    ObjectMessage message = session.createObjectMessage();

    for (Map.Entry<String, Object> entry : props.entrySet()) {
        message.setObjectProperty(entry.getKey(), entry.getValue());
    }

    long size = mail.getMessageSize();
    ByteArrayOutputStream out;
    if (size > -1) {
        out = new ByteArrayOutputStream((int) size);
    } else {
        out = new ByteArrayOutputStream();
    }
    mail.getMessage().writeTo(out);

    // store the byte array in a ObjectMessage so we can use a
    // SharedByteArrayInputStream later
    // without the need of copy the day
    message.setObject(out.toByteArray());

    producer.send(message, Message.DEFAULT_DELIVERY_MODE, msgPrio, Message.DEFAULT_TIME_TO_LIVE);
}

From source file:org.apache.james.queue.jms.JMSMailQueue.java

/**
 * Create a copy of the given {@link Message}. This includes the properties
 * and the payload//from   www  . j  av a 2 s.  c om
 *
 * @param session
 * @param m
 * @return copy
 * @throws JMSException
 */
@SuppressWarnings("unchecked")
protected Message copy(Session session, Message m) throws JMSException {
    ObjectMessage message = (ObjectMessage) m;
    ObjectMessage copy = session.createObjectMessage(message.getObject());

    Enumeration<String> properties = message.getPropertyNames();
    while (properties.hasMoreElements()) {
        String name = properties.nextElement();
        copy.setObjectProperty(name, message.getObjectProperty(name));
    }

    return copy;
}

From source file:org.jbpm.bpel.integration.server.SoapHandler.java

/**
 * Gets the values of message properties from the request message parts and sets them in the
 * property fields of the JMS message.//w w  w.j  a v a  2 s  .c om
 * @param requestParts the parts extracted from the request SOAP message
 * @param jmsRequest the JMS message whose properties will be set
 * @param propertyAliases the property aliases associated with the request message type
 * @throws JMSException
 */
private static void fillCorrelationProperties(Map requestParts, ObjectMessage jmsRequest, Map propertyAliases)
        throws JMSException {
    // easy way out: no property aliases
    if (propertyAliases == null)
        return;
    // iterate through the property aliases associated with the message type
    for (Iterator i = propertyAliases.entrySet().iterator(); i.hasNext();) {
        Entry aliasEntry = (Entry) i.next();
        QName propertyName = (QName) aliasEntry.getKey();
        PropertyAlias alias = (PropertyAlias) aliasEntry.getValue();
        // get part accessor from operation wrapper
        String partName = alias.getPart();
        Object value = requestParts.get(partName);
        if (value == null) {
            log.debug("message part not found, cannot get property value: property=" + propertyName + ", part="
                    + partName);
            continue;
        }
        // evaluate the query against the part value, if any
        PropertyQuery query = alias.getQuery();
        if (query != null) {
            try {
                value = query.getEvaluator().evaluate((Element) value);
            } catch (BpelFaultException e) {
                // the most likely cause is a selection failure due to missing nodes
                log.debug("query evaluation failed, " + "cannot get property value: property=" + propertyName
                        + ", part=" + partName + ", query=" + query.getText(), e);
                continue;
            }
        }
        // set the value in a jms message property field
        jmsRequest.setObjectProperty(propertyName.getLocalPart(),
                value instanceof Node ? DatatypeUtil.toString((Node) value) : value);
    }
}