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:org.genemania.broker.Worker.java

public synchronized void onMessage(Message msg) {
    if (msg instanceof TextMessage) {
        String responseBody = "";
        try {/*  w  ww.j av a  2  s.c o m*/
            // extract message data
            Queue queue = (Queue) msg.getJMSDestination();
            requestMessage = (TextMessage) msg;
            LOG.debug("new " + msg.getJMSType() + " message received on queue " + queue.getQueueName()
                    + "[correlation id: " + msg.getJMSCorrelationID() + "]");
            responseMessage = session.createTextMessage();
            responseMessage.setJMSDestination(requestMessage.getJMSReplyTo());
            responseMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
            responseMessage.setJMSCorrelationID(msg.getJMSCorrelationID());
            // invoke engine
            if (queue.getQueueName().equalsIgnoreCase(mqRequestsQueueName)) {
                if (MessageType.RELATED_GENES.equals(MessageType.fromCode(msg.getJMSType()))) {
                    RelatedGenesRequestMessage data = RelatedGenesRequestMessage
                            .fromXml(requestMessage.getText());
                    RelatedGenesResponseMessage response = getRelatedGenes(data);
                    responseBody = response.toXml();
                } else if (MessageType.TEXT2NETWORK.equals(MessageType.fromCode(msg.getJMSType()))) {
                    UploadNetworkRequestMessage data = UploadNetworkRequestMessage
                            .fromXml(requestMessage.getText());
                    UploadNetworkResponseMessage response = uploadNetwork(data);
                    responseBody = response.toXml();
                } else if (MessageType.PROFILE2NETWORK.equals(MessageType.fromCode(msg.getJMSType()))) {
                    LOG.warn("invoking engine.profile2network: not implemented");
                } else {
                    LOG.warn("Unknown jms type: " + msg.getJMSType());
                }
            }
            processedMessages++;
        } catch (JMSException e) {
            LOG.error(e);
            try {
                responseBody = buildErrorMessage(e.getMessage(), MessageType.fromCode(msg.getJMSType()));
            } catch (JMSException x) {
                LOG.error(x);
            }
        } finally {
            if ((requestMessage != null) && (responseMessage != null)) {
                try {
                    if (StringUtils.isNotEmpty(responseBody)) {
                        responseMessage.setText(responseBody);
                        LOG.debug("Responding to " + responseMessage.getJMSDestination() + ", msg id "
                                + responseMessage.getJMSCorrelationID() + ", response body size "
                                + (int) responseBody.length());
                        responseHandler.send(responseMessage.getJMSDestination(), responseMessage);
                    } else {
                        responseBody = buildErrorMessage("Empty response body detected",
                                MessageType.fromCode(msg.getJMSType()));
                    }
                } catch (JMSException e) {
                    LOG.error("JMS Exception: " + e.getMessage());
                    try {
                        responseBody = buildErrorMessage(e.getMessage(),
                                MessageType.fromCode(msg.getJMSType()));
                        responseHandler.send(responseMessage);
                    } catch (JMSException e1) {
                        LOG.error("JMS Exception", e1);
                    }
                }
            } else {
                if (requestMessage == null) {
                    LOG.error("request message is null");
                }
                if (responseMessage == null) {
                    LOG.error("response message is null");
                }
            }
        }
    } else {
        LOG.warn("Unknown message type: " + msg);
    }
    LOG.info("successfully processed messages: " + processedMessages);
}

From source file:org.genemania.connector.JmsEngineConnector.java

@Cacheable(cacheName = "searchResultsCache", keyGenerator = @KeyGenerator(name = "StringCacheKeyGenerator"))
public RelatedGenesWebResponseDto getRelatedGenes(final RelatedGenesWebRequestDto dto)
        throws ApplicationException {
    final String rgcid = String.valueOf(System.currentTimeMillis());
    RelatedGenesWebResponseDto ret = new RelatedGenesWebResponseDto();
    jmsTemplate.send(requestQueue, new MessageCreator() {
        public TextMessage createMessage(Session session) throws JMSException {
            LOG.debug("sending GetRelatedGenesMessage request to " + requestQueue.getQueueName());
            RelatedGenesRequestMessage request = BrokerUtils.dto2msg(dto);
            TextMessage ret = session.createTextMessage(request.toXml());
            ret.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
            ret.setJMSType(MessageType.RELATED_GENES.getCode());
            replyQueue = session.createTemporaryQueue();
            ret.setJMSReplyTo(replyQueue);
            ret.setJMSCorrelationID(rgcid);
            LOG.debug("getRelatedGenes waiting for reply on " + replyQueue.getQueueName());
            return ret;
        }//from   ww w.ja  v  a  2  s.  c o m
    });
    sentMessages++;
    Message response;
    try {
        response = jmsTemplate.receive(replyQueue);
        receivedMessages++;
        if (response == null) {
            LOG.error("getRelatedGenes JMS response is null");
        } else if (!response.getJMSCorrelationID().equals(rgcid)) {
            LOG.error("JMS response id does not match request, sent " + rgcid + ", recieved "
                    + response.getJMSCorrelationID() + ", dropping response.");
        } else {
            LOG.debug("getRelatedGenes reply received");
            String responseBody = ((TextMessage) response).getText();
            if (StringUtils.isNotEmpty(responseBody)) {
                RelatedGenesResponseMessage responseMessage = RelatedGenesResponseMessage.fromXml(responseBody);
                LOG.debug("finished fromXml");
                LOG.debug("num attributes in response message: " + responseMessage.getAttributes().size());
                if (responseMessage.getErrorCode() == 0) {
                    // friendlyPrintNetworks("networks in response message: ",
                    // responseMessage.getNetworks());
                    // friendlyPrintCategories("categories in response message: ",
                    // responseMessage.getAnnotations());
                    RelatedGenesWebResponseDto hollowResponseDto = BrokerUtils.msg2dto(responseMessage);
                    LOG.debug("finished msg2dto");
                    ret = load(hollowResponseDto);
                    LOG.debug("finished hollowResponseDto");
                } else {
                    LOG.error(responseMessage.getErrorMessage());
                    appErrors++;
                    throw new ApplicationException(responseMessage.getErrorMessage(),
                            responseMessage.getErrorCode());
                }
            } else {
                LOG.error("getRelatedGenes empty response body");
            }
        }
        processedMessages++;
    } catch (JMSException e) {
        LOG.error("getRelatedGenes JMSException: " + e.getMessage());
        errors++;
        throw new ApplicationException(Constants.ERROR_CODES.APPLICATION_ERROR);
    } catch (DataStoreException e) {
        LOG.error("getRelatedGenes DataStoreException: " + e.getMessage());
        errors++;
        throw new ApplicationException(Constants.ERROR_CODES.DATA_ERROR);
    } finally {
        LOG.debug("messages sent/received/processed/errors: " + sentMessages + "/" + receivedMessages + "/"
                + processedMessages + "/" + errors);
        // updateStats();
    }
    LOG.debug("getRelatedGenes request processing completed");
    return ret;
}

From source file:org.sakaiproject.kernel.messaging.email.EmailMessageListener.java

/**
 * {@inheritDoc}/*from   w w  w  . j  a v a2s . c  o  m*/
 *
 * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
 */
public void onMessage(javax.jms.Message jmsMsg) {
    if (jmsMsg instanceof ObjectMessage) {
        ObjectMessage objMsg = (ObjectMessage) jmsMsg;
        try {
            // get the email message and break out the parts
            Message email = (Message) objMsg.getObject();
            handleMessage(email);
        } catch (JMSException e) {
            // TODO log for now. We need to return a message to the sender that
            // something died while processing this message
            LOG.error(e.getMessage(), e);
        } catch (AddressException e) {
            LOG.error(e.getMessage(), e);
        } catch (UnsupportedEncodingException e) {
            LOG.error(e.getMessage(), e);
        } catch (SendFailedException e) {
            LOG.error(e.getMessage(), e);
        } catch (MessagingException e) {
            LOG.error(e.getMessage(), e);
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        }
    }
}

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

/**
 * {@inheritDoc}/*from   w  w  w. j  a  v a  2  s. c om*/
 */
public void subscribe(Subscription subscription) throws EventBrokerException {

    if (isDeactivated()) {
        return;
    }

    // in a multi tenant environment deployment synchronize may creates subscriptions before
    // the event observer get activated.
    if (this.subscriptionIDSessionDetailsMap.containsKey(subscription.getId())) {
        log.warn(
                "There is an subscription already exists for the subscription with id " + subscription.getId());
        return;
    }
    JMSMessageListener jmsMessageListener = new JMSMessageListener(this.notificationManager, subscription);
    try {
        TopicConnection topicConnection = getTopicConnection(subscription.getOwner());
        TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        String topicName = "";
        if (subscription.getTenantDomain() != null && (!subscription.getTenantDomain()
                .equals(org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME))) {

            if (!subscription.getTopicName().startsWith("/")) {
                topicName = getTopicName(subscription.getTenantDomain() + "/" + subscription.getTopicName());
            } else {
                topicName = getTopicName(subscription.getTenantDomain() + subscription.getTopicName());
            }
        } else {
            topicName = getTopicName(subscription.getTopicName());
        }
        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);
        }
        TopicSubscriber topicSubscriber = topicSession.createDurableSubscriber(topic, subscription.getId());
        topicSubscriber.setMessageListener(jmsMessageListener);

        this.subscriptionIDSessionDetailsMap.put(subscription.getId(),
                new JMSSubscriptionDetails(topicSubscriber, topicSession, topicConnection));
    } catch (JMSException e) {
        throw new EventBrokerException(
                "Can not subscribe to topic " + subscription.getTopicName() + " " + e.getMessage(), e);
    }
}

From source file:org.logicblaze.lingo.jmx.remote.jms.JmsJmxConnector.java

/**
 * <p>//  w w w  . java  2 s. c  o m
 * Establishes the connection to the connector server.
 * </p>
 * 
 * <p>
 * If <code>connect</code> has already been called successfully on this object, calling it again has no effect.
 * If, however, {@link #close} was called after <code>connect</code>, the new <code>connect</code> will throw
 * an <code>IOException</code>.
 * <p>
 * 
 * <p>
 * Otherwise, either <code>connect</code> has never been called on this object, or it has been called but produced
 * an exception. Then calling <code>connect</code> will attempt to establish a connection to the connector server.
 * </p>
 * 
 * @param env
 *            the properties of the connection. Properties in this map override properties in the map specified when
 *            the <code>JMXConnector</code> was created, if any. This parameter can be null, which is equivalent
 *            to an empty map.
 * 
 * @exception IOException
 *                if the connection could not be made because of a communication problem.
 * 
 * @exception SecurityException
 *                if the connection could not be made for security reasons.
 */
public void connect(Map env) throws IOException {
    if (!connected) {
        proxy = new JmsProxyFactoryBean();
        proxy.setServiceInterface(javax.management.MBeanServerConnection.class);
        ConnectionFactory fac = new ActiveMQConnectionFactory(jmsURL);
        if (destinationName == null) {
            destinationName = JmsJmxConnectorSupport.DEFAULT_DESTINATION_PREFIX + destinationGroupName + "."
                    + destinationServerName;
        }
        try {
            // this will start all the gubbins
            Destination destination = new ActiveMQTopic(destinationName);
            proxy.setDestination(destination);
            proxy.setConnectionFactory(fac);
            requestor = (MultiplexingRequestor) MultiplexingRequestor.newInstance(fac, new JmsProducerConfig(),
                    destination);
            proxy.setRequestor(requestor);
            proxy.setServiceInterface(MBeanJmsServerConnection.class);
            proxy.afterPropertiesSet();
            sendConnectionNotificationOpened();
            client = new MBeanJmsServerConnectionClient((MBeanJmsServerConnection) proxy.getObject(),
                    requestor.getConnection());
        } catch (JMSException e) {
            log.error("Failed to connect: " + e, e);
            IOException ioe = new IOException(e.getMessage());
            throw ioe;
        }
        connected = true;
    }
}

From source file:se.inera.intyg.rehabstod.service.monitoring.HealthCheckServiceImpl.java

private boolean checkJmsConnection() {
    try {//  w  w  w . j av a 2  s  .c  om
        Connection connection = connectionFactory.createConnection();
        connection.close();
    } catch (JMSException e) {
        LOG.error("checkJmsConnection failed with JMSException: {}", e);
        return false;
    } catch (Exception e) {
        LOG.error(String.format("checkJmsConnection failed with exception of class: %s. Message: %s",
                e.getClass().getName(), e.getMessage()), e);
        return false;
    }
    return true;
}

From source file:com.aol.advertising.qiao.emitter.AMQEmitter.java

@Override
public void process(Object data) {
    try {//w w  w  .  j a  v  a2 s. c  o  m
        Producer producer = getProducer();
        Message msg = msgCreator.createMessage(producer.session, data);
        if (msg != null) {
            if (logger.isDebugEnabled())
                logger.debug("send> " + data.toString());

            long ts_start = System.nanoTime();
            producer.send(msg);
            long dur = System.nanoTime() - ts_start;
            stats.update(dur);

            numDispatched.incrementAndGet();
        }
    } catch (JMSException e) {
        logger.warn(e.getClass().getName() + ": " + e.getMessage());
        running = false;
    } catch (QiaoOperationException e) {
        logger.error(e.getMessage(), e);
        running = false;
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
        running = false;
    }

}

From source file:org.sakaiproject.kernel.email.outgoing.OutgoingEmailMessageListener.java

protected void activate(ComponentContext ctx) {
    @SuppressWarnings("unchecked")
    Dictionary props = ctx.getProperties();

    Integer _maxRetries = (Integer) props.get(MAX_RETRIES);
    if (_maxRetries != null) {
        if (diff(maxRetries, _maxRetries)) {
            maxRetries = _maxRetries;/*from w  ww . j  av  a2 s.  co m*/
        }
    } else {
        LOGGER.error("Maximum times to retry messages not set.");
    }

    Integer _retryInterval = (Integer) props.get(RETRY_INTERVAL);
    if (_retryInterval != null) {
        if (diff(_retryInterval, retryInterval)) {
            retryInterval = _retryInterval;
        }
    } else {
        LOGGER.error("SMTP retry interval not set.");
    }

    if (maxRetries * retryInterval < 4320 /* minutes in 3 days */) {
        LOGGER.warn("SMTP retry window is very short.");
    }

    Integer _smtpPort = (Integer) props.get(SMTP_PORT);
    boolean validPort = _smtpPort != null && _smtpPort >= 0 && _smtpPort <= 65535;
    if (validPort) {
        if (diff(smtpPort, _smtpPort)) {
            smtpPort = _smtpPort;
        }
    } else {
        LOGGER.error("Invalid port set for SMTP");
    }

    String _smtpServer = (String) props.get(SMTP_SERVER);
    boolean smtpServerEmpty = _smtpServer == null || _smtpServer.trim().length() == 0;
    if (!smtpServerEmpty) {
        if (diff(smtpServer, _smtpServer)) {
            smtpServer = _smtpServer;
        }
    } else {
        LOGGER.error("No SMTP server set");
    }

    String _brokerUrl = (String) props.get(BROKER_URL);

    try {
        boolean urlEmpty = _brokerUrl == null || _brokerUrl.trim().length() == 0;
        if (!urlEmpty) {
            if (diff(brokerUrl, _brokerUrl)) {
                LOGGER.info("Creating a new ActiveMQ Connection Factory");
                connectionFactory = connFactoryService.createFactory(_brokerUrl);
            }

            if (connectionFactory != null) {
                connection = connectionFactory.createConnection();
                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                Topic dest = session.createTopic(TOPIC_NAME);
                MessageConsumer consumer = session.createConsumer(dest);
                consumer.setMessageListener(this);
                connection.start();
            }
        } else {
            LOGGER.error("Cannot create JMS connection factory with an empty URL.");
        }
        brokerUrl = _brokerUrl;
    } catch (JMSException e) {
        LOGGER.error(e.getMessage(), e);
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e1) {
            }
        }
    }
}

From source file:org.sdnmq.jms.PacketHandler.java

/**
 * Adds properties to a message according to IEEE802.1q frame information.
 * // w  ww  .  j a  v a2s .c o m
 * @param ieee8021q the IEEE802.q frame
 * @param json the JSON object to which the information will be added
 */
private void ieee8021qToProperties(IEEE8021Q ieee8021q, Message msg) {
    try {
        msg.setShortProperty(MessageFilterAttributes.Keys.DL_VLAN.toFilterName(), (short) ieee8021q.getVid());
    } catch (JMSException e) {
        log.error(e.getMessage());
    }

    try {
        msg.setByteProperty(MessageFilterAttributes.Keys.DL_VLAN_PR.toFilterName(), ieee8021q.getPcp());
    } catch (JMSException e) {
        log.error(e.getMessage());
    }
}

From source file:org.sdnmq.jms.PacketHandler.java

/**
 * Adds properties to a message according to TCP datagram header fields.
 * /*from  ww  w .j av  a  2 s . co  m*/
 * @param tcp the TCP datagram
 * @param msg the message to which the information will be added
 */
private void tcpToProperties(TCP tcp, Message msg) {
    try {
        msg.setShortProperty(MessageFilterAttributes.Keys.TP_SRC.toFilterName(), tcp.getSourcePort());
    } catch (JMSException e) {
        log.error(e.getMessage());
    }

    try {
        msg.setShortProperty(MessageFilterAttributes.Keys.TP_DST.toFilterName(), tcp.getDestinationPort());
    } catch (JMSException e) {
        log.error(e.getMessage());
    }
}