List of usage examples for javax.jms JMSException getCause
public synchronized Throwable getCause()
From source file:org.apache.servicemix.jbi.cluster.requestor.AbstractJmsRequestorPool.java
private JMSException fixForSpring5470(JMSException ex) { if (ex.getCause() != null && ex.getCause().getMessage() == null) { ex.setLinkedException(new Exception("Unknown", ex.getCause())); }/*ww w . j a va 2s.c om*/ return ex; }
From source file:org.openanzo.combus.bayeux.BridgeConnectionManager.java
/** * Creates a single JMS connection and session for use by the BayeuxJMSBridge. It connects to the combus using a configured sysadmin account. * //from w w w . j a va2 s.co m * @param factory * this will be used to create the JMS connection and session. * @param properties * must contain the username and password * @throws JMSException */ protected void initialize(ConnectionFactory factory, Properties properties) throws AnzoException { try { conn = factory.createConnection(credentials.getUserName(), credentials.getPassword()); conn.setExceptionListener(new ExceptionListener() { public void onException(JMSException exception) { if (!closed) { // if user has not requested disconnect if (exception.getCause() instanceof BrokerStoppedException || exception.getCause() instanceof TransportDisposedIOException) { closed = true; if (conn != null) { try { conn.close(); } catch (JMSException e) { log.debug(LogUtils.COMBUS_MARKER, "Error closing JMS connection", e); } } } else { log.error(LogUtils.COMBUS_MARKER, "Exception over Bayeux JMS connection", exception); } } } }); conn.start(); session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); mp = session.createProducer(null); mp.setDeliveryMode(DeliveryMode.NON_PERSISTENT); // setup all the destination queues destinations.put(COMBUS.NOTIFICATION_SERVICE_QUEUE, session.createQueue(COMBUS.NOTIFICATION_SERVICE_QUEUE)); destinations.put(COMBUS.MODEL_SERVICE_QUEUE, session.createQueue(COMBUS.MODEL_SERVICE_QUEUE)); destinations.put(COMBUS.UPDATE_SERVICE_QUEUE, session.createQueue(COMBUS.UPDATE_SERVICE_QUEUE)); destinations.put(COMBUS.AUTHENTICATION_SERVICE_QUEUE, session.createQueue(COMBUS.AUTHENTICATION_SERVICE_QUEUE)); destinations.put(COMBUS.REPLICATION_SERVICE_QUEUE, session.createQueue(COMBUS.REPLICATION_SERVICE_QUEUE)); destinations.put(COMBUS.QUERY_SERVICE_QUEUE, session.createQueue(COMBUS.QUERY_SERVICE_QUEUE)); destinations.put(COMBUS.RESET_SERVICE_QUEUE, session.createQueue(COMBUS.RESET_SERVICE_QUEUE)); destinations.put(COMBUS.EXECUTION_SERVICE_QUEUE, session.createQueue(COMBUS.EXECUTION_SERVICE_QUEUE)); destinations.put(COMBUS.AUTHORIZATION_SERVICE_QUEUE, session.createQueue(COMBUS.AUTHORIZATION_SERVICE_QUEUE)); } catch (JMSException jmsex) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_CONNECT_FAILED, jmsex); } }
From source file:org.openanzo.combus.CombusConnection.java
private void performConnect() throws JMSException, AnzoException { if (connected || closing) { return;/*from w w w. j a v a2 s.c o m*/ } if (jmsProvider == null) { throw new AnzoException(ExceptionConstants.COMBUS.NOTIFICATION_SERVICE_ERROR); } Properties propertiesNew = new Properties(); CombusProperties.setHost(propertiesNew, host); CombusProperties.setPort(propertiesNew, port); CombusProperties.setUseSsl(propertiesNew, useSsl); ConnectionFactory connectionFactory = jmsProvider.createConnectionFactory(propertiesNew); if (connectionFactory != null) { if (userName != null && password != null) { connection = connectionFactory.createConnection(userName, password); } else { connection = connectionFactory.createConnection(); } connection.setExceptionListener(new ExceptionListener() { public void onException(JMSException exception) { if (!closed) { // if user has not requested disconnect if (exception.getCause() instanceof BrokerStoppedException || exception.getCause() instanceof TransportDisposedIOException) { closed = true; } else { try { fireConnectionStateChange(INotificationConnectionListener.CONNECTIONFAILED); performDisconnect(false); } catch (AnzoException e) { log.error(LogUtils.COMBUS_MARKER, Messages.formatString(ExceptionConstants.COMBUS.JMS_DISCONNECT_FAILED), e); } finally { connected = false; } } } } }); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); destinations.clear(); destinations.put(INotificationRegistrationService.SERVICE_NAME, session.createQueue(COMBUS.NOTIFICATION_SERVICE_QUEUE)); destinations.put(IModelService.SERVICE_NAME, session.createQueue(COMBUS.MODEL_SERVICE_QUEUE)); destinations.put(IAuthorizationService.SERVICE_NAME, session.createQueue(COMBUS.AUTHORIZATION_SERVICE_QUEUE)); destinations.put(IAuthenticationService.SERVICE_NAME, session.createQueue(COMBUS.AUTHENTICATION_SERVICE_QUEUE)); destinations.put(IReplicationService.SERVICE_NAME, session.createQueue(COMBUS.REPLICATION_SERVICE_QUEUE)); destinations.put(IResetService.SERVICE_NAME, session.createQueue(COMBUS.RESET_SERVICE_QUEUE)); destinations.put(IUpdateService.SERVICE_NAME, session.createQueue(COMBUS.UPDATE_SERVICE_QUEUE)); destinations.put(IQueryService.SERVICE_NAME, session.createQueue(COMBUS.QUERY_SERVICE_QUEUE)); destinations.put(IIndexService.SERVICE_NAME, session.createQueue(COMBUS.INDEX_SERVICE_QUEUE)); destinations.put(IExecutionService.SERVICE_NAME, session.createQueue(COMBUS.EXECUTION_SERVICE_QUEUE)); tempQueue = session.createTemporaryQueue(); messageProducer = session.createProducer(null); messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); messageConsumer = session.createConsumer(tempQueue); listener = new JMSMessageListener(); messageConsumer.setMessageListener(listener); connected = true; fireConnectionStateChange(INotificationConnectionListener.CONNECTED); } return; }
From source file:org.openanzo.combus.endpoint.BaseServiceListener.java
private void processMessage(Message request) { try {//from ww w . jav a 2s .c o 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); } }
From source file:org.opencastproject.message.broker.impl.MessageReceiverImpl.java
/** * Private function to get a message or none if there is an error. * * @param destinationId//from w w w.ja v a 2s . com * The destination queue or topic to pull the message from. * @param type * The type of the destination either queue or topic. * @return A message or none if there was a problem getting the message. */ private Option<Message> waitForMessage(String destinationId, DestinationType type) { MessageConsumer consumer = null; try { // Create the destination (Topic or Queue) Destination destination; if (type.equals(DestinationType.Queue)) { destination = getSession().createQueue(destinationId); } else { destination = getSession().createTopic(destinationId); } // Create a MessageConsumer from the Session to the Topic or Queue consumer = getSession().createConsumer(destination); // Wait for a message Message message = consumer.receive(); return Option.option(message); } catch (JMSException e) { if (e instanceof javax.jms.IllegalStateException || e.getCause() instanceof InterruptedException || e.getCause() instanceof InterruptedIOException) { // Swallowing the shutdown exception logger.trace("Shutting down message receiver {}", ExceptionUtils.getStackTrace(e)); } else { logger.error("Unable to receive messages {}", ExceptionUtils.getStackTrace(e)); } return Option.<Message>none(); } finally { try { if (consumer != null) { consumer.close(); } } catch (JMSException e) { logger.error("Unable to close connections after receipt of message {}", ExceptionUtils.getStackTrace(e)); } } }