List of usage examples for javax.jms JMSException initCause
public synchronized Throwable initCause(Throwable cause)
From source file:it.geosolutions.geoserver.jms.JMSPublisher.java
/** * Used to publish the event on the queue. * //from www .java 2 s . c om * @param <S> a serializable object * @param <O> the object to serialize using a JMSEventHandler * @param destination * @param jmsTemplate the template to use to publish on the topic <br> * (default destination should be already set) * @param props the JMSProperties used by this instance of GeoServer * @param object the object (or event) to serialize and send on the JMS topic * * @throws JMSException */ public <S extends Serializable, O> void publish(final Topic destination, final JmsTemplate jmsTemplate, final Properties props, final O object) throws JMSException { try { final JMSEventHandler<S, O> handler = jmsManager.getHandler(object); // set the used SPI props.put(JMSEventHandlerSPI.getKeyName(), handler.getGeneratorClass().getSimpleName()); // TODO make this configurable final MessageCreator creator = new JMSObjectMessageCreator(handler.serialize(object), props); jmsTemplate.send(destination, creator); } catch (Exception e) { if (LOGGER.isLoggable(java.util.logging.Level.SEVERE)) { LOGGER.severe(e.getLocalizedMessage()); } final JMSException ex = new JMSException(e.getLocalizedMessage()); ex.initCause(e); throw ex; } }
From source file:it.geosolutions.geoserver.jms.client.JMSQueueListener.java
@Override public void onMessage(Message message, Session session) throws JMSException { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message event for session: " + session.toString()); }//w w w . j ava2 s . c o m // CHECKING LISTENER STATUS if (!isEnabled()) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message is swallowed since this component is disabled"); } return; } // FILTERING INCOMING MESSAGE if (!message.propertyExists(JMSConfiguration.INSTANCE_NAME_KEY)) { throw new JMSException("Unable to handle incoming message, property \'" + JMSConfiguration.INSTANCE_NAME_KEY + "\' not set."); } // FILTERING INCOMING MESSAGE if (!message.propertyExists(JMSConfiguration.GROUP_KEY)) { throw new JMSException( "Unable to handle incoming message, property \'" + JMSConfiguration.GROUP_KEY + "\' not set."); } // check if message comes from a master with the same name of this slave if (message.getStringProperty(JMSConfiguration.INSTANCE_NAME_KEY) .equals(config.getConfiguration(JMSConfiguration.INSTANCE_NAME_KEY))) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message discarded: source is equal to destination"); } // if so discard the message return; } // check if message comes from a different group final String group = message.getStringProperty(JMSConfiguration.GROUP_KEY); final String localGroup = config.getConfiguration(JMSConfiguration.GROUP_KEY); if (!group.equals(localGroup)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message discarded: incoming group-->" + group + " is different from the local one-->" + localGroup); } // if so discard the message return; } // check the property which define the SPI used (to serialize on the // server side). if (!message.propertyExists(JMSEventHandlerSPI.getKeyName())) throw new JMSException("Unable to handle incoming message, property \'" + JMSEventHandlerSPI.getKeyName() + "\' not set."); // END -> FILTERING INCOMING MESSAGE // get the name of the SPI used to serialize the message final String generatorClass = message.getStringProperty(JMSEventHandlerSPI.getKeyName()); if (generatorClass == null || generatorClass.isEmpty()) { throw new IllegalArgumentException("Unable to handle a message without a generator class name"); } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine( "Incoming message was serialized using an handler generated by: \'" + generatorClass + "\'"); } // USING INCOMING MESSAGE if (message instanceof ObjectMessage) { final ObjectMessage objMessage = (ObjectMessage) (message); final Serializable obj = objMessage.getObject(); try { // lookup the SPI handler, search is performed using the // name final JMSEventHandler<Serializable, Object> handler = jmsManager .getHandlerByClassName(generatorClass); if (handler == null) { throw new JMSException("Unable to find SPI named \'" + generatorClass + "\', be shure to load that SPI into your context."); } final Enumeration<String> keys = message.getPropertyNames(); final Properties options = new Properties(); while (keys.hasMoreElements()) { String key = keys.nextElement(); options.put(key, message.getObjectProperty(key)); } handler.setProperties(options); // try to synchronize object locally if (!handler.synchronize(handler.deserialize(obj))) { throw new JMSException("Unable to synchronize message locally.\n SPI: " + generatorClass); } } catch (Exception e) { final JMSException jmsE = new JMSException(e.getLocalizedMessage()); jmsE.initCause(e); throw jmsE; } } else throw new JMSException("Unrecognized message type for catalog incoming event"); }
From source file:com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.java
/** * Sets SQS endpoint and wraps IllegalArgumentException. * //from w ww . j a v a 2 s . co m * @param endpoint * The endpoint (ex: "sqs.us-east-1.amazonaws.com") of the region * specific AWS endpoint this client will communicate with. * @throws JMSException */ public void setEndpoint(String endpoint) throws JMSException { try { amazonSQSClient.setEndpoint(endpoint); } catch (IllegalArgumentException ase) { JMSException jmsException = new JMSException(ase.getMessage()); throw (JMSException) jmsException.initCause(ase); } }
From source file:com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.java
/** * Sets SQS region and wraps <code>IllegalArgumentException</code>. This is the recommend * way to set-up the SQS end-points./*from w w w . j ava 2 s .co m*/ * * @param region * The region this client will communicate with. See * {@link Region#getRegion(com.amazonaws.regions.Regions)} for * accessing a given region. * @throws JMSException */ public void setRegion(Region region) throws JMSException { try { amazonSQSClient.setRegion(region); } catch (IllegalArgumentException ase) { JMSException jmsException = new JMSException(ase.getMessage()); throw (JMSException) jmsException.initCause(ase); } }
From source file:com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.java
private JMSException handleException(AmazonClientException e, String operationName) throws JMSException { JMSException jmsException; if (e instanceof AmazonServiceException) { AmazonServiceException se = (AmazonServiceException) e; if (e instanceof QueueDoesNotExistException) { jmsException = new InvalidDestinationException(logAndGetAmazonServiceException(se, operationName), se.getErrorCode());//from www .j ava2s .c o m } else if (isJMSSecurityException(se)) { jmsException = new JMSSecurityException(logAndGetAmazonServiceException(se, operationName), se.getErrorCode()); } else { jmsException = new JMSException(logAndGetAmazonServiceException(se, operationName), se.getErrorCode()); } } else { jmsException = new JMSException(logAndGetAmazonClientException(e, operationName)); } jmsException.initCause(e); return jmsException; }
From source file:org.apache.activemq.jms.pool.PooledConnectionFactory.java
private JMSException createJmsException(String msg, Exception cause) { JMSException exception = new JMSException(msg); exception.setLinkedException(cause); exception.initCause(cause); return exception; }
From source file:org.apache.camel.component.jms.JmsBinding.java
/** * //w ww. j av a2 s . co m * Create the {@link Message} * * @return jmsMessage or null if the mapping was not successfully */ protected Message createJmsMessageForType(Exchange exchange, Object body, Map<String, Object> headers, Session session, CamelContext context, JmsMessageType type) throws JMSException { switch (type) { case Text: { TextMessage message = session.createTextMessage(); String payload = context.getTypeConverter().convertTo(String.class, exchange, body); message.setText(payload); return message; } case Bytes: { BytesMessage message = session.createBytesMessage(); byte[] payload = context.getTypeConverter().convertTo(byte[].class, exchange, body); message.writeBytes(payload); return message; } case Map: { MapMessage message = session.createMapMessage(); Map payload = context.getTypeConverter().convertTo(Map.class, exchange, body); populateMapMessage(message, payload, context); return message; } case Object: Serializable payload; try { payload = context.getTypeConverter().mandatoryConvertTo(Serializable.class, exchange, body); } catch (NoTypeConversionAvailableException e) { // cannot convert to serializable then thrown an exception to avoid sending a null message JMSException cause = new MessageFormatException(e.getMessage()); cause.initCause(e); throw cause; } return session.createObjectMessage(payload); default: break; } return null; }
From source file:org.fusesource.jms.pool.XaConnectionPool.java
public Session createSession(boolean transacted, int ackMode) throws JMSException { PooledSession session = null;/* w w w . j a v a 2 s . com*/ try { boolean isXa = (transactionManager != null && transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION); if (isXa) { transacted = true; ackMode = Session.SESSION_TRANSACTED; session = (PooledSession) super.createXaSession(transacted, ackMode); session.setIgnoreClose(true); session.setIsXa(true); transactionManager.getTransaction().registerSynchronization(new Synchronization(session)); incrementReferenceCount(); transactionManager.getTransaction().enlistResource(createXaResource(session)); } else { session = (PooledSession) super.createSession(transacted, ackMode); session.setIgnoreClose(false); } return session; } catch (RollbackException e) { final JMSException jmsException = new JMSException("Rollback Exception"); jmsException.initCause(e); throw jmsException; } catch (SystemException e) { final JMSException jmsException = new JMSException("System Exception"); jmsException.initCause(e); throw jmsException; } }
From source file:org.mule.transport.jms.JmsMessageUtils.java
private static Message outputHandlerToMessage(OutputHandler value, Session session) throws JMSException { ByteArrayOutputStream output = new ByteArrayOutputStream(); try {// w ww . j a v a 2s . co m value.write(null, output); } catch (IOException e) { JMSException j = new JMSException("Could not serialize OutputHandler."); j.initCause(e); throw j; } BytesMessage bMsg = session.createBytesMessage(); bMsg.writeBytes(output.toByteArray()); return bMsg; }