Example usage for javax.jms Message toString

List of usage examples for javax.jms Message toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:example.tempdest.ProducerRequestReply.java

public static void main(String[] args) {
    String url = BROKER_URL;
    if (args.length > 0) {
        url = args[0].trim();/*from  w ww .j  a v a 2  s. c o m*/
    }
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", url);
    Connection connection = null;

    try {

        connection = connectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createQueue("test-queue");
        MessageProducer producer = session.createProducer(destination);
        Destination replyDest = session.createTemporaryQueue();

        // set up the consumer to handle the reply
        MessageConsumer replyConsumer = session.createConsumer(replyDest);
        replyConsumer.setMessageListener(new MessageListener() {
            @Override
            public void onMessage(Message message) {
                System.out.println("*** REPLY *** ");
                System.out.println(message.toString());
            }
        });

        TextMessage message = session.createTextMessage("I need a response for this, please");
        message.setJMSReplyTo(replyDest);

        producer.send(message);

        // wait for a response
        TimeUnit.SECONDS.sleep(2);
        producer.close();
        session.close();

    } catch (Exception e) {
        System.out.println("Caught exception!");
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                System.out.println("Could not close an open connection...");
            }
        }
    }
}

From source file:org.vbossica.azurebox.servicebus.amqp.ClientConnectionIT.java

@Test
public void send_and_receive_with_destination() {
    template.send(destination, new MessageCreator() {
        @Override/*  www  .j  a  v a2 s .  c o m*/
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage("hello world (2)");
        }
    });
    Message msg = template.receive(destination);
    System.out.println(msg.toString());
}

From source file:org.vbossica.azurebox.servicebus.amqp.ClientConnectionIT.java

@Test
public void send_and_receive() {
    template.send(destinationName, new MessageCreator() {
        @Override/* w  w  w.  ja  v  a 2s .  c  o  m*/
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage("hello world");
        }
    });
    Message msg = template.receive(destinationName);
    System.out.println(msg.toString());
}

From source file:dk.netarkivet.monitor.distribute.MonitorMessageHandler.java

/**
 * Unpacks and calls accept() on the message object.
 *
 * This method catches <b>all</b> exceptions and logs them.
 *
 * @param msg a ObjectMessage//from w w w. j  a v  a  2s .c om
 *
 */
public void onMessage(Message msg) {
    ArgumentNotValid.checkNotNull(msg, "Message msg");
    log.trace("Message received:\n" + msg.toString());
    try {
        ((MonitorMessage) JMSConnection.unpack(msg)).accept(this);
    } catch (ClassCastException e) {
        log.warn("Invalid message type", e);
    } catch (Throwable e) {
        log.warn("Error processing message '" + msg + "'", e);
    }
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.batch.msg.consumer.DeleteDocMessageConsumer.java

@Override
public void handleMessage(Message message) {
    if (isTextMessageInvalid(message)) {
        logger.error("message is invalid and was not processed: {}", message.toString());
        return;//from  ww w  .j  a v a 2  s.c o m
    }

    TaxonomyDocumentMessageHolder deleteDocumentMessage = getTaxonomyDocumentMessageFromMessage(message);

    logger.info("received Delete Document message: {}, docReferences: {}", deleteDocumentMessage.getMessageId(),
            ArrayUtils.toString(deleteDocumentMessage.getListOfDocReferences()));

    for (String docReference : deleteDocumentMessage.getListOfDocReferences()) {
        try {
            removeDocumentFromMongoByDocReference(docReference);
        } catch (TaxonomyException e) {
            deleteDocumentMessage.addDocReferenceInError(docReference);
            logger.error("an error occured while processing Document: {}, from message: {}", docReference,
                    deleteDocumentMessage.getMessageId(), e);
        }
    }

    if (deleteDocumentMessage.hasProcessingErrors()) {
        logger.warn("completed treatment for message: {} with {} errors", deleteDocumentMessage.getMessageId(),
                deleteDocumentMessage.getListOfDocReferencesInError().size());
        logger.error("DOCREFERENCES that raise an issue while deleting: {}",
                Arrays.toString(deleteDocumentMessage.getListOfDocReferencesInError().toArray()));
    } else {
        logger.info("completed treatment for message: {}", deleteDocumentMessage.getMessageId());
    }
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.batch.msg.consumer.CategoriseDocMessageConsumer.java

@Override
public void handleMessage(Message message) {
    if (isTextMessageInvalid(message)) {
        logger.error("message is invalid and was not processed: {}", message.toString());
        return;// w  ww. j  a  va  2  s  .  c om
    }

    TaxonomyDocumentMessageHolder categoriseDocumentMessage = getTaxonomyDocumentMessageFromMessage(message);

    logger.info("received Categorise Document message: {}, docReferences: {}",
            categoriseDocumentMessage.getMessageId(),
            ArrayUtils.toString(categoriseDocumentMessage.getListOfDocReferences()));

    categoriserService.refreshTaxonomyIndex();

    for (String docReference : categoriseDocumentMessage.getListOfDocReferences()) {
        try {
            categoriserService.categoriseSingle(docReference);
        } catch (TaxonomyException e) {
            categoriseDocumentMessage.addDocReferenceInError(docReference);
            if (TaxonomyErrorType.DOC_NOT_FOUND.equals(e.getTaxonomyErrorType())) {
                logger.error(
                        "document could not be processed because it was not found in the index: {}, from message: {}",
                        docReference, categoriseDocumentMessage.getMessageId());
            } else {
                logger.error("an error occured while processing Document: {}, from message: {}", docReference,
                        categoriseDocumentMessage.getMessageId(), e);
            }
        }
    }

    if (categoriseDocumentMessage.hasProcessingErrors()) {
        logger.warn("completed treatment for message: {} with {} errors",
                categoriseDocumentMessage.getMessageId(),
                categoriseDocumentMessage.getListOfDocReferencesInError().size());
        logger.error("DOCREFERENCES THAT COULD NOT BE CATEGORISED: {}",
                Arrays.toString(categoriseDocumentMessage.getListOfDocReferencesInError().toArray()));
    } else {
        logger.info("completed treatment for message: {}", categoriseDocumentMessage.getMessageId());
    }
}

From source file:org.fuin.auction.query.server.AuctionMessageListener.java

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public final void onMessage(final Message message) {

    if (LOG.isDebugEnabled()) {
        LOG.debug(message.toString());
    }//from  ww w . java 2 s.  c  o m

    try {

        if (message instanceof ObjectMessage) {
            final ObjectMessage objectMessage = (ObjectMessage) message;
            try {
                final Serializable obj = objectMessage.getObject();
                if (obj instanceof CategoryCreatedMessage) {
                    handleMessage((CategoryCreatedMessage) obj);
                } else if (obj instanceof CategoryMarkedForDeletionMessage) {
                    handleMessage((CategoryMarkedForDeletionMessage) obj);
                } else if (obj instanceof CategoryDeletedMessage) {
                    handleMessage((CategoryDeletedMessage) obj);
                } else if (obj instanceof UserRegisteredMessage) {
                    handleMessage((UserRegisteredMessage) obj);
                } else if (obj instanceof UserEmailVerifiedMessage) {
                    handleMessage((UserEmailVerifiedMessage) obj);
                } else if (obj instanceof UserPasswordChangedMessage) {
                    handleMessage((UserPasswordChangedMessage) obj);
                } else {
                    LOG.warn("Received non-Auction message: " + obj);
                }
            } catch (final JMSException ex) {
                LOG.error("Error reading object from message", ex);
            }
        } else {
            LOG.warn("Received non-Object message: " + message);
        }

    } catch (final RuntimeException ex) {
        LOG.error("Error handling message", ex);
    }

}

From source file:dk.netarkivet.harvester.distribute.HarvesterMessageHandler.java

/**
 * Unpacks and calls accept() on the message object.
 *
 * This method catches <b>all</b> exceptions and logs them.
 *
 * @param msg an ObjectMessage/* www.  j  a va2  s  . co  m*/
 */
@Override
public void onMessage(Message msg) {
    ArgumentNotValid.checkNotNull(msg, "msg");
    log.trace("Message received:\n" + msg.toString());
    try {
        NetarkivetMessage unpackedMsg = JMSConnection.unpack(msg);
        ((HarvesterMessage) unpackedMsg).accept(this);
    } catch (Throwable e) {
        log.warn("Error processing message '" + msg + "'", e);
    }
}

From source file:dk.netarkivet.archive.distribute.ArchiveMessageHandler.java

/**
 * Unpacks and calls accept() on the message object.
 *
 * This method catches <b>all</b> exceptions and logs them.
 *
 * @param msg a ObjectMessage//from  w  w  w .  ja  v  a 2 s  .c  om
 *
 */
public void onMessage(Message msg) {
    ArgumentNotValid.checkNotNull(msg, "Message msg");
    log.trace("Message received:\n" + msg.toString());
    try {
        ((ArchiveMessage) JMSConnection.unpack(msg)).accept(this);
    } catch (ClassCastException e) {
        log.warn("Invalid message type", e);
    } catch (Throwable e) {
        log.warn("Error processing message '" + msg + "'", e);
    }
}

From source file:org.chtijbug.drools.platform.backend.jms.JMSHistoryEventListener.java

@Transactional
public void onMessage(Message message) {
    HistoryEvent historyEvent = null;// w  w  w  .  j a v a  2s.  co m
    try {
        if (message instanceof ObjectMessage) {
            ObjectMessage objectMessage = (ObjectMessage) message;
            Object messageContent = objectMessage.getObject();
            historyEvent = (HistoryEvent) messageContent;
            try {
                AbstractEventHandlerStrategy strategy = messageHandlerResolver
                        .resolveMessageHandler(historyEvent);
                strategy.handleMessage(historyEvent);
            } catch (Throwable e) {
                throw Throwables.propagate(e);
            }
            ObjectMessage msg = (ObjectMessage) message;
            LOG.debug("Consumed message: " + msg.toString());
        }
    } catch (Exception e) {
        LOG.error("Consumed message: " + e.toString() + " message content " + message.toString());
        LOG.error("                  message  " + message.toString());
        LOG.error("                  object content " + historyEvent.toString());

    }
}