Example usage for javax.jms JMSException getErrorCode

List of usage examples for javax.jms JMSException getErrorCode

Introduction

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

Prototype

public String getErrorCode() 

Source Link

Document

Gets the vendor-specific error code.

Usage

From source file:dk.netarkivet.common.distribute.JMSConnectionSunMQ.java

/**
 * Exceptionhandler for the JMSConnection. Will try to reconnect on errors
 * with error codes defined in the constant RECONNECT_ERRORCODES.
 *
 * @param e an JMSException/*  w  w w.j  a  v a 2  s . co  m*/
 */
public void onException(JMSException e) {
    ArgumentNotValid.checkNotNull(e, "JMSException e");
    final String errorcode = e.getErrorCode();
    log.warn("JMSException with errorcode '" + errorcode + "' encountered: " + e);

    if (Arrays.asList(RECONNECT_ERRORCODES).contains(errorcode)) {
        reconnect();
    } else {
        log.warn("Exception not handled. " + "Don't know how to handle exceptions with errorcode " + errorcode,
                e);
    }
}

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  va  2 s  .  c om*/
 * @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());
}

From source file:org.grouter.common.jms.QueueSenderDestination.java

/**
 * Connect to queue  and open a session.
 *///from w  w w. ja v  a 2  s.  c o  m
@Override
public void bind() {
    try {
        JNDIUtils.printJNDI(context, logger);
        logger.info("Binding to destination :" + destinationName);

        // Find ConnectionFactory
        queueConnectionFactory = getInstance().getQueueConnectionFactory(connectionFactory, context);
        // Get queue
        queue = getInstance().getQueue(destinationName, context);
        // Create conneciton to queue
        queueConnection = queueConnectionFactory.createQueueConnection();
        // Register an exceptionlistener
        queueConnection.setExceptionListener(exceptionListener);
        queueSession = queueConnection.createQueueSession(isTransactional, acknowledgeMode);

        queueSender = queueSession.createSender(queue);
        if (timeToLive > 0) {
            queueSender.setTimeToLive(timeToLive);
        }
        if (useTemporaryReplyDestination) {
            temporaryQueue = queueSession.createTemporaryQueue();
            logger.debug("TemporaryQueue created for this session " + temporaryQueue);
        }
        queueConnection.start();
        logger.info("Bound to destination " + destinationName);
    } catch (JMSException e) {
        logger.error("Got exception with JMS provider during bind to destination " + destinationName
                + ". Error code : " + e.getErrorCode());
        rebind(this);
    } catch (ServiceLocatorException ex) {
        logger.error("Got exception with JMS provider during bind to destination " + destinationName
                + ". Got error message : " + ex.getMessage());
        rebind(this);
    }
}

From source file:org.grouter.common.jms.TopicListenerDestination.java

/**
 * Connect to topic  and open a session.
 *//*  w  w w. j  a  v a  2 s .  co m*/
@Override
public void bind() {
    try {
        // Find ConnectionFactory
        final TopicConnectionFactory topicConnectionFactory = getInstance()
                .getTopicConnectionFactory(connectionFactory, context);
        // Get queue
        topic = getInstance().getTopic(destinationName, context);
        // Create conneciton to queue
        topicConnection = topicConnectionFactory.createTopicConnection();
        // Register an exceptionlistener
        topicConnection.setExceptionListener(exceptionListener);
        topicSession = topicConnection.createTopicSession(isTransactional, acknowledgeMode);

        messageConsumer = topicSession.createConsumer(topic);

        // Sets the receiver which onMessage method will be called.
        messageConsumer.setMessageListener(listener);

        topicConnection.start();
        logger.info("Bound to destination " + destinationName);
    } catch (JMSException e) {
        logger.error("Got exception with JMS provider during bind to destination " + destinationName
                + ". Error code : " + e.getErrorCode(), e);
        rebind(this);
    } catch (ServiceLocatorException ex) {
        logger.error("Got exception with JMS provider during bind to destination " + destinationName + ".", ex);
        rebind(this);
    }
}

From source file:org.grouter.common.jms.TopicSenderDestination.java

@Override
public void bind() {
    try {/*from  ww  w  .  j  av a 2  s  .c  om*/
        // Find ConnectionFactory
        final TopicConnectionFactory topicConnectionFactory = getInstance()
                .getTopicConnectionFactory(connectionFactory, context);
        // Get queue
        final Topic topic = getInstance().getTopic(destinationName, context);
        // Create conneciton to queue
        topicConnection = topicConnectionFactory.createTopicConnection();
        // Register an exceptionlistener
        topicConnection.setExceptionListener(exceptionListener);
        topicSession = topicConnection.createTopicSession(isTransactional, acknowledgeMode);
        topicPublisher = topicSession.createPublisher(topic);
        if (timeToLive > 0) {
            topicPublisher.setTimeToLive(timeToLive);
        }
        if (useTemporaryReplyDestination) {
            temporaryTopic = topicSession.createTemporaryTopic();
            logger.debug("TemporaryTopic created for this session " + temporaryTopic);
        }
        topicConnection.start();
        logger.info("Bound to destination " + destinationName);
    } catch (JMSException e) {
        logger.error("Got exception with JMS provider during bind to destination " + destinationName
                + ". Error code : " + e.getErrorCode(), e);
        rebind(this);
    } catch (ServiceLocatorException ex) {
        logger.error("Got exception with JMS provider during bind to destination " + destinationName + ".", ex);
        rebind(this);
    }
}

From source file:org.openanzo.combus.endpoint.BaseServiceListener.java

private void processMessage(Message request) {
    try {//w w w.  jav a  2 s .  co m
        IOperationContext context = null;
        TextMessage response = null;
        String operation = request.getStringProperty(SerializationConstants.operation);
        try {
            Destination replyTo = null;
            try {
                if (mp == null) {
                    mp = session.createProducer(null);
                    mp.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
                }
                replyTo = request.getJMSReplyTo();

                String resultFormat = request.getStringProperty(SerializationConstants.resultFormat);
                context = new BaseOperationContext(operation, request.getJMSCorrelationID(), null);
                if (request.propertyExists(SerializationConstants.userDescription)) {
                    context.setAttribute(SerializationConstants.userDescription,
                            request.getStringProperty(SerializationConstants.userDescription));
                }
                if (request.propertyExists(OPTIONS.SKIPCACHE)) {
                    context.setAttribute(OPTIONS.SKIPCACHE, request.getBooleanProperty(OPTIONS.SKIPCACHE));
                }
                if (request.propertyExists(OPTIONS.INCLUDEMETADATAGRAPHS)) {
                    context.setAttribute(OPTIONS.INCLUDEMETADATAGRAPHS,
                            request.getBooleanProperty(OPTIONS.INCLUDEMETADATAGRAPHS));
                }

                AnzoPrincipal callerPrincipal = getContextPrincipal(context, request);
                context.setOperationPrincipal(callerPrincipal);

                if (log.isTraceEnabled()) {
                    log.trace(LogUtils.COMBUS_MARKER,
                            MessageUtils.prettyPrint(request,
                                    "Message Recieved from [" + callerPrincipal.getName() + "]"
                                            + ((replyTo != null) ? (" with replyto [" + replyTo + "]") : "")));
                } else if (log.isDebugEnabled()) {
                    log.debug(LogUtils.COMBUS_MARKER, "Message Recieved from [" + callerPrincipal.getName()
                            + "]" + ((replyTo != null) ? (" with replyto [" + replyTo + "]") : ""));
                }
                context.setMDC();
                Boolean analyzeRequest = request
                        .getBooleanProperty(RequestAnalysis.CONTEXT_PROP_REQUEST_ENABLED);
                if (analyzeRequest || recorder != null) {
                    RequestAnalysis.setCurrentContext(context.getAttributes());
                    RequestAnalysis.setRequestAnalysisEnabled(true);
                }

                if (recorder != null) {
                    recorder.recordRequest((TextMessage) request, request.getStringProperty("JMSXUserID"),
                            request.getStringProperty(SerializationConstants.runAsUser));
                }

                long start = 0, end = 0;
                if (RequestAnalysis.isAnalysisEnabled(context.getAttributes())) {
                    start = System.currentTimeMillis();
                }

                response = handleMessage(context, replyTo, resultFormat, operation, (TextMessage) request, mp);
                if (RequestAnalysis.isAnalysisEnabled(context.getAttributes())) {
                    end = System.currentTimeMillis();
                    RequestAnalysis.addAnalysisProperty(RequestAnalysis.ANS_PROP_OPERATION_TIME,
                            String.valueOf(end - start));
                }

                if (response != null) {
                    response.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION);
                    if (operation != null) {
                        response.setStringProperty(SerializationConstants.operation, operation);
                    }
                    Integer totalSolutions = context.getAttribute(SerializationConstants.totalSolutions,
                            Integer.class);
                    if (totalSolutions != null) {
                        response.setIntProperty(SerializationConstants.totalSolutions,
                                totalSolutions.intValue());
                    }
                    if (analyzeRequest) {
                        for (String name : RequestAnalysis.getAnalysisPropertyNames()) {
                            response.setStringProperty(name, context.getAttribute(name).toString());
                        }
                    }
                }

                if (response != null && replyTo != null) {
                    response.setJMSCorrelationID(request.getJMSCorrelationID());
                    if (log.isTraceEnabled()) {
                        log.trace(LogUtils.COMBUS_MARKER,
                                MessageUtils.prettyPrint(response, "Sending Response to [" + replyTo + "]"));
                    } else if (log.isDebugEnabled()) {
                        log.debug(LogUtils.COMBUS_MARKER, "Sending Response to [" + replyTo + "]");
                    }
                    mp.send(replyTo, response);
                }

            } catch (JMSException jmex) {
                response = sendJMSErrorMessage(replyTo, request, jmex,
                        ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION, jmex.toString());
            } catch (AnzoException jmex) {
                response = sendJMSErrorMessage(replyTo, request, jmex, jmex.getErrorCode(), jmex.getArgs());
            } catch (AnzoRuntimeException jmex) {
                response = sendJMSErrorMessage(replyTo, request, jmex, jmex.getErrorCode(), jmex.getArgs());
            } catch (RuntimeException jmex) {
                response = sendJMSErrorMessage(replyTo, request, jmex,
                        ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION, jmex.toString());
            } catch (Throwable jmex) {
                response = sendJMSErrorMessage(replyTo, request, jmex,
                        ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION, jmex.toString());
            }

            if (recorder != null) {
                if (response != null) {
                    recorder.recordResponse(response);
                } else {
                    recorder.recordResponse(request.getJMSCorrelationID(), operation);
                }
            }
        } finally {
            if (context != null) {
                context.clearMDC();
            }
        }
    } catch (JMSException jmsex) {
        if (jmsex.getCause() instanceof InterruptedException) {
            log.debug(LogUtils.COMBUS_MARKER, "Thread interrupted in order to stop.", jmsex);
        } else {
            log.error(LogUtils.COMBUS_MARKER, "Error in BaseService Listener's process thread loop", jmsex);
        }
    } catch (Throwable jmex) {
        log.error(LogUtils.COMBUS_MARKER, "Error in BaseService Listener's process thread loop", jmex);
    }
}