Java Code Examples for javax.jms.JMSException#setLinkedException()

The following examples show how to use javax.jms.JMSException#setLinkedException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JMSExceptionSupport.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Creates or passes through a JMSException to be thrown to the client.
 *
 * In the event that the exception passed to this method is already a
 * JMSException it is passed through unmodified, otherwise a new JMSException
 * is created with the given message and the cause is set to the given
 * cause Throwable instance.
 *
 * @param message
 *        The message value to set when a new JMSException is created.
 * @param cause
 *        The exception that caused this error state.
 *
 * @return a JMSException instance.
 */
public static JMSException create(String message, Throwable cause) {
    if (cause instanceof JMSException) {
        return (JMSException) cause;
    }

    if (cause.getCause() instanceof JMSException) {
        return (JMSException) cause.getCause();
    }

    if (message == null || message.isEmpty()) {
        message = cause.getMessage();
        if (message == null || message.isEmpty()) {
            message = cause.toString();
        }
    }

    JMSException exception = new JMSException(message);
    if (cause instanceof Exception) {
        exception.setLinkedException((Exception) cause);
    }
    exception.initCause(cause);
    return exception;
}
 
Example 2
Source File: ActiveMQConnection.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public void setClientID(final String clientID) throws JMSException {
   checkClosed();

   if (this.clientID != null) {
      throw new IllegalStateException("Client id has already been set");
   }

   if (!justCreated) {
      throw new IllegalStateException("setClientID can only be called directly after the connection is created");
   }

   try {
      validateClientID(initialSession, clientID);
      this.clientID = clientID;
      this.addSessionMetaData(initialSession);
   } catch (ActiveMQException e) {
      JMSException ex = new JMSException("Internal error setting metadata jms-client-id");
      ex.setLinkedException(e);
      ex.initCause(e);
      throw ex;
   }

   justCreated = false;
}
 
Example 3
Source File: ActiveMQObjectMessage.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public void setObject(final Serializable object) throws JMSException {
   checkWrite();

   if (object != null) {
      try {
         ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);

         ObjectOutputStream oos = new ObjectOutputStream(baos);

         oos.writeObject(object);

         oos.flush();

         data = baos.toByteArray();
      } catch (Exception e) {
         JMSException je = new JMSException("Failed to serialize object");
         je.setLinkedException(e);
         je.initCause(e);
         throw je;
      }
   }
}
 
Example 4
Source File: JmsExceptionSupport.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Creates or passes through a JMSException to be thrown to the client.
 *
 * In the event that the exception passed to this method is already a
 * JMSException it is passed through unmodified, otherwise a new JMSException
 * is created with the given message and the cause is set to the given
 * cause Throwable instance.
 *
 * @param message
 *        The message value to set when a new JMSException is created.
 * @param cause
 *        The exception that caused this error state.
 *
 * @return a JMSException instance.
 */
public static JMSException create(String message, Throwable cause) {
    if (cause instanceof JMSException) {
        return (JMSException) cause;
    }

    if (cause.getCause() instanceof JMSException) {
        return (JMSException) cause.getCause();
    } else if (cause instanceof ProviderException) {
        return ((ProviderException) cause).toJMSException();
    }

    if (message == null || message.isEmpty()) {
        message = cause.getMessage();
        if (message == null || message.isEmpty()) {
            message = cause.toString();
        }
    }

    JMSException exception = new JMSException(message);
    if (cause instanceof Exception) {
        exception.setLinkedException((Exception) cause);
    }
    exception.initCause(cause);
    return exception;
}
 
Example 5
Source File: JmsTemplateTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testExceptionStackTrace() {
	JMSException jmsEx = new JMSException("could not connect");
	Exception innerEx = new Exception("host not found");
	jmsEx.setLinkedException(innerEx);
	JmsException springJmsEx = JmsUtils.convertJmsAccessException(jmsEx);
	StringWriter sw = new StringWriter();
	PrintWriter out = new PrintWriter(sw);
	springJmsEx.printStackTrace(out);
	String trace = sw.toString();
	assertTrue("inner jms exception not found", trace.indexOf("host not found") > 0);
}
 
Example 6
Source File: JmsTemplateTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testExceptionStackTrace() {
	JMSException jmsEx = new JMSException("could not connect");
	Exception innerEx = new Exception("host not found");
	jmsEx.setLinkedException(innerEx);
	JmsException springJmsEx = JmsUtils.convertJmsAccessException(jmsEx);
	StringWriter sw = new StringWriter();
	PrintWriter out = new PrintWriter(sw);
	springJmsEx.printStackTrace(out);
	String trace = sw.toString();
	assertTrue("inner jms exception not found", trace.indexOf("host not found") > 0);
}
 
Example 7
Source File: JmsTemplateTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testExceptionStackTrace() {
	JMSException jmsEx = new JMSException("could not connect");
	Exception innerEx = new Exception("host not found");
	jmsEx.setLinkedException(innerEx);
	JmsException springJmsEx = JmsUtils.convertJmsAccessException(jmsEx);
	StringWriter sw = new StringWriter();
	PrintWriter out = new PrintWriter(sw);
	springJmsEx.printStackTrace(out);
	String trace = sw.toString();
	assertTrue("inner jms exception not found", trace.indexOf("host not found") > 0);
}
 
Example 8
Source File: ActiveMQBytesMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void writeUTF(final String value) throws JMSException {
   checkWrite();
   try {
      bytesWriteUTF(message.getBodyBuffer(), value);
   } catch (Exception e) {
      JMSException je = new JMSException("Failed to write UTF");
      je.setLinkedException(e);
      je.initCause(e);
      throw je;
   }

}
 
Example 9
Source File: ProxyMessageConsumer.java    From lemon with Apache License 2.0 5 votes vote down vote up
public Message receive(long timeout) throws JMSException {
    try {
        Thread.sleep(timeout);
    } catch (InterruptedException ex) {
        logger.warn(ex.getMessage(), ex);

        JMSException jmsException = new JMSException(ex.getMessage());
        jmsException.setLinkedException(ex);
        throw jmsException;
    }

    return getMessage();
}
 
Example 10
Source File: ProviderException.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public JMSException toJMSException() {
    final JMSException jmsEx = new JMSException(getMessage());
    jmsEx.initCause(this);
    jmsEx.setLinkedException(this);
    return jmsEx;
}