Example usage for javax.jms JMSException getMessage

List of usage examples for javax.jms JMSException getMessage

Introduction

In this page you can find the example usage for javax.jms JMSException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.cws.esolutions.core.utils.MQUtils.java

/**
 * Gets an MQ message off a specified queue and returns it as an
 * <code>Object</code> to the requestor for further processing.
 *
 * @param connName - The connection name to utilize
 * @param authData - The authentication data to utilize, if required
 * @param responseQueue - The request queue name to put the message on
 * @param timeout - How long to wait for a connection or response
 * @param messageId - The JMS correlation ID of the message the response is associated with
 * @return <code>Object</code> - The serializable data returned by the MQ request
 * @throws UtilityException {@link com.cws.esolutions.core.utils.exception.UtilityException} if an error occurs processing
 *///from  w ww  . j a v a  2s .c  om
public static final synchronized Object getMqMessage(final String connName, final List<String> authData,
        final String responseQueue, final long timeout, final String messageId) throws UtilityException {
    final String methodName = MQUtils.CNAME
            + "getMqMessage(final String connName, final List<String> authData, final String responseQueue, final long timeout, final String messageId) throws UtilityException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", connName);
        DEBUGGER.debug("Value: {}", responseQueue);
        DEBUGGER.debug("Value: {}", timeout);
        DEBUGGER.debug("Value: {}", messageId);
    }

    Connection conn = null;
    Session session = null;
    Object response = null;
    Context envContext = null;
    MessageConsumer consumer = null;
    ConnectionFactory connFactory = null;

    try {
        try {
            InitialContext initCtx = new InitialContext();
            envContext = (Context) initCtx.lookup(MQUtils.INIT_CONTEXT);

            connFactory = (ConnectionFactory) envContext.lookup(connName);
        } catch (NamingException nx) {
            // we're probably not in a container
            connFactory = new ActiveMQConnectionFactory(connName);
        }

        if (DEBUG) {
            DEBUGGER.debug("ConnectionFactory: {}", connFactory);
        }

        if (connFactory == null) {
            throw new UtilityException("Unable to create connection factory for provided name");
        }

        // Create a Connection
        conn = connFactory.createConnection(authData.get(0),
                PasswordUtils.decryptText(authData.get(1), authData.get(2), authData.get(3),
                        Integer.parseInt(authData.get(4)), Integer.parseInt(authData.get(5)), authData.get(6),
                        authData.get(7), authData.get(8)));
        conn.start();

        if (DEBUG) {
            DEBUGGER.debug("Connection: {}", conn);
        }

        // Create a Session
        session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

        if (DEBUG) {
            DEBUGGER.debug("Session: {}", session);
        }

        if (envContext != null) {
            try {
                consumer = session.createConsumer((Destination) envContext.lookup(responseQueue),
                        "JMSCorrelationID='" + messageId + "'");
            } catch (NamingException nx) {
                throw new UtilityException(nx.getMessage(), nx);
            }
        } else {
            Destination destination = session.createQueue(responseQueue);

            if (DEBUG) {
                DEBUGGER.debug("Destination: {}", destination);
            }

            consumer = session.createConsumer(destination, "JMSCorrelationID='" + messageId + "'");
        }

        if (DEBUG) {
            DEBUGGER.debug("MessageConsumer: {}", consumer);
        }

        ObjectMessage message = (ObjectMessage) consumer.receive(timeout);

        if (DEBUG) {
            DEBUGGER.debug("ObjectMessage: {}", message);
        }

        if (message == null) {
            throw new UtilityException("Failed to retrieve message within the timeout specified.");
        }

        response = message.getObject();
        message.acknowledge();

        if (DEBUG) {
            DEBUGGER.debug("Object: {}", response);
        }
    } catch (JMSException jx) {
        throw new UtilityException(jx.getMessage(), jx);
    } finally {
        try {
            // Clean up
            if (!(session == null)) {
                session.close();
            }

            if (!(conn == null)) {
                conn.close();
                conn.stop();
            }
        } catch (JMSException jx) {
            ERROR_RECORDER.error(jx.getMessage(), jx);
        }
    }

    return response;
}

From source file:com.cws.esolutions.core.utils.MQUtils.java

/**
 * Puts an MQ message on a specified queue and returns the associated
 * correlation ID for retrieval upon request.
 *
 * @param connName - The connection name to utilize
 * @param authData - The authentication data to utilize, if required
 * @param requestQueue - The request queue name to put the message on
 * @param targetHost - The target host for the message
 * @param value - The data to place on the request. MUST be <code>Serialiable</code>
 * @return <code>String</code> - the JMS correlation ID associated with the message
 * @throws UtilityException {@link com.cws.esolutions.core.utils.exception.UtilityException} if an error occurs processing
 *//*from ww w .j av  a 2 s  .  c om*/
public static final synchronized String sendMqMessage(final String connName, final List<String> authData,
        final String requestQueue, final String targetHost, final Serializable value) throws UtilityException {
    final String methodName = MQUtils.CNAME
            + "sendMqMessage(final String connName, final List<String> authData, final String requestQueue, final String targetHost, final Serializable value) throws UtilityException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", connName);
        DEBUGGER.debug("Value: {}", requestQueue);
        DEBUGGER.debug("Value: {}", targetHost);
        DEBUGGER.debug("Value: {}", value);
    }

    Connection conn = null;
    Session session = null;
    Context envContext = null;
    InitialContext initCtx = null;
    MessageProducer producer = null;
    ConnectionFactory connFactory = null;

    final String correlationId = RandomStringUtils.randomAlphanumeric(64);

    if (DEBUG) {
        DEBUGGER.debug("correlationId: {}", correlationId);
    }

    try {
        try {
            initCtx = new InitialContext();
            envContext = (Context) initCtx.lookup(MQUtils.INIT_CONTEXT);

            connFactory = (ConnectionFactory) envContext.lookup(connName);
        } catch (NamingException nx) {
            // we're probably not in a container
            connFactory = new ActiveMQConnectionFactory(connName);
        }

        if (DEBUG) {
            DEBUGGER.debug("ConnectionFactory: {}", connFactory);
        }

        if (connFactory == null) {
            throw new UtilityException("Unable to create connection factory for provided name");
        }

        // Create a Connection
        conn = connFactory.createConnection(authData.get(0),
                PasswordUtils.decryptText(authData.get(1), authData.get(2), authData.get(3),
                        Integer.parseInt(authData.get(4)), Integer.parseInt(authData.get(5)), authData.get(6),
                        authData.get(7), authData.get(8)));
        conn.start();

        if (DEBUG) {
            DEBUGGER.debug("Connection: {}", conn);
        }

        // Create a Session
        session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

        if (DEBUG) {
            DEBUGGER.debug("Session: {}", session);
        }

        // Create a MessageProducer from the Session to the Topic or Queue
        if (envContext != null) {
            try {
                producer = session.createProducer((Destination) envContext.lookup(requestQueue));
            } catch (NamingException nx) {
                throw new UtilityException(nx.getMessage(), nx);
            }
        } else {
            Destination destination = session.createTopic(requestQueue);

            if (DEBUG) {
                DEBUGGER.debug("Destination: {}", destination);
            }

            producer = session.createProducer(destination);
        }

        if (producer == null) {
            throw new JMSException("Failed to create a producer object");
        }

        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

        if (DEBUG) {
            DEBUGGER.debug("MessageProducer: {}", producer);
        }

        ObjectMessage message = session.createObjectMessage(true);
        message.setJMSCorrelationID(correlationId);
        message.setStringProperty("targetHost", targetHost);

        if (DEBUG) {
            DEBUGGER.debug("correlationId: {}", correlationId);
        }

        message.setObject(value);

        if (DEBUG) {
            DEBUGGER.debug("ObjectMessage: {}", message);
        }

        producer.send(message);
    } catch (JMSException jx) {
        throw new UtilityException(jx.getMessage(), jx);
    } finally {
        try {
            // Clean up
            if (!(session == null)) {
                session.close();
            }

            if (!(conn == null)) {
                conn.close();
                conn.stop();
            }
        } catch (JMSException jx) {
            ERROR_RECORDER.error(jx.getMessage(), jx);
        }
    }

    return correlationId;
}

From source file:org.fao.geonet.jms.ClusterConfig.java

/**
 * Closes all Producers and Consumers.// ww w  .j  ava2 s  . co m
 *
 * @throws ClusterException hmm
 */
public static void shutdown() throws ClusterException {
    for (JMSActor participant : jmsActors) {
        // Capture exceptions to continue closing the rest of JMSActors.
        // Exceptions are logged in JMSActor.shutdown
        try {
            participant.shutdown();
        } catch (ClusterException ex) {

        }

    }

    // Close session and connection
    try {
        if (session != null)
            session.close();
        if (connection != null)
            connection.close();

    } catch (JMSException x) {
        Log.error(Geonet.JMS, x.getMessage());
        x.printStackTrace();
        throw new ClusterException(x.getMessage(), x);
    }
}

From source file:org.fao.geonet.jms.ClusterConfig.java

private static void initJMSConnection() throws ClusterException {
    try {//from w w w .  jav  a 2 s  .c o m
        // Getting JMS connection from the server
        System.out.println("Getting JMS Connection");
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ClusterConfig.getBrokerURL());
        connection = connectionFactory.createConnection();
        connection.setClientID(ClusterConfig.getClientID());
        connection.start();

        // Creating session for sending and receiving messages
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        // Set connection and session for all JMSActors
        JMSActor.connection = connection;
        JMSActor.session = session;
        System.out.println("Getiing JMS Connection successfull");
    } catch (JMSException x) {
        System.out.println("Getiing JMS Connection failed");
        System.err.println(x.getMessage());
        x.printStackTrace();
        throw new ClusterException(x.getMessage(), x);
    }
}

From source file:uk.co.jassoft.jms.listener.JmsExceptionListener.java

@Override
public void onException(final JMSException exception) {
    LOG.error(exception.getMessage(), exception);
}

From source file:org.apache.stratos.adc.topology.mgt.subscriber.TopologyListener.java

@SuppressWarnings("unchecked")
public void onMessage(Message message) {
    TextMessage receivedMessage = (TextMessage) message;
    try {//  w w  w  .ja  v  a2 s.  c o m

        ConfigHolder.getInstance().getSharedTopologyDiffQueue().add(receivedMessage.getText());

    } catch (JMSException e) {
        log.error(e.getMessage(), e);
    }

}

From source file:org.apache.stratos.lb.endpoint.subscriber.TopologyListener.java

@Override
public void onMessage(Message message) {
    TextMessage receivedMessage = (TextMessage) message;
    try {/* w w  w.j av  a  2 s .  com*/

        ConfigHolder.getInstance().getSharedTopologyDiffQueue().add(receivedMessage.getText());

    } catch (JMSException e) {
        log.error(e.getMessage(), e);
    }

}

From source file:org.hoteia.qalingo.core.jms.cms.listener.CmsQueueListener.java

/**
 * Implementation of <code>MessageListener</code>.
 */// w w w .j a v  a2  s .co m
public void onMessage(Message message) {
    try {
        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            String valueJMSMessage = tm.getText();
            if (logger.isDebugEnabled()) {
                logger.debug("Processed message, value: " + valueJMSMessage);
            }
        }
    } catch (JMSException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:org.apache.stratos.autoscaler.message.receiver.topology.TopologyEventMessageListener.java

@Override
public void onMessage(Message message) {
    if (message instanceof TextMessage) {
        TextMessage receivedMessage = (TextMessage) message;
        try {//ww w. j  a  v  a2s . c o  m
            if (log.isDebugEnabled()) {
                log.debug(String.format("Topology message received: %s", ((TextMessage) message).getText()));
            }
            // Add received message to the queue
            TopologyEventMessageQueue.getInstance().add(receivedMessage);

        } catch (JMSException e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:org.apache.stratos.messaging.message.receiver.topology.TopologyEventMessageListener.java

@Override
public void onMessage(Message message) {
    if (message instanceof TextMessage) {
        TextMessage receivedMessage = (TextMessage) message;
        try {/*from  w ww.  j  a v  a2s.  c  o  m*/
            if (log.isDebugEnabled()) {
                log.debug(String.format("Topology message received: %s", ((TextMessage) message).getText()));
            }
            // Add received message to the queue
            messageQueue.add(receivedMessage);

        } catch (JMSException e) {
            log.error(e.getMessage(), e);
        }
    }
}