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:tld.yourname.jms.client.ClockServiceStressTest.java

/**
 *
 * @param aArgs//from  w  w  w  . j a va2s.c o  m
 */
@SuppressWarnings("SleepWhileInLoop")
public static void main(String[] aArgs) {

    // set up log4j logging
    // later this should be read from a shared log4j properties or xml file!
    Properties lProps = new Properties();
    lProps.setProperty("log4j.rootLogger", "ERROR, console");
    lProps.setProperty("log4j.logger.org.apache.activemq.spring", "WARN");
    lProps.setProperty("log4j.logger.org.apache.activemq.web.handler", "WARN");
    lProps.setProperty("log4j.logger.org.springframework", "WARN");
    lProps.setProperty("log4j.logger.org.apache.xbean", "WARN");
    lProps.setProperty("log4j.logger.org.apache.camel", "INFO");
    lProps.setProperty("log4j.logger.org.eclipse.jetty", "WARN");
    lProps.setProperty("log4j.appender.console", "org.apache.log4j.ConsoleAppender");
    lProps.setProperty("log4j.appender.console.layout", "org.apache.log4j.PatternLayout");
    lProps.setProperty("log4j.appender.console.layout.ConversionPattern",
            // "%p: %m%n"
            "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %C{1}: %m%n");
    // set here the jWebSocket log level:
    lProps.setProperty("log4j.logger.org.jwebsocket", "ERROR");
    lProps.setProperty("log4j.appender.console.threshold", "ERROR");
    PropertyConfigurator.configure(lProps);

    // only for debug purposes
    // JMSLogging.setFullTextLogging(true);
    mLog.info("jWebSocket JMS Gateway Demo Client");

    Configuration lConfig = null;
    boolean lConfigLoaded;
    try {
        // try to load properties files from local folder or jar
        String lPath = "JMSClient.properties";
        mLog.debug("Tring to read properties from: " + lPath);
        lConfig = new PropertiesConfiguration(lPath);
    } catch (ConfigurationException ex) {
    }
    if (null == lConfig) {
        try {
            // try to load properties files from JWEBSOCKET_HOME/conf/JMSPlugIn
            String lPath = Tools.expandEnvVarsAndProps("${JWEBSOCKET_HOME}conf/JMSPlugIn/JMSClient.properties");
            // String lPath = Tools.expandEnvVarsAndProps("${JWEBSOCKET_HOME}conf/JMSPlugIn/JMSClient.properties");
            mLog.debug("Tring to read properties from: " + lPath);
            lConfig = new PropertiesConfiguration(lPath);
        } catch (ConfigurationException ex) {
        }
    }
    if (null == lConfig) {
        mLog.error("Configuration file could not be opened.");
        return;
    }

    // the URL of the message broker
    String lBrokerURL = lConfig.getString("BrokerURL", "tcp://127.0.0.1:61616");
    // "failover:(tcp://0.0.0.0:61616,tcp://127.0.0.1:61616)?initialReconnectDelay=100&randomize=false";
    // the name of the JMS Gateway topic
    String lGatewayTopic = lConfig.getString("GatewayTopic", "org.jwebsocket.jms.gateway");
    // endpoint id of JMS Gateway
    String lGatewayId = lConfig.getString("GatewayId", "org.jwebsocket.jms.gateway");
    String lEndPointId = lConfig.getString("EndPointId", UUID.randomUUID().toString());

    // get authentication information against jWebSocket
    final String lJWSUsername = lConfig.getString("JWSUsername");
    final String lJWSPassword = lConfig.getString("JWSPassword");
    final boolean lFullTextLogging = lConfig.getBoolean("FullTextLogging", false);

    mLog.info("Using: " + lBrokerURL + ", " + "topic: " + lGatewayTopic + ", " + "gateway-id: " + lGatewayId
            + ", " + "endpoint-id: " + lEndPointId);

    // todo: Comment that for production purposes
    JMSLogging.setFullTextLogging(lFullTextLogging);

    try {
        lJWSEndPoint = JWSEndPoint.getInstance(lBrokerURL, lGatewayTopic, // gateway topic
                lGatewayId, // gateway endpoint id
                lEndPointId, // unique node id
                4, // thread pool size, messages being processed concurrently
                JMSEndPoint.TEMPORARY // durable (for servers) or temporary (for clients)
        );

        // in case you will require the server LoadBalancer features
        // set the CPU updater for the instance
        // lCpuUpdater = new JWSLoadBalancerCpuUpdater(lJWSEndPoint, lTargetEndPointId);
        // lCpuUpdater.autoStart();
    } catch (JMSException lEx) {
        mLog.fatal("JMSEndpoint could not be instantiated: " + lEx.getMessage());
        System.exit(0);
    }

    // on welcome message from jWebSocket, authenticate against jWebSocket
    lJWSEndPoint.addRequestListener("org.jwebsocket.jms.gateway", "welcome",
            new JWSMessageListener(lJWSEndPoint) {
                @Override
                public void processToken(String aSourceId, Token aToken) {
                    if ("org.jwebsocket.jms.gateway".equals(aSourceId)) {
                        // create a login token...
                        mLog.info("Authenticating against jWebSocket...");
                        Token lToken = TokenFactory.createToken("org.jwebsocket.plugins.system", "login");
                        if (null != lJWSUsername && null != lJWSPassword) {
                            lToken.setString("username", lJWSUsername);
                            lToken.setString("password", lJWSPassword);
                        }
                        // and send it to the gateway (which is was the source of the message)
                        sendToken(aSourceId, lToken,
                                new JWSResponseTokenListener(JWSResponseTokenListener.RESP_TIME_FIELD) {

                                    @Override
                                    public void onTimeout() {
                                        mLog.info("Login timed out!");
                                    }

                                    @Override
                                    public void onFailure(Token aReponse) {
                                        mLog.error("Login failure!");
                                    }

                                    @Override
                                    public void onSuccess(Token aReponse) {
                                        if (mLog.isInfoEnabled()) {
                                            mLog.info("Login success (response received in "
                                                    + aReponse.getLong(JWSResponseTokenListener.RESP_TIME_FIELD)
                                                    + "ms).");
                                        }
                                    }

                                }, 1000);
                    }
                }
            });

    // process response of the JMS Gateway login...
    lJWSEndPoint.addResponseListener("org.jwebsocket.plugins.system", "login",
            new JWSMessageListener(lJWSEndPoint) {
                @Override
                public void processToken(String aSourceId, Token aToken) {
                    mLog.info("Login successful, initiating stress test...");
                    startStressTest();
                }

            });

    // start the endpoint all all listener have been assigned
    lJWSEndPoint.start();

    // add a listener to listen in coming messages
    // lJMSClient.addListener(new JMSClientMessageListener(lJMSClient));
    // this is a console app demo
    // so wait in a thread loop until the client get shut down
    try {
        while (lJWSEndPoint.isOpen()) {
            Thread.sleep(1000);
        }
    } catch (InterruptedException lEx) {
        // ignore a potential exception here
    }

    // check if JMS client has already been shutdown by logic
    if (!lJWSEndPoint.isShutdown()) {
        // if not yet done...
        mLog.info("Shutting down JMS Client Endpoint...");
        // shut the client properly down
        lJWSEndPoint.shutdown();
    }

    // and show final status message in the console
    mLog.info("JMS Client Endpoint properly shutdown.");
}

From source file:tld.yourname.jms.client.OntologyPlugInUsage.java

/**
 *
 * @param aArgs/*from w ww. ja va  2  s .c om*/
 */
public static void main(String[] aArgs) {

    // set up log4j logging
    // later this should be read from a shared log4j properties or xml file!
    Properties lProps = new Properties();
    lProps.setProperty("log4j.rootLogger", "ERROR, console");
    lProps.setProperty("log4j.logger.org.apache.activemq.spring", "WARN");
    lProps.setProperty("log4j.logger.org.apache.activemq.web.handler", "WARN");
    lProps.setProperty("log4j.logger.org.springframework", "WARN");
    lProps.setProperty("log4j.logger.org.apache.xbean", "WARN");
    lProps.setProperty("log4j.logger.org.apache.camel", "INFO");
    lProps.setProperty("log4j.logger.org.eclipse.jetty", "WARN");
    lProps.setProperty("log4j.appender.console", "org.apache.log4j.ConsoleAppender");
    lProps.setProperty("log4j.appender.console.layout", "org.apache.log4j.PatternLayout");
    lProps.setProperty("log4j.appender.console.layout.ConversionPattern",
            // "%p: %m%n"
            "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %C{1}: %m%n");
    // set here the jWebSocket log level:
    lProps.setProperty("log4j.logger.org.jwebsocket", "DEBUG");
    lProps.setProperty("log4j.appender.console.threshold", "DEBUG");
    PropertyConfigurator.configure(lProps);

    // only for debug purposes
    // JMSLogging.setFullTextLogging(true);
    mLog.info("jWebSocket JMS Gateway Demo Client");

    Configuration lConfig = null;
    try {
        // try to load properties files from local folder or jar
        String lPath = "JMSClient.properties";
        mLog.debug("Tring to read properties from: " + lPath);
        lConfig = new PropertiesConfiguration(lPath);
    } catch (ConfigurationException ex) {
    }
    if (null == lConfig) {
        try {
            // try to load properties files from JWEBSOCKET_HOME/conf/JMSPlugIn
            String lPath = Tools.expandEnvVarsAndProps("${JWEBSOCKET_HOME}conf/JMSPlugIn/JMSClient.properties");
            // String lPath = Tools.expandEnvVarsAndProps("${JWEBSOCKET_HOME}conf/JMSPlugIn/JMSClient.properties");
            mLog.debug("Tring to read properties from: " + lPath);
            lConfig = new PropertiesConfiguration(lPath);
        } catch (ConfigurationException ex) {
        }
    }
    if (null == lConfig) {
        mLog.error("Configuration file could not be opened.");
        return;
    }

    // the URL of the message broker
    String lBrokerURL = lConfig.getString("BrokerURL", "tcp://127.0.0.1:61616");
    // "failover:(tcp://0.0.0.0:61616,tcp://127.0.0.1:61616)?initialReconnectDelay=100&randomize=false";
    // the name of the JMS Gateway topic
    String lGatewayTopic = lConfig.getString("GatewayTopic", "org.jwebsocket.jms.gateway");
    // endpoint id of JMS Gateway
    String lGatewayId = lConfig.getString("GatewayId", "org.jwebsocket.jms.gateway");
    String lEndPointId = lConfig.getString("EndPointId", UUID.randomUUID().toString());

    // get authentication information against jWebSocket
    final String lJWSUsername = lConfig.getString("JWSUsername");
    final String lJWSPassword = lConfig.getString("JWSPassword");
    final boolean lFullTextLogging = lConfig.getBoolean("FullTextLogging", false);

    mLog.info("Using: " + lBrokerURL + ", " + "topic: " + lGatewayTopic + ", " + "gateway-id: " + lGatewayId
            + ", " + "endpoint-id: " + lEndPointId);

    // todo: Comment that for production purposes
    JMSLogging.setFullTextLogging(lFullTextLogging);

    try {
        lJWSEndPoint = JWSEndPoint.getInstance(lBrokerURL, lGatewayTopic, // gateway topic
                lGatewayId, // gateway endpoint id
                lEndPointId, // unique node id
                4, // thread pool size, messages being processed concurrently
                JMSEndPoint.TEMPORARY // durable (for servers) or temporary (for clients)
        );

        // in case you will require the server LoadBalancer features
        // set the CPU updater for the instance
        // lCpuUpdater = new JWSLoadBalancerCpuUpdater(lJWSEndPoint, lTargetEndPointId);
        // lCpuUpdater.autoStart();
    } catch (JMSException lEx) {
        mLog.fatal("JMSEndpoint could not be instantiated: " + lEx.getMessage());
        System.exit(0);
    }

    // on welcome message from jWebSocket, authenticate against jWebSocket
    lJWSEndPoint.addRequestListener("org.jwebsocket.jms.gateway", "welcome",
            new JWSMessageListener(lJWSEndPoint) {
                @Override
                public void processToken(String aSourceId, Token aToken) {
                    if ("org.jwebsocket.jms.gateway".equals(aSourceId)) {
                        // create a login token...
                        mLog.info("Authenticating against jWebSocket...");
                        Token lToken = TokenFactory.createToken("org.jwebsocket.plugins.system", "login");
                        if (null != lJWSUsername && null != lJWSPassword) {
                            lToken.setString("username", lJWSUsername);
                            lToken.setString("password", lJWSPassword);
                        }
                        // and send it to the gateway (which is was the source of the message)
                        sendToken(aSourceId, lToken,
                                new JWSResponseTokenListener(JWSResponseTokenListener.RESP_TIME_FIELD) {

                                    @Override
                                    public void onTimeout() {
                                        mLog.info("Login timed out!");
                                    }

                                    @Override
                                    public void onFailure(Token aReponse) {
                                        mLog.error("Login failure!");
                                    }

                                    @Override
                                    public void onSuccess(Token aReponse) {
                                        if (mLog.isInfoEnabled()) {
                                            mLog.info("Login success (response received in "
                                                    + aReponse.getLong(JWSResponseTokenListener.RESP_TIME_FIELD)
                                                    + "ms).");
                                        }
                                    }

                                }, 1000);
                    }
                }
            });

    // process response of the JMS Gateway login...
    lJWSEndPoint.addResponseListener("org.jwebsocket.plugins.system", "login",
            new JWSMessageListener(lJWSEndPoint) {
                @Override
                public void processToken(String aSourceId, Token aToken) {
                    mLog.info("Login successful, initiating stress test...");
                    getActionPlugInAPI();
                }

            });

    // start the endpoint all all listener have been assigned
    lJWSEndPoint.start();

    // add a listener to listen in coming messages
    // lJMSClient.addListener(new JMSClientMessageListener(lJMSClient));
    // this is a console app demo
    // so wait in a thread loop until the client get shut down
    try {
        while (lJWSEndPoint.isOpen()) {
            Thread.sleep(1000);
        }
    } catch (InterruptedException lEx) {
        // ignore a potential exception here
    }

    // check if JMS client has already been shutdown by logic
    if (!lJWSEndPoint.isShutdown()) {
        // if not yet done...
        mLog.info("Shutting down JMS Client Endpoint...");
        // shut the client properly down
        lJWSEndPoint.shutdown();
    }

    // and show final status message in the console
    mLog.info("JMS Client Endpoint properly shutdown.");
}

From source file:org.sdnmq.jms_demoapps.FilteringPacketInSubscriber.java

private static void printMsgProperties(Message msg) {
    try {//ww  w.j a v a2 s  .c om
        Enumeration keys = msg.getPropertyNames();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            Object value = msg.getObjectProperty(key);
            System.out.println(key + " " + value.toString());
        }
    } catch (JMSException e) {
        System.err.println(e.getMessage());
    }
}

From source file:org.wso2.carbon.sample.jmsclient.JMSClient.java

public static void publishMessages(String topicName, String broker) {
    try {/*from www  .j av a 2s  .c  o  m*/

        //            filePath = JMSClientUtil.getEventFilePath(sampleNumber, format, topicName, filePath);

        TopicConnection topicConnection = null;
        Session session = null;

        Properties properties = new Properties();
        if (broker.equalsIgnoreCase("activemq")) {
            properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties"));
            Context context = new InitialContext(properties);
            TopicConnectionFactory connFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory");
            topicConnection = connFactory.createTopicConnection();
            topicConnection.start();
            session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        } else if (broker.equalsIgnoreCase("mb")) {
            properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("mb.properties"));
            Context context = new InitialContext(properties);
            TopicConnectionFactory connFactory = (TopicConnectionFactory) context
                    .lookup("qpidConnectionFactory");
            topicConnection = connFactory.createTopicConnection();
            topicConnection.start();
            session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        } else if (broker.equalsIgnoreCase("qpid")) {
            properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("qpid.properties"));
            Context context = new InitialContext(properties);
            TopicConnectionFactory connFactory = (TopicConnectionFactory) context
                    .lookup("qpidConnectionFactory");
            topicConnection = connFactory.createTopicConnection();
            topicConnection.start();
            session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        } else {
            log.info("Please enter a valid JMS message broker. (ex: activemq, mb, qpid");
        }

        if (session != null) {
            Topic topic = session.createTopic(topicName);
            MessageProducer producer = session.createProducer(topic);

            try {

                List<Map<String, Object>> messageList = new ArrayList<Map<String, Object>>();

                Random random = new Random();
                for (int j = 0; j < sessionsPerThread; j++) {
                    for (int i = 0; i < msgsPerSession; i++) {
                        HashMap<String, Object> map = new HashMap<String, Object>();

                        map.put("id", random.nextInt() + "");
                        map.put("value", random.nextInt());
                        map.put("content", "sample content");
                        map.put("client", "jmsQueueClient");
                        // setting the timestamp later
                        messageList.add(map);
                    }

                    publishMapMessage(producer, session, messageList);

                }
            } catch (JMSException e) {
                log.error("Can not 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();
            }
        }
    } catch (Exception e) {
        log.error("Error when publishing message" + e.getMessage(), e);
    }
}

From source file:org.apache.stratos.status.monitor.agent.clients.service.CEPServerClient.java

private static void executeService() throws SQLException {
    int serviceID = MySQLConnectionInitializer.getServiceID(StatusMonitorConstants.CEP);
    AuthConfigBean authConfigBean = StatusMonitorConfigurationBuilder.getAuthConfigBean();

    String userName = authConfigBean.getUserName();
    tcpUserName = userName.replace('@', '!');

    //check whether login success
    if (ServiceLoginClient.loginChecker(StatusMonitorConstants.CEP_HOST, serviceID)) {

        Properties properties = new Properties();
        properties.put(Context.INITIAL_CONTEXT_FACTORY, StatusMonitorAgentConstants.QPID_ICF);
        properties.put(StatusMonitorAgentConstants.CF_NAME_PREFIX + StatusMonitorAgentConstants.CF_NAME,
                getTCPConnectionURL(tcpUserName, authConfigBean.getPassword()));

        InitialContext ctx;//from  w ww.j  a  v a2  s. c om
        try {
            ctx = new InitialContext(properties);

            // Lookup connection factory
            QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx
                    .lookup(StatusMonitorAgentConstants.CF_NAME);
            QueueConnection queueConnection = connFactory.createQueueConnection();
            queueConnection.start();
            QueueSession queueSession = queueConnection.createQueueSession(false,
                    QueueSession.AUTO_ACKNOWLEDGE);

            // Send message
            Queue queue = queueSession.createQueue(
                    StatusMonitorAgentConstants.QUEUE_NAME_CEP + ";{create:always, node:{durable: True}}");

            // create the message to send
            TextMessage textMessage = queueSession.createTextMessage("Test Message Hello");
            javax.jms.QueueSender queueSender = queueSession.createSender(queue);
            queueSender.setTimeToLive(100000000);

            QueueReceiver queueReceiver = queueSession.createReceiver(queue);
            queueSender.send(textMessage);

            TextMessage message = (TextMessage) queueReceiver.receiveNoWait();
            if (log.isDebugEnabled()) {
                log.debug("Message in the execute() of CEPServer Client: " + message.getText());
            }
            if (message.getText().equals("Test Message Hello")) {
                MySQLConnector.insertStats(serviceID, true);
                MySQLConnector.insertState(serviceID, true, "");
            } else {
                MySQLConnector.insertStats(serviceID, false);
                MySQLConnector.insertState(serviceID, false, "Send or retrieve messages failed");
            }
            queueSender.close();
            queueSession.close();
            queueConnection.close();

        } catch (JMSException e) {
            MySQLConnector.insertStats(serviceID, false);
            MySQLConnector.insertState(serviceID, false, e.getMessage());
            String msg = "JMS Exception in inserting stats into the DB for the CEPServerClient";
            log.warn(msg, e);
        } catch (NamingException e) {
            MySQLConnector.insertStats(serviceID, false);
            MySQLConnector.insertState(serviceID, false, e.getMessage());
            String msg = "Naming Exception in inserting stats into the DB for the CEPServerClient";
            log.warn(msg, e);
        }
    }
}

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

/**
 * Build a descriptive exception message for the given JMSException,
 * incorporating a linked exception's message if appropriate.
 * @param ex the JMSException to build a message for
 * @return the descriptive message String
 * @see javax.jms.JMSException#getLinkedException()
 *//*w  w w  .  jav  a2 s .com*/
public static String buildExceptionMessage(JMSException ex) {
    String message = ex.getMessage();
    Exception linkedEx = ex.getLinkedException();
    if (linkedEx != null) {
        if (message == null) {
            message = linkedEx.toString();
        } else {
            String linkedMessage = linkedEx.getMessage();
            if (linkedMessage != null && !message.contains(linkedMessage)) {
                message = message + "; nested exception is " + linkedEx;
            }
        }
    }
    return message;
}

From source file:org.apache.stratos.status.monitor.agent.clients.service.MessageBrokerServiceClient.java

private static void executeService() throws SQLException {
    int serviceID = MySQLConnectionInitializer.getServiceID(StatusMonitorConstants.MESSAGING);
    AuthConfigBean authConfigBean = StatusMonitorConfigurationBuilder.getAuthConfigBean();

    String userName = authConfigBean.getUserName();
    tcpUserName = userName.replace('@', '!');

    //check whether login success
    if (ServiceLoginClient.loginChecker(StatusMonitorConstants.MESSAGING_HOST, serviceID)) {

        Properties properties = new Properties();
        properties.put(Context.INITIAL_CONTEXT_FACTORY, StatusMonitorAgentConstants.QPID_ICF);
        properties.put(StatusMonitorAgentConstants.CF_NAME_PREFIX + StatusMonitorAgentConstants.CF_NAME,
                getTCPConnectionURL(tcpUserName, authConfigBean.getPassword()));

        if (log.isDebugEnabled()) {
            log.debug("getTCPConnectionURL(username,password) = "
                    + getTCPConnectionURL(tcpUserName, authConfigBean.getPassword()));
        }//  w ww.j ava 2 s. c  om
        try {
            InitialContext ctx = new InitialContext(properties);
            // Lookup connection factory
            QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx
                    .lookup(StatusMonitorAgentConstants.CF_NAME);
            QueueConnection queueConnection = connFactory.createQueueConnection();
            queueConnection.start();
            QueueSession queueSession = queueConnection.createQueueSession(false,
                    QueueSession.AUTO_ACKNOWLEDGE);

            // Send message
            Queue queue = queueSession.createQueue(
                    StatusMonitorAgentConstants.QUEUE_NAME_MB + ";{create:always, node:{durable: True}}");

            // create the message to send
            TextMessage textMessage = queueSession.createTextMessage("Test Message Hello");
            javax.jms.QueueSender queueSender = queueSession.createSender(queue);
            queueSender.setTimeToLive(100000000);

            QueueReceiver queueReceiver = queueSession.createReceiver(queue);
            queueSender.send(textMessage);

            TextMessage message = (TextMessage) queueReceiver.receiveNoWait();

            if (message.getText().equals("Test Message Hello")) {
                MySQLConnector.insertStats(serviceID, true);
                MySQLConnector.insertState(serviceID, true, "");
            } else {
                MySQLConnector.insertStats(serviceID, false);
                MySQLConnector.insertState(serviceID, false, "Send and retrieve messages failed");
            }
            queueSender.close();
            queueSession.close();
            queueConnection.close();

        } catch (JMSException e) {
            MySQLConnector.insertStats(serviceID, false);
            MySQLConnector.insertState(serviceID, false, e.getMessage());
            String msg = "Exception in executing the client - "
                    + "Status Monitor Agent for MessageBrokerServiceClient";
            log.warn(msg, e);

        } catch (NamingException e) {
            MySQLConnector.insertStats(serviceID, false);
            MySQLConnector.insertState(serviceID, false, e.getMessage());
            String msg = "Naming exception in executing the client - "
                    + "Status Monitor agent for MessageBrokerServiceClient";
            log.warn(msg, e);
        }
    }
}

From source file:org.wso2.carbon.integration.test.client.JMSPublisherClient.java

/**
 * This method will publish the data in the test data file to the given topic via ActiveMQ message broker
 *
 * @param topicName             the topic which the messages should be published under
 * @param format                format of the test data file (csv or text)
 * @param testCaseFolderName    Testcase folder name which is in the test artifacts folder
 * @param dataFileName          data file name with the extension to be read
 *
 *///from   www .  j a v a  2s.c  om
public static void publish(String topicName, String format, String testCaseFolderName, String dataFileName) {

    if (format == null || "map".equals(format)) {
        format = "csv";
    }

    try {
        Properties properties = new Properties();

        String filePath = getTestDataFileLocation(testCaseFolderName, dataFileName);
        properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties"));
        Context context = new InitialContext(properties);
        TopicConnectionFactory connFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory");
        TopicConnection topicConnection = connFactory.createTopicConnection();
        topicConnection.start();
        Session session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        Topic topic = session.createTopic(topicName);
        MessageProducer producer = session.createProducer(topic);

        List<String> messagesList = readFile(filePath);
        try {

            if (format.equalsIgnoreCase("csv")) {
                log.info("Sending Map messages on '" + topicName + "' topic");
                publishMapMessages(producer, session, messagesList);

            } else {
                log.info("Sending  " + format + " messages on '" + topicName + "' topic");
                publishTextMessage(producer, session, messagesList);
            }
        } catch (JMSException e) {
            log.error("Can not subscribe." + e.getMessage(), e);
        } finally {
            producer.close();
            session.close();
            topicConnection.stop();
            topicConnection.close();
        }
    } catch (Exception e) {
        log.error("Error when publishing messages" + e.getMessage(), e);
    }

    log.info("All Order Messages sent");
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.JMSInjectHandler.java

/**
 * //from  ww  w.  ja v a2  s .c  o m
 * @param message
 *            JMSMap message
 * @return XML representation of JMS Map message
 */
public static OMElement convertJMSMapToXML(MapMessage message) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace jmsMapNS = OMAbstractFactory.getOMFactory().createOMNamespace(JMSConstants.JMS_MAP_NS, "");
    OMElement jmsMap = fac.createOMElement(JMSConstants.JMS_MAP_ELEMENT_NAME, jmsMapNS);
    try {
        Enumeration names = message.getMapNames();
        while (names.hasMoreElements()) {
            String nextName = names.nextElement().toString();
            String nextVal = message.getString(nextName);
            OMElement next = fac.createOMElement(nextName.replace(" ", ""), jmsMapNS);
            next.setText(nextVal);
            jmsMap.addChild(next);
        }
    } catch (JMSException e) {
        log.error("Error while processing the JMS Map Message. " + e.getMessage());
    }
    return jmsMap;
}

From source file:net.timewalker.ffmq4.utils.ErrorTools.java

/**
 * Log a JMS exception with an error level
 * @param e//from w  w  w  .  j a  v  a 2 s  .  com
 * @param log
 */
public static void log(String context, JMSException e, Log log) {
    StringBuilder message = new StringBuilder();
    if (context != null) {
        message.append("[");
        message.append(context);
        message.append("] ");
    }
    if (e.getErrorCode() != null) {
        message.append("error={");
        message.append(e.getErrorCode());
        message.append("} ");
    }
    message.append(e.getMessage());
    log.error(message.toString());
    if (e.getLinkedException() != null)
        log.error("Linked exception was :", e.getLinkedException());
}