javax.jms.JMSException#setLinkedException ( )源码实例Demo

下面列出了javax.jms.JMSException#setLinkedException ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pooled-jms   文件: JMSExceptionSupport.java
/**
 * 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;
}
 
源代码2 项目: activemq-artemis   文件: ActiveMQConnection.java
@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;
}
 
源代码3 项目: activemq-artemis   文件: ActiveMQObjectMessage.java
@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;
      }
   }
}
 
源代码4 项目: qpid-jms   文件: JmsExceptionSupport.java
/**
 * 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;
}
 
源代码5 项目: spring-analysis-note   文件: JmsTemplateTests.java
@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);
}
 
源代码6 项目: java-technology-stack   文件: JmsTemplateTests.java
@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);
}
 
源代码7 项目: spring4-understanding   文件: JmsTemplateTests.java
@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);
}
 
源代码8 项目: activemq-artemis   文件: ActiveMQBytesMessage.java
@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;
   }

}
 
源代码9 项目: lemon   文件: ProxyMessageConsumer.java
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();
}
 
源代码10 项目: qpid-jms   文件: ProviderException.java
public JMSException toJMSException() {
    final JMSException jmsEx = new JMSException(getMessage());
    jmsEx.initCause(this);
    jmsEx.setLinkedException(this);
    return jmsEx;
}