Example usage for javax.jms Message setJMSReplyTo

List of usage examples for javax.jms Message setJMSReplyTo

Introduction

In this page you can find the example usage for javax.jms Message setJMSReplyTo.

Prototype


void setJMSReplyTo(Destination replyTo) throws JMSException;

Source Link

Document

Sets the Destination object to which a reply to this message should be sent.

Usage

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);
    }/*www  .j av a 2 s .  c  o m*/

    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.grouter.common.jms.QueueSenderDestination.java

/**
 * Set header for JMS message. Only JMSReplyTo, JMSCorrelationID and JMSType can be set using setters.
 *
 * @param msg Message// w  ww . j a  v  a2  s.com
 * @throws javax.jms.JMSException a JMS exception when failing to set the header values
 */
private void setJMSHeader(Message msg) throws JMSException {
    if (useTemporaryReplyDestination && temporaryQueue != null) {
        logger.debug("Using a temporary destination for this session.");
        msg.setJMSReplyTo(temporaryQueue);
    }
}

From source file:org.grouter.common.jms.TopicSenderDestination.java

/**
 * Set header for JMS message. Only JMSReplyTo, JMSCorrelationID and JMSType can be set using setters.
 *
 * @param msg Message/* w w w .ja v a2s  .  c  o  m*/
 * @throws javax.jms.JMSException  a JMSException
 */
private void setJMSHeader(Message msg) throws JMSException {
    if (useTemporaryReplyDestination && temporaryTopic != null) {
        logger.debug("Using a temporary destination for this session.");
        msg.setJMSReplyTo(temporaryTopic);
    }
}

From source file:org.mule.transport.jms.JmsMessageUtils.java

public static Message copyJMSProperties(Message from, Message to, JmsConnector connector) throws JMSException {
    if (connector.supportsProperty(JmsConstants.JMS_CORRELATION_ID)) {
        to.setJMSCorrelationID(from.getJMSCorrelationID());
    }// ww  w  .j  a  v  a2 s.  c  om
    if (connector.supportsProperty(JmsConstants.JMS_DELIVERY_MODE)) {
        to.setJMSDeliveryMode(from.getJMSDeliveryMode());
    }
    if (connector.supportsProperty(JmsConstants.JMS_DESTINATION)) {
        to.setJMSDestination(from.getJMSDestination());
    }
    if (connector.supportsProperty(JmsConstants.JMS_EXPIRATION)) {
        to.setJMSExpiration(from.getJMSExpiration());
    }
    if (connector.supportsProperty(JmsConstants.JMS_MESSAGE_ID)) {
        to.setJMSMessageID(from.getJMSMessageID());
    }
    if (connector.supportsProperty(JmsConstants.JMS_PRIORITY)) {
        to.setJMSPriority(from.getJMSPriority());
    }
    if (connector.supportsProperty(JmsConstants.JMS_REDELIVERED)) {
        to.setJMSRedelivered(from.getJMSRedelivered());
    }
    if (connector.supportsProperty(JmsConstants.JMS_REPLY_TO)) {
        to.setJMSReplyTo(from.getJMSReplyTo());
    }
    if (connector.supportsProperty(JmsConstants.JMS_TIMESTAMP)) {
        to.setJMSTimestamp(from.getJMSTimestamp());
    }
    if (connector.supportsProperty(JmsConstants.JMS_TYPE)) {
        to.setJMSType(from.getJMSType());
    }
    return to;
}

From source file:org.openanzo.combus.CombusConnection.java

/**
 * Send a request to a destination and wait for a response
 * //from  w  w w.  ja v  a  2 s. c  om
 * @param context
 *            context for this operational call
 * @param destinationName
 *            destination queue for this request
 * @param request
 *            request message
 * @param timeout
 *            timeout for waiting for a response
 * @return response message
 * @throws AnzoException
 *             if there was an exception sending request, or a timeout waiting for a response
 */
public TextMessage requestResponse(IOperationContext context, String destinationName, Message request,
        long timeout) throws AnzoException {
    Destination destination = null;

    if (context.getAttribute(OPTIONS.DATASOURCE) != null) {
        URI datasourceUri = (URI) context.getAttribute(OPTIONS.DATASOURCE);
        Queue defaultDestination = (Queue) destinations.get(destinationName);
        if (datasourceUri.toString().equals("http://openanzo.org/datasource/systemDatasource")) {
            destination = defaultDestination;
        } else {
            String queueNamePrefix = UriGenerator.generateEncapsulatedString("", datasourceUri.toString())
                    + "/";
            try {
                String[] parts = StringUtils.split(defaultDestination.getQueueName(), '/');
                String queue = "services/" + queueNamePrefix + parts[1];
                destination = destinations.get(queue);
                if (destination == null) {
                    destination = session.createQueue(queue);
                    destinations.put(queue, destination);
                }
            } catch (JMSException e) {
                throw new AnzoException(ExceptionConstants.COMBUS.NO_SUCH_DESTINATION, destinationName);
            }
        }
    } else {
        destination = destinations.get(destinationName);
        if (destination == null) {
            throw new AnzoException(ExceptionConstants.COMBUS.NO_SUCH_DESTINATION, destinationName);
        }
    }

    if (context.getAttribute(COMBUS.TIMEOUT) != null) {
        timeout = (Long) context.getAttribute(COMBUS.TIMEOUT);
    }

    String correlationId = context.getOperationId();
    if (correlationId == null) {
        correlationId = UUID.randomUUID().toString();
    }

    try {
        request.setJMSCorrelationID(correlationId);
        request.setJMSReplyTo(tempQueue);
        request.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION);
        if (context.getOperationPrincipal() != null
                && !context.getOperationPrincipal().getName().equals(this.userName)) {
            request.setStringProperty(SerializationConstants.runAsUser,
                    context.getOperationPrincipal().getName());
        }
        if (context.getAttribute(OPTIONS.PRIORITY) != null) {
            Integer priority = (Integer) context.getAttribute(OPTIONS.PRIORITY);
            request.setJMSPriority(priority);
            messageProducer.setPriority(priority);
        } else {
            messageProducer.setPriority(4);
        }
        if (context.getAttribute(OPTIONS.SKIPCACHE) != null) {
            request.setBooleanProperty(OPTIONS.SKIPCACHE,
                    context.getAttribute(OPTIONS.SKIPCACHE, Boolean.class));
        }
        if (log.isTraceEnabled()) {
            log.trace(LogUtils.COMBUS_MARKER,
                    MessageUtils.prettyPrint(request, "Sending Request: (destination=" + destination + ")"));
        }
        messageProducer.send(destination, request);
    } catch (JMSException jmsex) {
        performDisconnect(true);
        throw new AnzoException(ExceptionConstants.COMBUS.COULD_NOT_PUBLISH, jmsex);
    }
    lock.lock();
    try {
        Collection<TextMessage> messageSet = correlationIdToMessage.remove(correlationId);
        long start = System.currentTimeMillis();
        while (messageSet == null) {
            if (timeout <= 0) {
                try {
                    newMessage.await(2, TimeUnit.SECONDS);
                } catch (InterruptedException ie) {
                    throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                }
                if (closed || closing) {
                    throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                }
                messageSet = correlationIdToMessage.remove(correlationId);
            } else {
                try {
                    newMessage.await(timeout, TimeUnit.MILLISECONDS);
                } catch (InterruptedException ie) {
                    throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                }
                if (closed || closing) {
                    throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                }
                messageSet = correlationIdToMessage.remove(correlationId);
                if (!connected) {
                    log.error(LogUtils.COMBUS_MARKER, "Request Response failed because connection was closed");
                    throw new AnzoException(ExceptionConstants.COMBUS.JMS_NOT_CONNECTED, correlationId);
                }
                if (messageSet == null && ((timeout > 0) && ((System.currentTimeMillis() - start) > timeout))) {
                    throw new AnzoException(ExceptionConstants.COMBUS.NO_SERVER_RESPONSE, correlationId);
                }
            }
        }
        try {
            TextMessage message = messageSet.iterator().next();
            if (log.isTraceEnabled()) {
                log.trace(LogUtils.COMBUS_MARKER, MessageUtils.prettyPrint(message, "Received Response:"));
            }

            if (message.getBooleanProperty(SerializationConstants.operationFailed)) {
                long errorCodes = message.propertyExists(SerializationConstants.errorTags)
                        ? message.getLongProperty(SerializationConstants.errorCode)
                        : ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION;

                // if available, use enumerated args, since these can be reconstruct an AnzoException correctly.
                List<String> args = new ArrayList<String>();
                for (int i = 0; true; i++) {
                    String errorArg = message.getStringProperty(SerializationConstants.errorMessageArg + i);
                    if (errorArg == null) {
                        break;
                    }
                    args.add(errorArg);
                }

                // NOTE: This doesn't really make any sense, but it was here before and it's better to be too verbose than not verbose enough
                // when it comes to error messages, so it stays.  For now at least. -jpbetz
                if (args.isEmpty()) {
                    args.add(message.getText());
                }
                throw new AnzoException(errorCodes, args.toArray(new String[0]));
            }
            /*Object prp = context.getAttribute("populateResponseProperties");
            if (prp != null && ((Boolean) prp)) {
            HashMap<String, Object> props = new HashMap<String, Object>();
            Enumeration<String> keys = message.getPropertyNames();
            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                props.put(key, message.getObjectProperty(key));
            }
            context.setAttribute("responseProperties", props);
            }*/
            return message;
        } catch (JMSException jmsex) {
            log.debug(LogUtils.COMBUS_MARKER, Messages.formatString(
                    ExceptionConstants.COMBUS.ERROR_PROCESSING_MESSGE, "request response"), jmsex);
        }
        return null;
    } finally {
        lock.unlock();
    }
}

From source file:org.openanzo.combus.CombusConnection.java

/**
 * Send a request to a destination and wait for a response
 * //from w  ww. ja va 2 s .  c  om
 * @param context
 *            context for this operational call
 * @param destinationName
 *            destination queue for this request
 * @param request
 *            request message
 * @param timeout
 *            timeout for waiting for a response
 * @param messageHandler
 *            the handler of multiple messages
 * @throws AnzoException
 *             if there was an exception sending request, or a timeout waiting for a response
 */
public void requestMultipleResponse(IOperationContext context, String destinationName, Message request,
        long timeout, IMessageHandler messageHandler) throws AnzoException {
    Destination destination = null;
    if (context.getAttribute(OPTIONS.DATASOURCE) != null) {
        URI datasourceUri = (URI) context.getAttribute(OPTIONS.DATASOURCE);
        Queue defaultDestination = (Queue) destinations.get(destinationName);
        if (datasourceUri.toString().equals("http://openanzo.org/datasource/systemDatasource")) {
            destination = defaultDestination;
        } else {
            String queueNamePrefix = UriGenerator.generateEncapsulatedString("", datasourceUri.toString())
                    + "/";
            try {
                String[] parts = StringUtils.split(defaultDestination.getQueueName(), '/');
                String queue = "services/" + queueNamePrefix + parts[1];
                destination = destinations.get(queue);
                if (destination == null) {
                    destination = session.createQueue(queue);
                    destinations.put(queue, destination);
                }
            } catch (JMSException e) {
                throw new AnzoException(ExceptionConstants.COMBUS.NO_SUCH_DESTINATION, destinationName);
            }
        }
    } else {
        destination = destinations.get(destinationName);
        if (destination == null) {
            throw new AnzoException(ExceptionConstants.COMBUS.NO_SUCH_DESTINATION, destinationName);
        }
    }
    String correlationId = context.getOperationId();
    if (correlationId == null) {
        correlationId = UUID.randomUUID().toString();
    }

    try {
        request.setJMSCorrelationID(correlationId);
        request.setJMSReplyTo(tempQueue);
        request.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION);
        if (context.getOperationPrincipal() != null
                && !context.getOperationPrincipal().getName().equals(this.userName)) {
            request.setStringProperty(SerializationConstants.runAsUser,
                    context.getOperationPrincipal().getName());
        }
        if (context.getAttribute(OPTIONS.PRIORITY) != null) {
            Integer priority = (Integer) context.getAttribute(OPTIONS.PRIORITY);
            request.setJMSPriority(priority);
            messageProducer.setPriority(priority);
        } else {
            messageProducer.setPriority(4);
        }
        if (context.getAttribute(OPTIONS.SKIPCACHE) != null) {
            request.setBooleanProperty(OPTIONS.SKIPCACHE,
                    context.getAttribute(OPTIONS.SKIPCACHE, Boolean.class));
        }
        if (context.getAttribute(OPTIONS.INCLUDEMETADATAGRAPHS) != null) {
            request.setBooleanProperty(OPTIONS.INCLUDEMETADATAGRAPHS,
                    context.getAttribute(OPTIONS.INCLUDEMETADATAGRAPHS, Boolean.class));
        }
        if (log.isTraceEnabled()) {
            log.trace(LogUtils.COMBUS_MARKER,
                    MessageUtils.prettyPrint(request, "Sending Request: (destination=" + destination + ")"));
        }
        messageProducer.send(destination, request);
    } catch (JMSException jmsex) {
        performDisconnect(true);
        throw new AnzoException(ExceptionConstants.COMBUS.COULD_NOT_PUBLISH, jmsex);
    }
    lock.lock();
    try {
        long start = System.currentTimeMillis();
        boolean done = false;
        int seq = 0;
        while (!done) {
            Collection<TextMessage> messageSet = correlationIdToMessage.remove(correlationId);
            while (messageSet == null) {
                if (timeout <= 0) {
                    try {
                        newMessage.await(2, TimeUnit.SECONDS);
                    } catch (InterruptedException ie) {
                        throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                    }
                    if (closed || closing) {
                        throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                    }
                    messageSet = correlationIdToMessage.remove(correlationId);
                } else {
                    try {
                        newMessage.await(timeout, TimeUnit.MILLISECONDS);
                    } catch (InterruptedException ie) {
                        throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                    }
                    if (closed || closing) {
                        throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                    }
                    messageSet = correlationIdToMessage.remove(correlationId);
                    if (!connected) {
                        log.error(LogUtils.COMBUS_MARKER, Messages.formatString(
                                ExceptionConstants.COMBUS.ERROR_PROCESSING_MESSGE, "connection closed"));
                        throw new AnzoException(ExceptionConstants.COMBUS.JMS_NOT_CONNECTED, correlationId);
                    }
                    if (messageSet == null
                            && ((timeout > -1) && ((System.currentTimeMillis() - start) > timeout))) {
                        throw new AnzoException(ExceptionConstants.COMBUS.NO_SERVER_RESPONSE, correlationId);
                    }
                }

            }
            try {
                for (TextMessage message : messageSet) {
                    if (log.isTraceEnabled()) {
                        log.trace(LogUtils.COMBUS_MARKER,
                                MessageUtils.prettyPrint(message, "Recieved Response:"));
                    }
                    if (message.propertyExists("done")) {
                        done = message.getBooleanProperty("done");
                    } else {
                        done = true;
                    }
                    if (message.propertyExists("sequence")) {
                        int sequence = message.getIntProperty("sequence");
                        if (sequence != seq) {
                            throw new AnzoException(ExceptionConstants.COMBUS.NO_SERVER_RESPONSE,
                                    correlationId);
                        } else {
                            seq++;
                        }
                    }

                    int totalSize = 0;
                    if (message.propertyExists(SerializationConstants.totalSolutions)) {
                        totalSize = message.getIntProperty(SerializationConstants.totalSolutions);
                    }
                    if (message.getBooleanProperty(SerializationConstants.operationFailed)) {
                        long errorCodes = message.propertyExists(SerializationConstants.errorTags)
                                ? message.getLongProperty(SerializationConstants.errorCode)
                                : ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION;

                        // if available, use enumerated args, since these can be reconstruct an AnzoException correctly.
                        List<String> args = new ArrayList<String>();
                        for (int i = 0; true; i++) {
                            String errorArg = message
                                    .getStringProperty(SerializationConstants.errorMessageArg + i);
                            if (errorArg == null) {
                                break;
                            }
                            args.add(errorArg);
                        }

                        // NOTE: This doesn't really make any sense, but it was here before and it's better to be too verbose than not verbose enough
                        // when it comes to error messages, so it stays.  For now at least. -jpbetz
                        if (args.isEmpty()) {
                            args.add(message.getText());
                        }
                        throw new AnzoException(errorCodes, args.toArray(new String[0]));
                    } else {
                        messageHandler.handleMessage(message, seq, done, totalSize);
                    }
                }
            } catch (JMSException jmsex) {
                log.debug(LogUtils.COMBUS_MARKER, Messages.formatString(
                        ExceptionConstants.COMBUS.ERROR_PROCESSING_MESSGE, "request multiple response"), jmsex);
            }
        }
    } finally {
        lock.unlock();
    }
}

From source file:org.springframework.integration.jms.DefaultJmsHeaderMapper.java

public void fromHeaders(MessageHeaders headers, javax.jms.Message jmsMessage) {
    try {/*w w  w . jav a2 s.co  m*/
        Object jmsCorrelationId = headers.get(JmsHeaders.CORRELATION_ID);
        if (jmsCorrelationId instanceof Number) {
            jmsCorrelationId = ((Number) jmsCorrelationId).toString();
        }
        if (jmsCorrelationId instanceof String) {
            try {
                jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
            } catch (Exception e) {
                logger.info("failed to set JMSCorrelationID, skipping", e);
            }
        }
        Object jmsReplyTo = headers.get(JmsHeaders.REPLY_TO);
        if (jmsReplyTo instanceof Destination) {
            try {
                jmsMessage.setJMSReplyTo((Destination) jmsReplyTo);
            } catch (Exception e) {
                logger.info("failed to set JMSReplyTo, skipping", e);
            }
        }
        Object jmsType = headers.get(JmsHeaders.TYPE);
        if (jmsType instanceof String) {
            try {
                jmsMessage.setJMSType((String) jmsType);
            } catch (Exception e) {
                logger.info("failed to set JMSType, skipping", e);
            }
        }
        Set<String> headerNames = headers.keySet();
        for (String headerName : headerNames) {
            if (StringUtils.hasText(headerName) && !headerName.startsWith(JmsHeaders.PREFIX)) {
                Object value = headers.get(headerName);
                if (value != null && SUPPORTED_PROPERTY_TYPES.contains(value.getClass())) {
                    try {
                        String propertyName = this.fromHeaderName(headerName);
                        jmsMessage.setObjectProperty(propertyName, value);
                    } catch (Exception e) {
                        if (headerName.startsWith("JMSX")) {
                            if (logger.isTraceEnabled()) {
                                logger.trace(
                                        "skipping reserved header, it cannot be set by client: " + headerName);
                            }
                        } else if (logger.isWarnEnabled()) {
                            logger.warn("failed to map Message header '" + headerName + "' to JMS property", e);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn("error occurred while mapping from MessageHeaders to JMS properties", e);
        }
    }
}

From source file:org.springframework.jms.support.converter.SimpleJmsHeaderMapper.java

@Override
public void fromHeaders(MessageHeaders headers, javax.jms.Message jmsMessage) {
    try {/* ww w  .  ja v a 2s .c  o  m*/
        Object jmsCorrelationId = headers.get(JmsHeaders.CORRELATION_ID);
        if (jmsCorrelationId instanceof Number) {
            jmsCorrelationId = jmsCorrelationId.toString();
        }
        if (jmsCorrelationId instanceof String) {
            try {
                jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
            } catch (Exception e) {
                logger.info("failed to set JMSCorrelationID, skipping", e);
            }
        }
        Object jmsReplyTo = headers.get(JmsHeaders.REPLY_TO);
        if (jmsReplyTo instanceof Destination) {
            try {
                jmsMessage.setJMSReplyTo((Destination) jmsReplyTo);
            } catch (Exception e) {
                logger.info("failed to set JMSReplyTo, skipping", e);
            }
        }
        Object jmsType = headers.get(JmsHeaders.TYPE);
        if (jmsType instanceof String) {
            try {
                jmsMessage.setJMSType((String) jmsType);
            } catch (Exception e) {
                logger.info("failed to set JMSType, skipping", e);
            }
        }
        Set<String> headerNames = headers.keySet();
        for (String headerName : headerNames) {
            if (StringUtils.hasText(headerName) && !headerName.startsWith(JmsHeaders.PREFIX)) {
                Object value = headers.get(headerName);
                if (value != null && SUPPORTED_PROPERTY_TYPES.contains(value.getClass())) {
                    try {
                        String propertyName = this.fromHeaderName(headerName);
                        jmsMessage.setObjectProperty(propertyName, value);
                    } catch (Exception e) {
                        if (headerName.startsWith("JMSX")) {
                            if (logger.isTraceEnabled()) {
                                logger.trace(
                                        "skipping reserved header, it cannot be set by client: " + headerName);
                            }
                        } else if (logger.isWarnEnabled()) {
                            logger.warn("failed to map Message header '" + headerName + "' to JMS property", e);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn("error occurred while mapping from MessageHeaders to JMS properties", e);
        }
    }
}

From source file:org.springframework.jms.support.SimpleJmsHeaderMapper.java

@Override
public void fromHeaders(MessageHeaders headers, javax.jms.Message jmsMessage) {
    try {/*from w  ww.  j a v a2 s  . co  m*/
        Object jmsCorrelationId = headers.get(JmsHeaders.CORRELATION_ID);
        if (jmsCorrelationId instanceof Number) {
            jmsCorrelationId = jmsCorrelationId.toString();
        }
        if (jmsCorrelationId instanceof String) {
            try {
                jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
            } catch (Exception e) {
                logger.info("failed to set JMSCorrelationID, skipping", e);
            }
        }
        Object jmsReplyTo = headers.get(JmsHeaders.REPLY_TO);
        if (jmsReplyTo instanceof Destination) {
            try {
                jmsMessage.setJMSReplyTo((Destination) jmsReplyTo);
            } catch (Exception e) {
                logger.info("failed to set JMSReplyTo, skipping", e);
            }
        }
        Object jmsType = headers.get(JmsHeaders.TYPE);
        if (jmsType instanceof String) {
            try {
                jmsMessage.setJMSType((String) jmsType);
            } catch (Exception e) {
                logger.info("failed to set JMSType, skipping", e);
            }
        }
        Set<String> headerNames = headers.keySet();
        for (String headerName : headerNames) {
            if (StringUtils.hasText(headerName) && !headerName.startsWith(JmsHeaders.PREFIX)) {
                Object value = headers.get(headerName);
                if (value != null && SUPPORTED_PROPERTY_TYPES.contains(value.getClass())) {
                    try {
                        String propertyName = this.fromHeaderName(headerName);
                        jmsMessage.setObjectProperty(propertyName, value);
                    } catch (Exception e) {
                        if (headerName.startsWith("JMSX")) {
                            if (logger.isTraceEnabled()) {
                                logger.trace(
                                        "skipping reserved header, it cannot be set by client: " + headerName);
                            }
                        } else if (logger.isWarnEnabled()) {
                            logger.warn("failed to map Message header '" + headerName + "' to JMS property", e);
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        if (logger.isWarnEnabled()) {
            logger.warn("error occurred while mapping from MessageHeaders to JMS properties", ex);
        }
    }
}

From source file:org.wso2.carbon.apimgt.jms.listener.utils.JMSUtils.java

/**
 * Set the JMS ReplyTo for the message/*from  www  . j a  v  a 2 s.  co m*/
 *
 * @param replyDestination the JMS Destination where the reply is expected
 * @param session          the session to use to create a temp Queue if a response is expected
 *                         but a Destination has not been specified
 * @param message          the JMS message where the final Destinatio would be set as the JMS ReplyTo
 * @return the JMS ReplyTo Destination for the message
 */
public static Destination setReplyDestination(Destination replyDestination, Session session, Message message) {

    if (replyDestination == null) {
        try {
            // create temporary queue to receive the reply
            replyDestination = createTemporaryDestination(session);
        } catch (JMSException e) {
            BaseUtils.handleException("Error creating temporary queue for response", e);
        }
    }

    try {
        message.setJMSReplyTo(replyDestination);
    } catch (JMSException e) {
        log.warn("Error setting JMS ReplyTo destination to : " + replyDestination, e);
    }

    if (log.isDebugEnabled()) {
        try {
            assert replyDestination != null;
            log.debug("Expecting a response to JMS Destination : "
                    + (replyDestination instanceof Queue ? ((Queue) replyDestination).getQueueName()
                            : ((Topic) replyDestination).getTopicName()));
        } catch (JMSException ignore) {
        }
    }
    return replyDestination;
}