Example usage for javax.jms JMSException toString

List of usage examples for javax.jms JMSException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.oneops.daq.AsyncPerfWorker.java

@Override
public Void call() {
    try {/*  ww  w  . ja v  a  2  s  .c o m*/
        long startTime = System.currentTimeMillis();
        if (perfEvent.isAggregate()) {
            perfDao.processAggregate(perfEvent);
            perfDao.newCount.incrementAndGet();
        } else {
            perfDao.process(perfEvent, ip);
            perfDao.oldCount.incrementAndGet();
        }
        long duration = System.currentTimeMillis() - startTime;
        logger.debug(
                "process " + perfEvent.getCiId() + " " + perfEvent.getGrouping() + " took " + duration + " ms");

        long eventCount = perfDao.eventCounter.incrementAndGet();
        perfDao.batchDuration.getAndAdd(duration);
        if (eventCount % PRINT_STATUS_INCREMENT == 0) {
            writeStats(eventCount);
        }

    } catch (HectorException he) {
        logger.error("invalid message: " + he.toString(), he);
        long heCount = perfDao.hectorExceptionCount.incrementAndGet();
        logger.warn("total hector exceptions: " + heCount);
    } catch (JMSException je) {
        logger.error("invalid message: " + je.toString(), je);
        long jeCount = perfDao.jmsExceptionCount.incrementAndGet();
        logger.warn("total jms exceptions: " + jeCount);
    } catch (UncategorizedJmsException uje) {
        logger.error("invalid message: " + uje.toString(), uje);
        long jeCount = perfDao.jmsExceptionCount.incrementAndGet();
        logger.warn("total (uncat) jms exceptions: " + jeCount);
    } catch (Exception e) {
        // log and ignore
        logger.error("invalid message: " + e.toString(), e);
        return null;
    }
    return null;
}

From source file:TopicPublisher.java

Object getReport(Message m) {
    try {/*from w w w  .j a va  2 s .c om*/
        return ((TextMessage) m).getText();
    } catch (JMSException e) {
        e.printStackTrace(System.out);
        return e.toString();
    }
}

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 {/*  ww  w  .ja  va  2  s  .co 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:org.powertac.visualizer.services.VisualizerServiceTournament.java

@Override
public void onMessage(Message message) {
    lastMsgTime = new Date().getTime();
    //log.info("onMessage");
    if (message instanceof TextMessage) {
        try {/*from w  w w  . j a  va2  s . c  o  m*/
            //log.info("onMessage: text");
            onMessage(((TextMessage) message).getText());
        } catch (JMSException e) {
            log.info("ERROR: viz failed to extract text from TextMessage: " + e.toString());
        }
    }
}

From source file:net.timewalker.ffmq4.listeners.ClientProcessor.java

@Override
public boolean packetReceived(AbstractPacket packet) {
    AbstractQueryPacket query = (AbstractQueryPacket) packet;
    AbstractResponsePacket response = null;

    // Process packet
    try {//from ww w .  ja v a 2 s .co  m
        try {
            response = process(query);
        } catch (JMSException e) {
            log.debug("#" + id + " process() failed with " + e.toString());
            response = new ErrorResponse(e);
        }
    } catch (Exception e) {
        log.error("#" + id + " Cannot process command", e);
    }

    // Send response
    if (response != null && query.isResponseExpected()) {
        // Map endpoint id on response
        response.setEndpointId(query.getEndpointId());

        try {
            if (traceEnabled)
                log.trace("#" + id + " Sending " + response);
            transport.send(response);
        } catch (Exception e) {
            log.warn("#" + id + " Cannot send response to client : " + e.toString());
            transport.close();
        }
    }

    return localConnection != null; // Connection still valid ?
}

From source file:net.timewalker.ffmq4.remote.session.RemoteQueueBrowserEnumeration.java

@Override
public boolean hasMoreElements() {
    if (endOfQueueReached)
        return false;
    try {/*from   w ww. j a v  a 2  s. c  o m*/
        checkNotClosed();
        Message msg = fetchNext();
        return msg != null;
    } catch (JMSException e) {
        throw new IllegalStateException(e.toString());
    }
}

From source file:org.apache.activemq.jms.pool.PooledSession.java

@Override
public void close() throws JMSException {
    if (ignoreClose) {
        return;//from   w w  w .  ja v  a2s. c  o  m
    }

    if (closed.compareAndSet(false, true)) {
        boolean invalidate = false;
        try {
            // lets reset the session
            getInternalSession().setMessageListener(null);

            // Close any consumers and browsers that may have been created.
            for (Iterator<MessageConsumer> iter = consumers.iterator(); iter.hasNext();) {
                MessageConsumer consumer = iter.next();
                consumer.close();
            }

            for (Iterator<QueueBrowser> iter = browsers.iterator(); iter.hasNext();) {
                QueueBrowser browser = iter.next();
                browser.close();
            }

            if (transactional && !isXa) {
                try {
                    getInternalSession().rollback();
                } catch (JMSException e) {
                    invalidate = true;
                    LOG.warn(
                            "Caught exception trying rollback() when putting session back into the pool, will invalidate. "
                                    + e,
                            e);
                }
            }
        } catch (JMSException ex) {
            invalidate = true;
            LOG.warn(
                    "Caught exception trying close() when putting session back into the pool, will invalidate. "
                            + ex,
                    ex);
        } finally {
            consumers.clear();
            browsers.clear();
            for (PooledSessionEventListener listener : this.sessionEventListeners) {
                listener.onSessionClosed(this);
            }
            sessionEventListeners.clear();
        }

        if (invalidate) {
            // lets close the session and not put the session back into the pool
            // instead invalidate it so the pool can create a new one on demand.
            if (sessionHolder != null) {
                try {
                    sessionHolder.close();
                } catch (JMSException e1) {
                    LOG.trace("Ignoring exception on close as discarding session: " + e1, e1);
                }
            }
            try {
                sessionPool.invalidateObject(key, sessionHolder);
            } catch (Exception e) {
                LOG.trace("Ignoring exception on invalidateObject as discarding session: " + e, e);
            }
        } else {
            try {
                sessionPool.returnObject(key, sessionHolder);
            } catch (Exception e) {
                javax.jms.IllegalStateException illegalStateException = new javax.jms.IllegalStateException(
                        e.toString());
                illegalStateException.initCause(e);
                throw illegalStateException;
            }
        }

        sessionHolder = null;
    }
}

From source file:org.apache.aries.transaction.jms.internal.PooledSession.java

@Override
public void close() throws JMSException {
    if (!ignoreClose) {
        boolean invalidate = false;
        try {//  ww  w  .  ja  v a  2 s . c o  m
            // lets reset the session
            getInternalSession().setMessageListener(null);

            // Close any consumers and browsers that may have been created.
            for (Iterator<MessageConsumer> iter = consumers.iterator(); iter.hasNext();) {
                MessageConsumer consumer = iter.next();
                consumer.close();
            }

            for (Iterator<QueueBrowser> iter = browsers.iterator(); iter.hasNext();) {
                QueueBrowser browser = iter.next();
                browser.close();
            }

            if (transactional && !isXa) {
                try {
                    getInternalSession().rollback();
                } catch (JMSException e) {
                    invalidate = true;
                    LOG.warn(
                            "Caught exception trying rollback() when putting session back into the pool, will invalidate. "
                                    + e,
                            e);
                }
            }
        } catch (JMSException ex) {
            invalidate = true;
            LOG.warn(
                    "Caught exception trying close() when putting session back into the pool, will invalidate. "
                            + ex,
                    ex);
        } finally {
            consumers.clear();
            browsers.clear();
            for (PooledSessionEventListener listener : this.sessionEventListeners) {
                listener.onSessionClosed(this);
            }
            sessionEventListeners.clear();
        }

        if (invalidate) {
            // lets close the session and not put the session back into the pool
            // instead invalidate it so the pool can create a new one on demand.
            if (session != null) {
                try {
                    session.close();
                } catch (JMSException e1) {
                    LOG.trace("Ignoring exception on close as discarding session: " + e1, e1);
                }
                session = null;
            }
            try {
                sessionPool.invalidateObject(key, this);
            } catch (Exception e) {
                LOG.trace("Ignoring exception on invalidateObject as discarding session: " + e, e);
            }
        } else {
            try {
                sessionPool.returnObject(key, this);
            } catch (Exception e) {
                javax.jms.IllegalStateException illegalStateException = new javax.jms.IllegalStateException(
                        e.toString());
                illegalStateException.initCause(e);
                throw illegalStateException;
            }
        }
    }
}

From source file:org.apache.jmeter.protocol.jms.sampler.PublisherSampler.java

/**
 * The implementation will publish n messages within a for loop. Once n
 * messages are published, it sets the attributes of SampleResult.
 *
 * @return the populated sample result/*from   w  ww.j  a v a 2  s .c om*/
 */
@Override
public SampleResult sample() {
    SampleResult result = new SampleResult();
    result.setSampleLabel(getName());
    result.setSuccessful(false); // Assume it will fail
    result.setResponseCode("000"); // ditto $NON-NLS-1$
    if (publisher == null) {
        try {
            initClient();
        } catch (JMSException e) {
            result.setResponseMessage(e.toString());
            return result;
        } catch (NamingException e) {
            result.setResponseMessage(e.toString());
            return result;
        }
    }
    StringBuilder buffer = new StringBuilder();
    StringBuilder propBuffer = new StringBuilder();
    int loop = getIterationCount();
    result.sampleStart();
    String type = getMessageChoice();

    try {
        Map<String, Object> msgProperties = getJMSProperties().getJmsPropertysAsMap();
        int deliveryMode = getUseNonPersistentDelivery() ? DeliveryMode.NON_PERSISTENT
                : DeliveryMode.PERSISTENT;
        int priority = Integer.parseInt(getPriority());
        long expiration = Long.parseLong(getExpiration());

        for (int idx = 0; idx < loop; idx++) {
            if (JMSPublisherGui.TEXT_MSG_RSC.equals(type)) {
                String tmsg = getMessageContent();
                Message msg = publisher.publish(tmsg, getDestination(), msgProperties, deliveryMode, priority,
                        expiration);
                buffer.append(tmsg);
                Utils.messageProperties(propBuffer, msg);
            } else if (JMSPublisherGui.MAP_MSG_RSC.equals(type)) {
                Map<String, Object> m = getMapContent();
                Message msg = publisher.publish(m, getDestination(), msgProperties, deliveryMode, priority,
                        expiration);
                Utils.messageProperties(propBuffer, msg);
            } else if (JMSPublisherGui.OBJECT_MSG_RSC.equals(type)) {
                Serializable omsg = getObjectContent();
                Message msg = publisher.publish(omsg, getDestination(), msgProperties, deliveryMode, priority,
                        expiration);
                Utils.messageProperties(propBuffer, msg);
            } else if (JMSPublisherGui.BYTES_MSG_RSC.equals(type)) {
                byte[] bmsg = getBytesContent();
                Message msg = publisher.publish(bmsg, getDestination(), msgProperties, deliveryMode, priority,
                        expiration);
                Utils.messageProperties(propBuffer, msg);
            } else {
                throw new JMSException(type + " is not recognised");
            }
        }
        result.setResponseCodeOK();
        result.setResponseMessage(loop + " messages published");
        result.setSuccessful(true);
        result.setSamplerData(buffer.toString());
        result.setSampleCount(loop);
        result.setRequestHeaders(propBuffer.toString());
    } catch (Exception e) {
        result.setResponseMessage(e.toString());
    } finally {
        result.sampleEnd();
    }
    return result;
}

From source file:org.apache.jmeter.protocol.jms.sampler.SubscriberSampler.java

/**
 * sample method will check which client it should use and call the
 * appropriate client specific sample method.
 *
 * @return the appropriate sample result
 *//*from   w  w  w . jav  a 2s . c o m*/
// TODO - should we call start() and stop()?
@Override
public SampleResult sample() {
    // run threadStarted only if Destination setup on each sample
    if (!isDestinationStatic()) {
        threadStarted(true);
    }
    SampleResult result = new SampleResult();
    result.setDataType(SampleResult.TEXT);
    result.setSampleLabel(getName());
    result.sampleStart();
    if (exceptionDuringInit != null) {
        result.sampleEnd();
        result.setSuccessful(false);
        result.setResponseCode("000");
        result.setResponseMessage(exceptionDuringInit.toString());
        return result;
    }
    if (stopBetweenSamples) { // If so, we need to start collection here
        try {
            SUBSCRIBER.start();
        } catch (JMSException e) {
            log.warn("Problem starting subscriber", e);
        }
    }
    StringBuilder buffer = new StringBuilder();
    StringBuilder propBuffer = new StringBuilder();

    int loop = getIterationCount();
    int read = 0;

    long until = 0L;
    long now = System.currentTimeMillis();
    if (timeout > 0) {
        until = timeout + now;
    }
    while (!interrupted && (until == 0 || now < until) && read < loop) {
        Message msg;
        try {
            msg = SUBSCRIBER.getMessage(calculateWait(until, now));
            if (msg != null) {
                read++;
                extractContent(buffer, propBuffer, msg, (read == loop));
            }
        } catch (JMSException e) {
            log.warn("Error " + e.toString());
        }
        now = System.currentTimeMillis();
    }
    result.sampleEnd();
    if (getReadResponseAsBoolean()) {
        result.setResponseData(buffer.toString().getBytes()); // TODO - charset?
    } else {
        result.setBytes(buffer.toString().length());
    }
    result.setResponseHeaders(propBuffer.toString());
    if (read == 0) {
        result.setResponseCode("404"); // Not found
        result.setSuccessful(false);
    } else if (read < loop) { // Not enough messages found
        result.setResponseCode("500"); // Server error
        result.setSuccessful(false);
    } else {
        result.setResponseCodeOK();
        result.setSuccessful(true);
    }
    result.setResponseMessage(read + " message(s) received successfully of " + loop + " expected");
    result.setSamplerData(loop + " messages expected");
    result.setSampleCount(read);

    if (stopBetweenSamples) {
        try {
            SUBSCRIBER.stop();
        } catch (JMSException e) {
            log.warn("Problem stopping subscriber", e);
        }
    }
    // run threadFinished only if Destination setup on each sample (stop Listen queue)
    if (!isDestinationStatic()) {
        threadFinished(true);
    }
    return result;
}