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:net.timewalker.ffmq4.admin.RemoteAdministrationThread.java

private String process(Message msg) {
    try {/* w ww .  j a va 2 s  . c  om*/
        String command = msg.getStringProperty(FFMQAdminConstants.ADM_HEADER_COMMAND);
        if (StringTools.isEmpty(command))
            return "Administration command not set in message header";

        // Dispatch
        if (command.equals(FFMQAdminConstants.ADM_COMMAND_CREATE_QUEUE))
            return processCreateQueue(msg);

        if (command.equals(FFMQAdminConstants.ADM_COMMAND_CREATE_TOPIC))
            return processCreateTopic(msg);

        if (command.equals(FFMQAdminConstants.ADM_COMMAND_DELETE_QUEUE))
            return processDeleteQueue(msg);

        if (command.equals(FFMQAdminConstants.ADM_COMMAND_DELETE_TOPIC))
            return processDeleteTopic(msg);

        if (command.equals(FFMQAdminConstants.ADM_COMMAND_PURGE_QUEUE))
            return processPurgeQueue(msg);

        if (command.equals(FFMQAdminConstants.ADM_COMMAND_SHUTDOWN))
            return processShutdown();

        log.error("Invalid administration command : " + command);
        return "Invalid administration command : " + command;
    } catch (JMSException e) {
        ErrorTools.log(e, log);
        return "Error processing administration command : " + e.getMessage();
    } catch (Exception e) {
        ErrorTools.log(new FFMQException("Cannot process admin message", "INVALID_ADMIN_MESSAGE", e), log);
        return "Error processing administration command : " + e.getMessage();
    }
}

From source file:org.codice.pubsub.stomp.SubscriptionQueryMessageListener.java

public void destroy() {
    try {/*from  ww w . j  a v  a 2 s.c  o  m*/
        consumer.close();
        session.close();
        connection.stop();
        connection.close();
        consumer = null;
        session = null;
        connection = null;
        timer.cancel();
        timer.purge();
        subServerWorker.interrupt();
    } catch (JMSException e) {
        LOGGER.error(e.getMessage());
    }
}

From source file:com.mirth.connect.connectors.jms.transformers.MessageObjectToJMSMessage.java

public Object doTransform(Object src) throws TransformerException {

    if (src instanceof MessageObject) {
        MessageObject messageObject = (MessageObject) src;
        if (messageObject.getStatus().equals(MessageObject.Status.FILTERED)) {
            return null;
        }//from  ww w .  j  a  v a2 s.  c o  m
        String template = replacer.replaceValues(connector.getTemplate(), messageObject);
        Message message = transformToMessage(template);
        try {
            message.setStringProperty("MIRTH_MESSAGE_ID", messageObject.getId());
        } catch (JMSException e) {
            //Various Jms servers have slightly different rules to what can be set as an object property on the message
            //As such we have to take a hit n' hope approach
            if (logger.isDebugEnabled())
                logger.debug(
                        "Unable to set property '" + encodeHeader("MIRTH_MESSAGE_ID") + "': " + e.getMessage());
        }
        return message;
    }
    return null;
}

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

public Destination createDestination(Session session, String name, boolean topic, ImmutableEndpoint endpoint)
        throws JMSException {
    if (connector.isJndiDestinations()) {
        try {/*  w  w w.  j a v a2  s .co m*/
            Destination dest = getJndiDestination(name);
            if (dest != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug(
                            MessageFormat.format("Destination {0} located in JNDI, will use it now", name));
                }
                return dest;
            } else {
                throw new JMSException("JNDI destination not found with name: " + name);
            }
        } catch (JMSException e) {
            if (connector.isForceJndiDestinations()) {
                throw e;
            } else {
                logger.warn("Unable to look up JNDI destination " + name + ": " + e.getMessage());
            }
        }
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Using non-JNDI destination " + name + ", will create one now");
    }

    if (session == null) {
        throw new IllegalArgumentException("Session cannot be null when creating a destination");
    }
    if (name == null) {
        throw new IllegalArgumentException("Destination name cannot be null when creating a destination");
    }

    if (topic) {
        return session.createTopic(name);
    } else {
        return session.createQueue(name);
    }
}

From source file:org.jwebsocket.jms.endpoint.JMSEndPointSender.java

/**
 *
 * @param aTargetId//  www  . j a v a2s. com
 * @param aCorrelationID
 * @param aText
 * @param aResponseListener
 * @param aTimeout
 */
public synchronized void sendText(String aTargetId, final String aCorrelationID, final String aText,
        IJMSResponseListener aResponseListener, long aTimeout) {
    Message lMsg;
    try {
        lMsg = mSession.createTextMessage(aText);
        if (null != aCorrelationID) {
            lMsg.setJMSCorrelationID(aCorrelationID);
        }
        lMsg.setStringProperty("targetId", aTargetId);
        lMsg.setStringProperty("sourceId", mEndPointId);

        if (mLog.isDebugEnabled()) {
            StringBuilder lPropStr = new StringBuilder();
            Enumeration lPropNames = lMsg.getPropertyNames();
            while (lPropNames.hasMoreElements()) {
                String lPropName = (String) lPropNames.nextElement();
                Object lValue = lMsg.getObjectProperty(lPropName);
                lPropStr.append(lPropName).append("=").append(lValue);
                if (lPropNames.hasMoreElements()) {
                    lPropStr.append(", ");
                }
            }
            mLog.debug("Sending text to '" + aTargetId + "': "
                    + (JMSLogging.isFullTextLogging() ? aText
                            : "[content suppressed, length: " + aText.length() + " bytes]")
                    + ", props: " + lPropStr + "...");
        }

        // processing callbacks
        if (null != aResponseListener) {
            Assert.notNull(aCorrelationID, "The 'correlationID' argument cannot be null!");
            Assert.isTrue(aTimeout > 0, "Invalid 'timeout' argument. Expecting 'timeout' > 0");
            // setting the expiration time
            lMsg.setJMSExpiration(aTimeout);

            // saving the callback 
            mResponseListeners.put(aCorrelationID, aResponseListener);

            // schedule the timer task
            Tools.getTimer().schedule(new JWSTimerTask() {
                @Override
                public void runTask() {
                    Thread lThread = new Thread() {
                        @Override
                        public void run() {
                            IJMSResponseListener lListener = mResponseListeners.remove(aCorrelationID);
                            if (null != lListener) {
                                lListener.onTimeout();
                            }
                        }
                    };
                    lThread.setName("JMSEndPointSender Timeout Thread");
                    Tools.getThreadPool().submit(lThread);
                }
            }, aTimeout);
        }

        mProducer.send(lMsg);

    } catch (JMSException lEx) {
        mLog.error(lEx.getClass().getSimpleName() + " sending message: " + lEx.getMessage() + " "
                + ExceptionUtils.getStackTrace(lEx));
    }
}

From source file:org.codice.pubsub.stomp.SubscriptionQueryMessageListener.java

private void execute() {

    StompJmsConnectionFactory factory = new StompJmsConnectionFactory();

    factory.setBrokerURI("tcp://" + stompHost + ":" + stompPort);

    try {/* w w  w  .j ava2 s.com*/
        connection = factory.createConnection(user, password);
        connection.start();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination dest = new StompJmsDestination(destTopicName);
        consumer = session.createConsumer(dest);

        while (!Thread.currentThread().isInterrupted()) {
            Message msg = consumer.receive();
            if (msg instanceof TextMessage) {
                String body = ((TextMessage) msg).getText();
                processMessage(body);

            } else if (msg instanceof StompJmsBytesMessage) {
                //Non-ActiveMQ STOMP client implementations end up here
                StompJmsBytesMessage byteMsg = (StompJmsBytesMessage) msg;

                long len = ((StompJmsBytesMessage) msg).getBodyLength();

                byte[] byteArr = new byte[(int) byteMsg.getBodyLength()];

                for (int i = 0; i < (int) byteMsg.getBodyLength(); i++) {
                    byteArr[i] = byteMsg.readByte();
                }
                String msgStr = new String(byteArr);
                processMessage(msgStr);
            } else {
            }
        }

        //stop the connection
        destroy();
    } catch (JMSException e) {
        LOGGER.error(e.getMessage());
    }
}

From source file:org.wso2.extension.siddhi.io.jms.source.client.JMSClient.java

public void sendJMSEvents(String filePath, String topicName, String queueName, String format, String broker,
        String providerURL) {/*from  ww  w  .j  av a  2s .co  m*/
    if (format == null || "map".equals(format)) {
        format = "csv";
    }
    if ("".equalsIgnoreCase(broker)) {
        broker = "activemq";
    }
    Session session = null;
    Properties properties = new Properties();
    if (!"activemq".equalsIgnoreCase(broker) && !"mb".equalsIgnoreCase(broker)
            && !"qpid".equalsIgnoreCase(broker)) {
        log.error("Please enter a valid JMS message broker. (ex: activemq, mb, qpid");
        return;
    }
    try {
        if (topicName != null && !"".equalsIgnoreCase(topicName)) {
            TopicConnection topicConnection;
            TopicConnectionFactory connFactory = null;
            if ("activemq".equalsIgnoreCase(broker)) {
                properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties"));
                // to provide custom provider urls
                if (providerURL != null) {
                    properties.put(Context.PROVIDER_URL, providerURL);
                }
                Context context = new InitialContext(properties);
                connFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory");
            } else if ("mb".equalsIgnoreCase(broker)) {
                properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("mb.properties"));
                Context context = new InitialContext(properties);
                connFactory = (TopicConnectionFactory) context.lookup("qpidConnectionFactory");
            } else if ("qpid".equalsIgnoreCase(broker)) {
                properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("qpid.properties"));
                Context context = new InitialContext(properties);
                connFactory = (TopicConnectionFactory) context.lookup("qpidConnectionFactory");
            }
            if (connFactory != null) {
                topicConnection = connFactory.createTopicConnection();
                topicConnection.start();
                session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
                if (session != null) {
                    Topic topic = session.createTopic(topicName);
                    MessageProducer producer = session.createProducer(topic);
                    List<String> messagesList = JMSClientUtil.readFile(filePath);
                    try {
                        if ("csv".equalsIgnoreCase(format)) {
                            log.info("Sending Map messages on '" + topicName + "' topic");
                            JMSClientUtil.publishMapMessage(producer, session, messagesList);

                        } else {
                            log.info("Sending  " + format + " messages on '" + topicName + "' topic");
                            JMSClientUtil.publishTextMessage(producer, session, messagesList);
                        }
                        log.info("All Order Messages sent");
                    } catch (JMSException e) {
                        log.error("Cannot subscribe." + e.getMessage(), e);
                    } catch (IOException e) {
                        log.error("Error when reading the data file." + e.getMessage(), e);
                    } finally {
                        producer.close();
                        session.close();
                        topicConnection.stop();
                    }
                }
            } else {
                log.error("Error when creating connection factory. Please check necessary jar files");
            }
        } else if (queueName != null && !queueName.equalsIgnoreCase("")) {
            QueueConnection queueConnection;
            QueueConnectionFactory connFactory = null;
            if ("activemq".equalsIgnoreCase(broker)) {
                properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties"));
                Context context = new InitialContext(properties);
                connFactory = (QueueConnectionFactory) context.lookup("ConnectionFactory");
            } else if ("mb".equalsIgnoreCase(broker)) {
                properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("mb.properties"));
                Context context = new InitialContext(properties);
                connFactory = (QueueConnectionFactory) context.lookup("qpidConnectionFactory");
            } else if ("qpid".equalsIgnoreCase(broker)) {
                properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("qpid.properties"));
                Context context = new InitialContext(properties);
                connFactory = (QueueConnectionFactory) context.lookup("qpidConnectionFactory");
            }
            if (connFactory != null) {
                queueConnection = connFactory.createQueueConnection();
                queueConnection.start();
                session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                if (session != null) {
                    Queue queue = session.createQueue(queueName);
                    MessageProducer producer = session.createProducer(queue);
                    List<String> messagesList = JMSClientUtil.readFile(filePath);
                    try {
                        if ("csv".equalsIgnoreCase(format)) {
                            log.info("Sending Map messages on '" + queueName + "' queue");
                            JMSClientUtil.publishMapMessage(producer, session, messagesList);

                        } else {
                            log.info("Sending  " + format + " messages on '" + queueName + "' queue");
                            JMSClientUtil.publishTextMessage(producer, session, messagesList);
                        }
                    } catch (JMSException e) {
                        log.error("Cannot subscribe." + e.getMessage(), e);
                    } catch (IOException e) {
                        log.error("Error when reading the data file." + e.getMessage(), e);
                    } finally {
                        producer.close();
                        session.close();
                        queueConnection.stop();
                    }
                }
            } else {
                log.error("Error when creating connection factory. Please check necessary jar files");
            }
        } else {
            log.error("Enter queue name or topic name to be published!");
        }
    } catch (Exception e) {
        log.error("Error when publishing" + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.bpmn.extensions.jms.JMSConnectionFactory.java

/**
 *
 * @return the shared connection object/*w w w  .j a  va 2  s  .  c  om*/
 */
private synchronized Connection getSharedConnection() {

    Connection connection = sharedConnectionMap.get(lastReturnedConnectionIndex);

    //int connectionIndex = lastReturnedConnectionIndex;
    if (connection == null) {
        connection = createConnection();
        try {
            connection.start();
        } catch (JMSException e) {
            log.error(e.getMessage(), e);
        }

        if (connection != null) {
        }

        //            incrementConnectionCounter(lastReturnedConnectionIndex);
        sharedConnectionMap.put(lastReturnedConnectionIndex, connection);
    }
    //        else{
    //            incrementConnectionCounter(lastReturnedConnectionIndex);
    //        }
    lastReturnedConnectionIndex++;
    if (lastReturnedConnectionIndex >= maxSharedConnectionCount) {
        lastReturnedConnectionIndex = 0;
    }

    return connection;
}

From source file:org.wso2.carbon.andes.event.core.internal.delivery.jms.JMSDeliveryManager.java

/**
 * {@inheritDoc}/*from   w  w  w. j  a va2 s  . co m*/
 */
public void publish(Message message, String topicName, int deliveryMode) throws EventBrokerException {

    if (isDeactivated()) {
        return;
    }

    try {
        String userName = getLoggedInUserName();
        if ((userName == null) || (userName.equals(""))) {
            // use the system user name
            userName = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
        }

        TopicConnection topicConnection = getTopicConnection(userName);
        TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        String tenantDomain = EventBrokerHolder.getInstance().getTenantDomain();
        if (tenantDomain != null
                && (!tenantDomain.equals(org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME))) {
            topicName = tenantDomain + "/" + getTopicName(topicName);
        } else {
            topicName = getTopicName(topicName);
        }

        Topic topic = topicSession.createTopic(topicName);
        //Some times we are not getting the proper topic with the required syntax, if it is not
        //appropriate we need to check and add the BURL syntax to fix the issue https://wso2.org/jira/browse/MB-185
        if (!topic.toString().startsWith("topic://amq.topic")) {
            topic = topicSession.createTopic("BURL:" + topicName);
        }
        TopicPublisher topicPublisher = topicSession.createPublisher(topic);
        topicPublisher.setDeliveryMode(deliveryMode);
        TextMessage textMessage = topicSession.createTextMessage(message.getMessage());

        Map<String, String> properties = message.getProperties();
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            textMessage.setStringProperty(entry.getKey(), entry.getValue());
        }

        // saving the domain to be used send with the soap header
        if (CarbonContext.getThreadLocalCarbonContext().getTenantDomain() != null) {
            textMessage.setStringProperty(MultitenantConstants.TENANT_DOMAIN_HEADER_NAME,
                    CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
        }

        topicPublisher.publish(textMessage);
        topicPublisher.close();
        topicSession.close();
        topicConnection.stop();
        topicConnection.close();
    } catch (JMSException e) {
        throw new EventBrokerException("Can not publish to topic " + topicName + " " + e.getMessage(), e);
    }
}

From source file:org.wso2.extension.siddhi.io.jms.source.client.JMSClient.java

public void sendJMSEvents(List<String> messageList, String topicName, String queueName, String format,
        String broker, String providerURL) {
    if (format == null || "map".equals(format)) {
        format = "csv";
    }// w  w w . ja v a 2  s  .c o m
    if ("".equalsIgnoreCase(broker)) {
        broker = "activemq";
    }
    Session session = null;
    Properties properties = new Properties();
    if (!"activemq".equalsIgnoreCase(broker) && !"mb".equalsIgnoreCase(broker)
            && !"qpid".equalsIgnoreCase(broker)) {
        log.error("Please enter a valid JMS message broker. (ex: activemq, mb, qpid");
        return;
    }
    try {
        if (topicName != null && !"".equalsIgnoreCase(topicName)) {
            TopicConnection topicConnection;
            TopicConnectionFactory connFactory = null;
            if ("activemq".equalsIgnoreCase(broker)) {
                properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties"));
                // to provide custom provider urls
                if (providerURL != null) {
                    properties.put(Context.PROVIDER_URL, providerURL);
                }
                Context context = new InitialContext(properties);
                connFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory");
            } else if ("mb".equalsIgnoreCase(broker)) {
                properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("mb.properties"));
                Context context = new InitialContext(properties);
                connFactory = (TopicConnectionFactory) context.lookup("qpidConnectionFactory");
            } else if ("qpid".equalsIgnoreCase(broker)) {
                properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("qpid.properties"));
                Context context = new InitialContext(properties);
                connFactory = (TopicConnectionFactory) context.lookup("qpidConnectionFactory");
            }
            if (connFactory != null) {
                topicConnection = connFactory.createTopicConnection();
                topicConnection.start();
                session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
                if (session != null) {
                    Topic topic = session.createTopic(topicName);
                    MessageProducer producer = session.createProducer(topic);
                    //List<String> messagesList = JMSClientUtil.readFile(filePath);
                    try {
                        if ("csv".equalsIgnoreCase(format)) {
                            log.info("Sending Map messages on '" + topicName + "' topic");
                            JMSClientUtil.publishMapMessage(producer, session, messageList);

                        } else {
                            log.info("Sending  " + format + " messages on '" + topicName + "' topic");
                            JMSClientUtil.publishTextMessage(producer, session, messageList);
                        }
                        log.info("All Order Messages sent");
                    } catch (JMSException e) {
                        log.error("Cannot subscribe." + e.getMessage(), e);
                    } catch (IOException e) {
                        log.error("Error when reading the data file." + e.getMessage(), e);
                    } finally {
                        producer.close();
                        session.close();
                        topicConnection.stop();
                    }
                }
            } else {
                log.error("Error when creating connection factory. Please check necessary jar files");
            }
        } else if (queueName != null && !queueName.equalsIgnoreCase("")) {
            QueueConnection queueConnection;
            QueueConnectionFactory connFactory = null;
            if ("activemq".equalsIgnoreCase(broker)) {
                properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties"));
                // to provide custom provider urls
                if (providerURL != null) {
                    properties.put(Context.PROVIDER_URL, providerURL);
                }
                Context context = new InitialContext(properties);
                connFactory = (QueueConnectionFactory) context.lookup("ConnectionFactory");
            } else if ("mb".equalsIgnoreCase(broker)) {
                properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("mb.properties"));
                Context context = new InitialContext(properties);
                connFactory = (QueueConnectionFactory) context.lookup("qpidConnectionFactory");
            } else if ("qpid".equalsIgnoreCase(broker)) {
                properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("qpid.properties"));
                Context context = new InitialContext(properties);
                connFactory = (QueueConnectionFactory) context.lookup("qpidConnectionFactory");
            }
            if (connFactory != null) {
                queueConnection = connFactory.createQueueConnection();
                queueConnection.start();
                session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                if (session != null) {
                    Queue queue = session.createQueue(queueName);
                    MessageProducer producer = session.createProducer(queue);
                    //List<String> messagesList = JMSClientUtil.readFile(filePath);
                    try {
                        if ("csv".equalsIgnoreCase(format)) {
                            log.info("Sending Map messages on '" + queueName + "' queue");
                            JMSClientUtil.publishMapMessage(producer, session, messageList);

                        } else {
                            log.info("Sending  " + format + " messages on '" + queueName + "' queue");
                            JMSClientUtil.publishTextMessage(producer, session, messageList);
                        }
                    } catch (JMSException e) {
                        log.error("Cannot subscribe." + e.getMessage(), e);
                    } catch (IOException e) {
                        log.error("Error when reading the data file." + e.getMessage(), e);
                    } finally {
                        producer.close();
                        session.close();
                        queueConnection.stop();
                    }
                }
            } else {
                log.error("Error when creating connection factory. Please check necessary jar files");
            }
        } else {
            log.error("Enter queue name or topic name to be published!");
        }
    } catch (Exception e) {
        log.error("Error when publishing" + e.getMessage(), e);
    }
}