Example usage for javax.jms Message getJMSReplyTo

List of usage examples for javax.jms Message getJMSReplyTo

Introduction

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

Prototype


Destination getJMSReplyTo() throws JMSException;

Source Link

Document

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

Usage

From source file:com.bitsofproof.supernode.core.ImplementBCSAPI.java

private void addBloomScanListener() throws JMSException {
    addMessageListener("scanRequest", new MessageListener() {
        @Override/*from   w  w  w.  j  av  a  2  s . co  m*/
        public void onMessage(Message msg) {
            BytesMessage o = (BytesMessage) msg;
            byte[] body;
            try {
                body = new byte[(int) o.getBodyLength()];
                o.readBytes(body);
                BCSAPIMessage.FilterRequest request = BCSAPIMessage.FilterRequest.parseFrom(body);
                byte[] data = request.getFilter().toByteArray();
                long hashFunctions = request.getHashFunctions();
                long tweak = request.getTweak();
                UpdateMode updateMode = UpdateMode.values()[request.getMode()];
                final BloomFilter filter = new BloomFilter(data, hashFunctions, tweak, updateMode);
                final MessageProducer producer = session.createProducer(msg.getJMSReplyTo());
                requestProcessor.execute(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            store.scan(filter, new TransactionProcessor() {
                                @Override
                                public void process(Tx tx) {
                                    if (tx != null) {
                                        Transaction transaction = toBCSAPITransaction(tx);
                                        BytesMessage m;
                                        try {
                                            m = session.createBytesMessage();
                                            m.writeBytes(transaction.toProtobuf().toByteArray());
                                            producer.send(m);
                                        } catch (JMSException e) {
                                        }
                                    } else {
                                        try {
                                            BytesMessage m = session.createBytesMessage();
                                            producer.send(m); // indicate EOF
                                            producer.close();
                                        } catch (JMSException e) {
                                        }
                                    }
                                }
                            });
                        } catch (ValidationException e) {
                            log.error("Error while scanning", e);
                        }
                    }
                });
            } catch (JMSException e) {
                log.error("invalid filter request", e);
            } catch (InvalidProtocolBufferException e) {
                log.error("invalid filter request", e);
            }
        }
    });
}

From source file:edu.harvard.i2b2.crc.ejb.QueryExecutorMDB.java

/**
 * Take the XML based message and delegate to the system coordinator to
 * handle the actual processing// w  w w  .  j ava  2 s  . c  om
 * 
 * @param msg
 *            th JMS TextMessage object containing XML data
 */
public void onMessage(Message msg) {
    MapMessage message = null;
    QueueConnection conn = null;
    QueueSession session = null;
    QueueSender sender = null;
    QueryProcessorUtil qpUtil = QueryProcessorUtil.getInstance();
    Queue replyToQueue = null;
    UserTransaction transaction = sessionContext.getUserTransaction();
    // default timeout three minutes
    int transactionTimeout = 0;

    try {

        transactionTimeout = this.readTimeoutPropertyValue(SMALL_QUEUE);
        if (callingMDBName.equalsIgnoreCase(QueryExecutorMDB.MEDIUM_QUEUE)) {
            // four hours
            // transactionTimeout = 14400;
            transactionTimeout = this.readTimeoutPropertyValue(MEDIUM_QUEUE);
        } else if (callingMDBName.equalsIgnoreCase(QueryExecutorMDB.LARGE_QUEUE)) {
            // twelve hours
            // transactionTimeout = 43200;
            transactionTimeout = this.readTimeoutPropertyValue(LARGE_QUEUE);
        }

        transaction.setTransactionTimeout(transactionTimeout);

        transaction.begin();
        message = (MapMessage) msg;
        String sessionId = msg.getJMSCorrelationID();
        replyToQueue = (Queue) msg.getJMSReplyTo();
        log.debug("Extracting the message [" + msg.getJMSMessageID() + " ] on " + callingMDBName);
        transaction.commit();
        ExecRunnable er = new ExecRunnable(transaction, transactionTimeout, callingMDBName, message, sessionId);
        er.execute();

    } catch (Exception ex) {
        ex.printStackTrace();
        try {
            if (transaction.getStatus() != 4) {

                transaction.rollback();

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.error("Error extracting message", ex);
    } finally {

        QueryManagerBeanUtil qmBeanUtil = new QueryManagerBeanUtil();
        qmBeanUtil.closeAll(sender, null, conn, session);
    }
}

From source file:org.apache.servicemix.jms.jca.JcaConsumerProcessor.java

public void process(MessageExchange exchange) throws Exception {
    Context context = (Context) pendingMessages.remove(exchange.getExchangeId());
    Message message = (Message) context.getProperty(Message.class.getName());
    Message response = null;/*from w w w.  j  a  v  a  2  s  .c  o  m*/
    Connection connection = null;
    try {
        if (exchange.getStatus() == ExchangeStatus.DONE) {
            return;
        } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
            if (endpoint.isRollbackOnError()) {
                TransactionManager tm = (TransactionManager) endpoint.getServiceUnit().getComponent()
                        .getComponentContext().getTransactionManager();
                tm.setRollbackOnly();
                return;
            } else if (exchange instanceof InOnly) {
                LOG.info("Exchange in error: " + exchange, exchange.getError());
                return;
            } else {
                connection = connectionFactory.createConnection();
                Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
                Exception error = exchange.getError();
                if (error == null) {
                    error = new Exception("Exchange in error");
                }
                response = session.createObjectMessage(error);
                MessageProducer producer = session.createProducer(message.getJMSReplyTo());
                if (endpoint.isUseMsgIdInResponse()) {
                    response.setJMSCorrelationID(message.getJMSMessageID());
                } else {
                    response.setJMSCorrelationID(message.getJMSCorrelationID());
                }
                producer.send(response);
            }
        } else {
            connection = connectionFactory.createConnection();
            Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
            response = fromNMSResponse(exchange, context, session);
            if (response != null) {
                MessageProducer producer = session.createProducer(message.getJMSReplyTo());
                if (endpoint.isUseMsgIdInResponse()) {
                    response.setJMSCorrelationID(message.getJMSMessageID());
                } else {
                    response.setJMSCorrelationID(message.getJMSCorrelationID());
                }
                producer.send(response);
            }
        }
    } finally {
        if (connection != null) {
            connection.close();
        }
        if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
            exchange.setStatus(ExchangeStatus.DONE);
            channel.send(exchange);
        }
    }
}

From source file:com.bitsofproof.supernode.core.ImplementBCSAPI.java

private void addBloomFilterListener() throws JMSException {
    addMessageListener("filterRequest", new MessageListener() {
        @Override//w  w w.  j  av  a  2s  .  c  o  m
        public void onMessage(Message msg) {
            BytesMessage o = (BytesMessage) msg;
            byte[] body;
            try {
                body = new byte[(int) o.getBodyLength()];
                o.readBytes(body);
                BCSAPIMessage.FilterRequest request = BCSAPIMessage.FilterRequest.parseFrom(body);
                byte[] data = request.getFilter().toByteArray();
                long hashFunctions = request.getHashFunctions();
                long tweak = request.getTweak();
                UpdateMode updateMode = UpdateMode.values()[request.getMode()];
                BloomFilter filter = new BloomFilter(data, hashFunctions, tweak, updateMode);
                synchronized (correlationBloomFilter) {
                    if (!correlationProducer.containsKey(o.getJMSCorrelationID())) {
                        MessageProducer producer = session.createProducer(msg.getJMSReplyTo());
                        correlationProducer.put(o.getJMSCorrelationID(), producer);
                    }
                    correlationBloomFilter.put(o.getJMSCorrelationID(), filter);
                }
            } catch (JMSException e) {
                log.error("invalid filter request", e);
            } catch (InvalidProtocolBufferException e) {
                log.error("invalid filter request", e);
            }
        }
    });
}

From source file:org.apache.axis2.transport.jms.JMSMessageReceiver.java

/**
 * Process the new message through Axis2
 *
 * @param message the JMS message/*  w  w  w .  j  a va2s .c om*/
 * @param ut      the UserTransaction used for receipt
 * @return true if the caller should commit
 * @throws JMSException, on JMS exceptions
 * @throws AxisFault     on Axis2 errors
 */
private boolean processThoughEngine(Message message, UserTransaction ut) throws JMSException, AxisFault {

    MessageContext msgContext = endpoint.createMessageContext();

    // set the JMS Message ID as the Message ID of the MessageContext
    try {
        msgContext.setMessageID(message.getJMSMessageID());
        String jmsCorrelationID = message.getJMSCorrelationID();
        if (jmsCorrelationID != null && jmsCorrelationID.length() > 0) {
            msgContext.setProperty(JMSConstants.JMS_COORELATION_ID, jmsCorrelationID);
        } else {
            msgContext.setProperty(JMSConstants.JMS_COORELATION_ID, message.getJMSMessageID());
        }
    } catch (JMSException ignore) {
    }

    String soapAction = JMSUtils.getProperty(message, BaseConstants.SOAPACTION);

    ContentTypeInfo contentTypeInfo = endpoint.getContentTypeRuleSet().getContentTypeInfo(message);
    if (contentTypeInfo == null) {
        throw new AxisFault("Unable to determine content type for message " + msgContext.getMessageID());
    }

    // set the message property OUT_TRANSPORT_INFO
    // the reply is assumed to be over the JMSReplyTo destination, using
    // the same incoming connection factory, if a JMSReplyTo is available
    Destination replyTo = message.getJMSReplyTo();
    if (replyTo == null) {
        // does the service specify a default reply destination ?
        String jndiReplyDestinationName = endpoint.getJndiReplyDestinationName();
        if (jndiReplyDestinationName != null) {
            replyTo = jmsConnectionFactory.getDestination(jndiReplyDestinationName,
                    endpoint.getReplyDestinationType());
        }

    }
    if (replyTo != null) {
        msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
                new JMSOutTransportInfo(jmsConnectionFactory, replyTo, contentTypeInfo.getPropertyName()));
    }

    JMSUtils.setSOAPEnvelope(message, msgContext, contentTypeInfo.getContentType());
    if (ut != null) {
        msgContext.setProperty(BaseConstants.USER_TRANSACTION, ut);
    }

    jmsListener.handleIncomingMessage(msgContext, JMSUtils.getTransportHeaders(message), soapAction,
            contentTypeInfo.getContentType());

    Object o = msgContext.getProperty(BaseConstants.SET_ROLLBACK_ONLY);
    if (o != null) {
        if ((o instanceof Boolean && ((Boolean) o)) || (o instanceof String && Boolean.valueOf((String) o))) {
            return false;
        }
    }
    return true;
}

From source file:org.apache.camel.component.jms.JmsBinding.java

public Map<String, Object> extractHeadersFromJms(Message jmsMessage, Exchange exchange) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (jmsMessage != null) {
        // lets populate the standard JMS message headers
        try {//from ww w.ja v a 2s.c  om
            map.put("JMSCorrelationID", jmsMessage.getJMSCorrelationID());
            map.put("JMSDeliveryMode", jmsMessage.getJMSDeliveryMode());
            map.put("JMSDestination", jmsMessage.getJMSDestination());
            map.put("JMSExpiration", jmsMessage.getJMSExpiration());
            map.put("JMSMessageID", jmsMessage.getJMSMessageID());
            map.put("JMSPriority", jmsMessage.getJMSPriority());
            map.put("JMSRedelivered", jmsMessage.getJMSRedelivered());
            map.put("JMSTimestamp", jmsMessage.getJMSTimestamp());

            // to work around OracleAQ not supporting the JMSReplyTo header (CAMEL-2909)
            try {
                map.put("JMSReplyTo", jmsMessage.getJMSReplyTo());
            } catch (JMSException e) {
                LOG.trace("Cannot read JMSReplyTo header. Will ignore this exception.", e);
            }
            // to work around OracleAQ not supporting the JMSType header (CAMEL-2909)
            try {
                map.put("JMSType", jmsMessage.getJMSType());
            } catch (JMSException e) {
                LOG.trace("Cannot read JMSType header. Will ignore this exception.", e);
            }

            // this works around a bug in the ActiveMQ property handling
            map.put("JMSXGroupID", jmsMessage.getStringProperty("JMSXGroupID"));
        } catch (JMSException e) {
            throw new RuntimeCamelException(e);
        }

        Enumeration names;
        try {
            names = jmsMessage.getPropertyNames();
        } catch (JMSException e) {
            throw new RuntimeCamelException(e);
        }
        while (names.hasMoreElements()) {
            String name = names.nextElement().toString();
            try {
                Object value = jmsMessage.getObjectProperty(name);
                if (headerFilterStrategy != null
                        && headerFilterStrategy.applyFilterToExternalHeaders(name, value, exchange)) {
                    continue;
                }

                // must decode back from safe JMS header name to original header name
                // when storing on this Camel JmsMessage object.
                String key = jmsKeyFormatStrategy.decodeKey(name);
                map.put(key, value);
            } catch (JMSException e) {
                throw new RuntimeCamelException(name, e);
            }
        }
    }

    return map;
}

From source file:org.openengsb.ports.jms.JMSIncomingPort.java

public void start() {
    simpleMessageListenerContainer = createListenerContainer(receive, new MessageListener() {
        @Override/*w  w  w  .  j  a v a2  s  . c om*/
        public void onMessage(Message message) {
            LOGGER.trace("JMS-message recieved. Checking if the type is supported");
            if (!(message instanceof TextMessage)) {
                LOGGER.debug("Received JMS-message is not type of text message.");
                return;
            }
            LOGGER.trace("Received a text message and start parsing");
            TextMessage textMessage = (TextMessage) message;
            String textContent = extractTextFromMessage(textMessage);
            HashMap<String, Object> metadata = new HashMap<String, Object>();
            String result = null;
            try {
                LOGGER.debug("starting filterchain for incoming message");
                result = (String) getFilterChainToUse().filter(textContent, metadata);
            } catch (Exception e) {
                LOGGER.error("an error occured when processing the filterchain", e);
                result = ExceptionUtils.getStackTrace(e);
            }
            Destination replyQueue;
            final String correlationID;
            try {
                if (message.getJMSCorrelationID() == null) {
                    correlationID = message.getJMSMessageID();
                } else {
                    correlationID = message.getJMSCorrelationID();
                }
                replyQueue = message.getJMSReplyTo();
            } catch (JMSException e) {
                LOGGER.warn("error when getting destination queue or correlationid from client message: {}", e);
                return;
            }
            if (replyQueue == null) {
                LOGGER.warn("no replyTo destination specifyed could not send response");
                return;
            }

            new JmsTemplate(connectionFactory).convertAndSend(replyQueue, result, new MessagePostProcessor() {
                @Override
                public Message postProcessMessage(Message message) throws JMSException {
                    message.setJMSCorrelationID(correlationID);
                    return message;
                }
            });
        }

        private String extractTextFromMessage(TextMessage textMessage) {
            try {
                return textMessage.getText();
            } catch (JMSException e) {
                throw new IllegalStateException("Couldn't extract text from jms message", e);
            }
        }

    });
    simpleMessageListenerContainer.start();
}

From source file:org.apache.axis2.transport.jms.JMSUtils.java

/**
 * Extract transport level headers for JMS from the given message into a Map
 *
 * @param message the JMS message/*from   w  ww  . j  a  v  a 2 s  .  c  om*/
 * @return a Map of the transport headers
 */
public static Map<String, Object> getTransportHeaders(Message message) {
    // create a Map to hold transport headers
    Map<String, Object> map = new HashMap<String, Object>();

    // 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, message.getBooleanProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getIntProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getLongProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getDoubleProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getFloatProperty(headerName));
            } catch (JMSException ignore) {
            }
        }
    }

    return map;
}

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/* www . ja v  a 2  s .c  o  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.jbpm.ejb.CommandListenerBean.java

public void onMessage(Message message) {
    try {/*w ww .  ja  v a 2  s .  c o m*/
        // extract command from message
        Command command = extractCommand(message);
        // a null return value means the message did not carry a valid command
        // warnings were logged already; just swallow the message and return 
        if (command == null)
            return;

        // execute command via local command executor bean
        Object result;
        try {
            if (log.isDebugEnabled()) {
                log.debug("executing " + command);
            }
            result = commandService.execute(command);

            if (log.isTraceEnabled()) {
                log.trace(command + " completed successfully, committing");
            }
        } catch (RuntimeException e) {
            // if this is a locking exception, keep it quiet
            if (DbPersistenceService.isLockingException(e)) {
                StaleObjectLogConfigurer.getStaleObjectExceptionsLog()
                        .error(message + " failed to execute " + command, e);
            } else {
                log.error(message + " failed to execute " + command, e);
            }
            // MDBs are not supposed to throw exceptions
            messageDrivenContext.setRollbackOnly();
            return;
        }

        // send a response back if a "reply to" destination is set
        Destination replyTo;
        if (jmsConnectionFactory != null && (replyTo = message.getJMSReplyTo()) != null
                && (result instanceof Serializable || result == null)) {
            sendResult((Serializable) result, replyTo, message.getJMSMessageID());
        }
    } catch (JMSException e) {
        messageDrivenContext.setRollbackOnly();
        log.error("failed to process message " + message, e);
    }
}