Example usage for javax.jms JMSException printStackTrace

List of usage examples for javax.jms JMSException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.apache.ode.extension.jmseventlistener.JmsBpelEventListener.java

public void shutdown() {
    if (connection == null) {
        return;/*from w ww  .  j av a 2 s.  c  om*/
    }
    try {
        connection.stop();
        connection.close();
        connection = null;
        initialized = false;
    } catch (JMSException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    factory = null;
    logger.info("JMS BPEL event has been shutdown.");
}

From source file:com.provenance.cloudprovenance.connector.traceability.TraceabilityEventConsumer.java

public void onMessage(final Message newMessage) {

    logger.info("Received Traceability Statements Message = " + counter++);

    if (newMessage instanceof TextMessage) {
        TextMessage textMessage = (TextMessage) newMessage;

        String traceabilityRecord = null;
        try {//from   www  .ja v a 2 s .c  o  m
            traceabilityRecord = textMessage.getText();

            logger.info(" Traceability content: \n" + traceabilityRecord);

            /**
             * Get the record Id, if it is just use POST request, otherwise
             * use PUT reequest
             */

            if (traceabilityRecordUri == null || traceabilityRecordUri.equals("")) {

                logger.info("Calling get Resource URI ...");
                String traceabilityRecordResponse = trConnection.getCurrentTraceabilityRecordId(serviceID);

                if (traceabilityRecordResponse != null || traceabilityRecordResponse == "") {

                    logger.info("Resource URI does not exist, creation a new resource with content");

                    traceabilityRecordUri = (resExtraction.getResponseURI(traceabilityRecordResponse));

                    logger.info("New resource created URI is: " + traceabilityRecordUri);

                    trConnection.updateTraceabilityRecord(serviceID, traceabilityRecordUri, traceabilityRecord);

                    logger.info("Sucessfully updated the traceability record: " + traceabilityRecordUri);

                } else {
                    // get a new record Id
                    String response = trConnection.createNewTraceabilityRecord(serviceID, traceabilityRecord);

                    traceabilityRecordUri = (resExtraction.getResponseURI(response));// .split(":")[1];
                    logger.info("Sucessfully created a new traceability record: " + response + "\n"
                            + traceabilityRecordUri);
                }
            } else {
                logger.info("Updating record :" + traceabilityRecordUri);
                trConnection.updateTraceabilityRecord(serviceID, traceabilityRecordUri, traceabilityRecord);

                logger.info("Sucessfully updated the traceability record: " + traceabilityRecordUri);

            }

            // If an ack is required, use the reponse queue
            if (traceabilityStoreStorageAck) {
                logger.info("Sending an ACK to response tranceability queue" + traceabilityRecordUri);

                jmsTemplate.send(responseTraceabilityQueueName, new MessageCreator() {

                    public Message createMessage(Session session) throws JMSException {
                        TextMessage message = session.createTextMessage("Sucessfully Stored, ID: " + counter);
                        // message.setIntProperty("messageCount",
                        // i);
                        return message;
                    }
                });
            }

        } catch (JMSException e) {
            logger.error(e.toString());
            e.printStackTrace();
        } catch (XPathExpressionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        logger.warn("Unknown message type, cannot process");
    }
}

From source file:TopicRequestor.java

/** Create JMS client for publishing and subscribing to messages. */
private void start(String broker, String username, String password) {
    // Create a connection.
    try {//w w  w  . j a  v a2  s .  c  om
        javax.jms.TopicConnectionFactory factory;
        factory = new ActiveMQConnectionFactory(username, password, broker);
        connect = factory.createTopicConnection(username, password);
        session = connect.createTopicSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
    } catch (javax.jms.JMSException jmse) {
        System.err.println("error: Cannot connect to Broker - " + broker);
        jmse.printStackTrace();
        System.exit(1);
    }

    // Create Topic for all requests.  TopicRequestor will be created
    // as needed.
    javax.jms.Topic topic = null;
    try {
        topic = session.createTopic(APP_TOPIC);
        // Now that all setup is complete, start the Connection
        connect.start();
    } catch (javax.jms.JMSException jmse) {
        jmse.printStackTrace();
    }
    try {
        // Read all standard input and send it as a message.
        java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
        System.out.println("\nRequestor application:\n" + "============================\n"
                + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME
                + ".\n" + "The application uses a TopicRequestor to on the " + APP_TOPIC + " topic."
                + "The Replier application gets the message, and transforms it."
                + "The Requestor application displays the result.\n\n"
                + "Type some mixed case text, and then press Enter to make a request.\n");
        while (true) {
            String s = stdin.readLine();

            if (s == null)
                exit();
            else if (s.length() > 0) {
                javax.jms.TextMessage msg = session.createTextMessage();
                msg.setText(username + ": " + s);
                // Instead of publishing, we will use a TopicRequestor.
                javax.jms.TopicRequestor requestor = new javax.jms.TopicRequestor(session, topic);
                javax.jms.Message response = requestor.request(msg);
                // The message should be a TextMessage.  Just report it.
                javax.jms.TextMessage textMessage = (javax.jms.TextMessage) response;
                System.out.println("[Reply] " + textMessage.getText());
            }
        }
    } catch (java.io.IOException ioe) {
        ioe.printStackTrace();
    } catch (javax.jms.JMSException jmse) {
        jmse.printStackTrace();
    }
}

From source file:org.apache.activemq.usecases.DurableSubscriberWithNetworkDisconnectTest.java

public void testSendOnAReceiveOnBWithTransportDisconnect() throws Exception {
    bridgeBrokers(SPOKE, HUB);// ww  w. j  a v a  2  s.co  m

    startAllBrokers();

    // Setup connection
    URI hubURI = brokers.get(HUB).broker.getVmConnectorURI();
    URI spokeURI = brokers.get(SPOKE).broker.getVmConnectorURI();
    ActiveMQConnectionFactory facHub = new ActiveMQConnectionFactory(hubURI);
    ActiveMQConnectionFactory facSpoke = new ActiveMQConnectionFactory(spokeURI);
    Connection conHub = facHub.createConnection();
    Connection conSpoke = facSpoke.createConnection();
    conHub.setClientID("clientHUB");
    conSpoke.setClientID("clientSPOKE");
    conHub.start();
    conSpoke.start();
    Session sesHub = conHub.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session sesSpoke = conSpoke.createSession(false, Session.AUTO_ACKNOWLEDGE);

    ActiveMQTopic topic = new ActiveMQTopic("TEST.FOO");
    String consumerName = "consumerName";

    // Setup consumers
    MessageConsumer remoteConsumer = sesSpoke.createDurableSubscriber(topic, consumerName);
    remoteConsumer.setMessageListener(new MessageListener() {
        public void onMessage(Message msg) {
            try {
                TextMessage textMsg = (TextMessage) msg;
                receivedMsgs++;
                LOG.info("Received messages (" + receivedMsgs + "): " + textMsg.getText());
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    });

    // allow subscription information to flow back to Spoke
    sleep(1000);

    // Setup producer
    MessageProducer localProducer = sesHub.createProducer(topic);
    localProducer.setDeliveryMode(DeliveryMode.PERSISTENT);

    // Send messages
    for (int i = 0; i < MESSAGE_COUNT; i++) {
        sleep(50);
        if (i == 50 || i == 150) {
            if (simulateStalledNetwork) {
                socketProxy.pause();
            } else {
                socketProxy.close();
            }
            networkDownTimeStart = System.currentTimeMillis();
        } else if (networkDownTimeStart > 0) {
            // restart after NETWORK_DOWN_TIME seconds
            sleep(NETWORK_DOWN_TIME);
            networkDownTimeStart = 0;
            if (simulateStalledNetwork) {
                socketProxy.goOn();
            } else {
                socketProxy.reopen();
            }
        } else {
            // slow message production to allow bridge to recover and limit message duplication
            sleep(500);
        }
        Message test = sesHub.createTextMessage("test-" + i);
        localProducer.send(test);
    }

    LOG.info("waiting for messages to flow");
    Wait.waitFor(new Wait.Condition() {
        @Override
        public boolean isSatisified() throws Exception {
            return receivedMsgs >= MESSAGE_COUNT;
        }
    });

    assertTrue("At least message " + MESSAGE_COUNT + " must be received, count=" + receivedMsgs,
            MESSAGE_COUNT <= receivedMsgs);
    brokers.get(HUB).broker.deleteAllMessages();
    brokers.get(SPOKE).broker.deleteAllMessages();
    conHub.close();
    conSpoke.close();
}

From source file:Chat.java

/** Create JMS client for publishing and subscribing to messages. */
private void chatter(String broker, String username, String password) {
    // Create a connection.
    try {//ww  w. j  ava  2 s .c  om
        javax.jms.ConnectionFactory factory;
        factory = new ActiveMQConnectionFactory(username, password, broker);
        connect = factory.createConnection(username, password);
        pubSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
        subSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
    } catch (javax.jms.JMSException jmse) {
        System.err.println("error: Cannot connect to Broker - " + broker);
        jmse.printStackTrace();
        System.exit(1);
    }

    // Create Publisher and Subscriber to 'chat' topics
    try {
        javax.jms.Topic topic = pubSession.createTopic(APP_TOPIC);
        javax.jms.MessageConsumer subscriber = subSession.createConsumer(topic);
        subscriber.setMessageListener(this);
        publisher = pubSession.createProducer(topic);
        // Now that setup is complete, start the Connection
        connect.start();
    } catch (javax.jms.JMSException jmse) {
        jmse.printStackTrace();
    }

    try {
        // Read all standard input and send it as a message.
        java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
        System.out.println("\nChat application:\n" + "=================\n" + "The application user " + username
                + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n"
                + "The application will publish messages to the " + APP_TOPIC + " topic.\n"
                + "The application also subscribes to that topic to consume any messages published there.\n\n"
                + "Type some text, and then press Enter to publish it as a TextMesssage from " + username
                + ".\n");
        while (true) {
            String s = stdin.readLine();

            if (s == null)
                exit();
            else if (s.length() > 0) {
                javax.jms.TextMessage msg = pubSession.createTextMessage();
                msg.setText(username + ": " + s);
                publisher.send(msg);
            }
        }
    } catch (java.io.IOException ioe) {
        ioe.printStackTrace();
    } catch (javax.jms.JMSException jmse) {
        jmse.printStackTrace();
    }
}

From source file:QueueRoundTrip.java

private void QueueRoundTripper(String broker, String username, String password, int numTests) {

    try {/*from www  . j  a  v  a 2  s.com*/
        //Set up two sessions, one for sending and the other for receiving
        factory = new ActiveMQConnectionFactory(username, password, broker);
        connection = factory.createConnection(username, password);
        sendSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
        receiveSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
    } catch (javax.jms.JMSException jmse) {
        System.err.println("error: Cannot connect to broker- " + broker + ".\n");
        jmse.printStackTrace();
        System.exit(1);
    }

    try {
        //Set up a temporary Queue:
        javax.jms.TemporaryQueue tempQueue = sendSession.createTemporaryQueue();
        receiver = receiveSession.createConsumer(tempQueue);
        sender = sendSession.createProducer(tempQueue);
        connection.start();
    } catch (javax.jms.JMSException jmse) {
        System.err.println("error: Connection couldn't be started.\n");
        jmse.printStackTrace();
        System.exit(1);
    }

    //Send messages using Temporary Queue:
    try {
        System.out.println("QueueRoundTrip application:");
        System.out.println("===========================");
        System.out.println("Sending Messages to Temporary Queue...");

        //create a message to send
        javax.jms.BytesMessage msg = sendSession.createBytesMessage();
        msg.writeBytes(msgBody);

        //send and receive the message the specified number of times:
        long time = System.currentTimeMillis();
        for (int i = 0; i < numTests; i++) {
            sender.send(msg);
            msg = (javax.jms.BytesMessage) receiver.receive();
        }
        time = System.currentTimeMillis() - time;

        System.out.println("\nTime for " + numTests + " sends and receives:\t\t" + time + "ms\n"
                + "Average Time per message:\t\t\t" + (float) time / (float) numTests + "ms\n");
        System.out.println("\n\nPress Enter to close this window.");
        java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
        stdin.readLine();
        System.exit(0);
    }

    catch (javax.jms.JMSException jmse) {
        System.err.println("error: message not sent/received.\n");
        jmse.printStackTrace();
        System.exit(1);
    }

    catch (java.io.IOException ioe) {
        ioe.printStackTrace();
    }

}

From source file:Requestor.java

/** Create JMS client for sending messages. */
private void start(String broker, String username, String password, String sQueue) {
    // Create a connection.
    try {// w ww . j  av  a  2  s.co m
        javax.jms.QueueConnectionFactory factory;
        factory = new ActiveMQConnectionFactory(username, password, broker);
        connect = factory.createQueueConnection(username, password);
        session = connect.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
    } catch (javax.jms.JMSException jmse) {
        System.err.println("error: Cannot connect to Broker - " + broker);
        jmse.printStackTrace();
        System.exit(1);
    }

    // Create the Queue and QueueRequestor for sending requests.
    javax.jms.Queue queue = null;
    try {
        queue = session.createQueue(sQueue);
        requestor = new javax.jms.QueueRequestor(session, queue);

        // Now that all setup is complete, start the Connection.
        connect.start();
    } catch (javax.jms.JMSException jmse) {
        jmse.printStackTrace();
        exit();
    }

    try {
        // Read all standard input and send it as a message.
        java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
        System.out.println("\nRequestor application:\n" + "============================\n"
                + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME
                + ".\n" + "The application uses a QueueRequestor to on the " + DEFAULT_QUEUE + " queue."
                + "The Replier application gets the message, and transforms it."
                + "The Requestor application displays the result.\n\n"
                + "Type some mixed case text, and then press Enter to make a request.\n");
        while (true) {
            String s = stdin.readLine();

            if (s == null)
                exit();
            else if (s.length() > 0) {
                javax.jms.TextMessage msg = session.createTextMessage();
                msg.setText(username + ": " + s);
                // Instead of sending, we will use the QueueRequestor.
                javax.jms.Message response = requestor.request(msg);
                // The message should be a TextMessage.  Just report it.
                javax.jms.TextMessage textMessage = (javax.jms.TextMessage) response;
                System.out.println("[Reply] " + textMessage.getText());
            }
        }
    } catch (java.io.IOException ioe) {
        ioe.printStackTrace();
    } catch (javax.jms.JMSException jmse) {
        jmse.printStackTrace();
    }
}

From source file:it.cnr.isti.labse.glimpse.manager.GlimpseManager.java

public void onMessage(Message arg0) {

    TextMessage msg = null;//from w  w  w .  ja va  2 s  . c o  m
    try {
        msg = (TextMessage) arg0;
        DebugMessages.line();
        DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "receive " + msg.getText());
        DebugMessages.line();
        String XMLRule = msg.getText();
        String sender = msg.getStringProperty("SENDER");

        /* 
         * check if the message contains a ComplexEventRule or a Model
         * in the second case, it must be forwarded to the new component
         * Transformer that will convert Model to Drools rule
         *
         */

        ComplexEventRuleActionType rules;

        if (XMLRule.contains("ComplexEventRuleActionList")) {

            //if the message contains a rule represented through ComplexEventRule XSD
            ComplexEventRuleActionListDocument ruleDoc;
            ruleDoc = ComplexEventRuleActionListDocument.Factory.parse(XMLRule);
            rules = ruleDoc.getComplexEventRuleActionList();
        } else {

            //if the message contains a rule represented through a model (CPMM)
            Transformer transformer = new TransformerImpl(null);
            /*TODO: as parameter of the transformerImpl, we must put the
             * path of the metamodel file.
             */
            rules = transformer.convertInputModel(XMLRule).getComplexEventRuleActionList();

        }
        //the topic where the listener will give analysis results
        answerTopic = "answerTopic" + "#" + this.getName() + "#" + System.nanoTime();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Create answerTopic");
        connectionTopic = publishSession.createTopic(answerTopic);
        //tPub = publishSession.createPublisher(connectionTopic);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Setup ComplexEventProcessor with Enabler request.");
        try {
            Object[] loadedKnowledgePackage = rulesManager.loadRules(rules);
            //inserisco la coppia chiave valore dove la chiave  il KnowledgePackage
            //caricato, generato da DroolsRulesManager con la loadRules
            //e il valore  l'enabler che l'ha inviata
            //(il KnowledgePackage array dovrebbe avere sempre dimensione 1 essendo creato ad ogni loadrules)
            for (int i = 0; i < loadedKnowledgePackage.length; i++) {
                KnowledgePackageImp singleKnowlPack = (KnowledgePackageImp) loadedKnowledgePackage[i];
                Rule singleRuleContainer[] = new Rule[singleKnowlPack.getRules().size()];
                singleRuleContainer = singleKnowlPack.getRules().toArray(singleRuleContainer);

                for (int j = 0; j < singleRuleContainer.length; j++) {
                    requestMap.put(singleRuleContainer[j].getName(), new ConsumerProfile(sender, answerTopic));
                }
                DebugMessages.ok();
                DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                        "KnowledgeBase packages loaded: "
                                + rulesManager.getLoadedKnowledgePackageCardinality());
            }

            DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                    "Communicate the answerTopic to the enabler");
            sendMessage(createMessage("AnswerTopic == " + answerTopic, sender));
            DebugMessages.ok();
        } catch (IncorrectRuleFormatException e) {
            sendMessage(createMessage("PROVIDED RULE CONTAINS ERRORS", sender));
        }
    } catch (NullPointerException asd) {
        try {
            sendMessage(createMessage("PROVIDED RULE IS NULL, PLEASE PROVIDE A VALID RULE",
                    msg.getStringProperty("SENDER")));
        } catch (JMSException e) {
            e.printStackTrace();
        }
    } catch (XmlException e) {
        try {
            sendMessage(createMessage("PROVIDED XML CONTAINS ERRORS", msg.getStringProperty("SENDER")));
        } catch (JMSException e1) {
            e1.printStackTrace();
        }
    } catch (JMSException ee) {
        ee.printStackTrace();
    }
    DebugMessages.line();
}

From source file:MessageMonitor.java

/** Constructor for MessageMonitor window. */
public MessageMonitor() {
    loadProperties();/*from   w  w w  .  ja va  2s.co m*/

    setTitle(title);

    // Connect to Message Broker
    try {
        javax.jms.ConnectionFactory factory;
        factory = new ActiveMQConnectionFactory(user, password, url);

        connection = factory.createConnection(userID, password);
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    } catch (javax.jms.JMSException jmse) {
        System.err.println("Cannot connect to Broker");
        jmse.printStackTrace();
        System.exit(1);
    }

    // Subscribe to Topics
    StringTokenizer topics = new StringTokenizer(subscriptionTopics, ",");
    while (topics.hasMoreTokens()) {
        try {
            String topicName = topics.nextToken();
            System.out.println("Subscribing to: " + topicName);
            new Subscription(session.createTopic(topicName));
        } catch (javax.jms.JMSException jmse) {
            jmse.printStackTrace();
        }
    }

    // Set up the viewing area.
    textArea.setEditable(false);
    scrollPane.setBorder(
            new CompoundBorder(new EmptyBorder(6, 6, 6, 6), new SoftBevelBorder(BevelBorder.LOWERED)));
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    getContentPane().add(clearButton, BorderLayout.SOUTH);
    clearButton.addActionListener(new OnClear());
    // Start the connection so that we can now receive messages.
    try {
        connection.start();
    } catch (javax.jms.JMSException jmse) {
        System.err.println("Cannot start connection");
        jmse.printStackTrace();
        System.exit(1);
    }

}

From source file:DurableChat.java

public void DurableChatter(String broker, String username, String password) {
    javax.jms.MessageProducer publisher = null;
    javax.jms.MessageConsumer subscriber = null;
    javax.jms.Topic topic = null;/*  ww w. j  av  a  2 s  .  c om*/

    //Create a connection:
    try {
        javax.jms.ConnectionFactory factory;
        factory = new ActiveMQConnectionFactory(username, password, broker);
        connection = factory.createConnection(username, password);

        //Durable Subscriptions are indexed by username, clientID and subscription name
        //It is a good practice to set the clientID:
        connection.setClientID(username);
        pubSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
        subSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
    } catch (javax.jms.JMSException jmse) {
        System.err.println("Error: Cannot connect to Broker - " + broker);
        jmse.printStackTrace();
        System.exit(1);
    }

    //Create Publisher and Durable Subscriber:
    try {

        topic = pubSession.createTopic(APP_TOPIC);
        subscriber = subSession.createDurableSubscriber(topic, username);
        subscriber.setMessageListener(this);
        publisher = pubSession.createProducer(topic);
        connection.start();
    } catch (javax.jms.JMSException jmse) {
        System.out.println("Error: connection not started.");
        jmse.printStackTrace();
        System.exit(1);
    }

    //Wait for user input
    try {
        System.out.println("\nDurableChat application:\n" + "========================\n" + "The user "
                + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n"
                + "The application will publish messages to the " + APP_TOPIC + " topic.\n"
                + "The application also creates a durable subscription to that topic to consume any messages published there.\n\n"
                + "Type some text, and then press Enter to publish it as a TextMesssage from " + username
                + ".\n");
        java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
        while (true) {
            String s = stdin.readLine();

            if (s == null) {
                exit();
            } else if (s.length() > 0) {
                try {
                    javax.jms.TextMessage msg = pubSession.createTextMessage();
                    msg.setText(username + ": " + s);
                    //Publish the message persistantly:
                    publisher.send(msg, //message
                            javax.jms.DeliveryMode.PERSISTENT, //publish persistently
                            javax.jms.Message.DEFAULT_PRIORITY, //priority
                            MESSAGE_LIFESPAN); //Time to Live
                } catch (javax.jms.JMSException jmse) {
                    System.err.println("Error publishing message:" + jmse.getMessage());
                }
            }
        }
    } catch (java.io.IOException ioe) {
        ioe.printStackTrace();
    }
}