Class JmsUtils

java.lang.Object
org.springframework.jms.support.JmsUtils

public abstract class JmsUtils extends Object
Generic utility methods for working with JMS. Mainly for internal use within the framework, but also useful for custom JMS access code.
Since:
1.1
Author:
Juergen Hoeller, Sam Brannen
  • Constructor Details

    • JmsUtils

      public JmsUtils()
  • Method Details

    • closeConnection

      public static void closeConnection(@Nullable Connection con)
      Close the given JMS Connection and ignore any thrown exception.

      This is useful for typical finally blocks in manual JMS code.

      Parameters:
      con - the JMS Connection to close (may be null)
    • closeConnection

      public static void closeConnection(@Nullable Connection con, boolean stop)
      Close the given JMS Connection and ignore any thrown exception.

      This is useful for typical finally blocks in manual JMS code.

      Parameters:
      con - the JMS Connection to close (may be null)
      stop - whether to call stop() before closing
    • closeSession

      public static void closeSession(@Nullable Session session)
      Close the given JMS Session and ignore any thrown exception.

      This is useful for typical finally blocks in manual JMS code.

      Parameters:
      session - the JMS Session to close (may be null)
    • closeMessageProducer

      public static void closeMessageProducer(@Nullable MessageProducer producer)
      Close the given JMS MessageProducer and ignore any thrown exception.

      This is useful for typical finally blocks in manual JMS code.

      Parameters:
      producer - the JMS MessageProducer to close (may be null)
    • closeMessageConsumer

      public static void closeMessageConsumer(@Nullable MessageConsumer consumer)
      Close the given JMS MessageConsumer and ignore any thrown exception.

      This is useful for typical finally blocks in manual JMS code.

      Parameters:
      consumer - the JMS MessageConsumer to close (may be null)
    • closeQueueBrowser

      public static void closeQueueBrowser(@Nullable QueueBrowser browser)
      Close the given JMS QueueBrowser and ignore any thrown exception.

      This is useful for typical finally blocks in manual JMS code.

      Parameters:
      browser - the JMS QueueBrowser to close (may be null)
    • closeQueueRequestor

      public static void closeQueueRequestor(@Nullable QueueRequestor requestor)
      Close the given JMS QueueRequestor and ignore any thrown exception.

      This is useful for typical finally blocks in manual JMS code.

      Parameters:
      requestor - the JMS QueueRequestor to close (may be null)
    • commitIfNecessary

      public static void commitIfNecessary(Session session) throws JMSException
      Commit the Session if not within a JTA transaction.
      Parameters:
      session - the JMS Session to commit
      Throws:
      JMSException - if committing failed
    • rollbackIfNecessary

      public static void rollbackIfNecessary(Session session) throws JMSException
      Roll back the Session if not within a JTA transaction.
      Parameters:
      session - the JMS Session to rollback
      Throws:
      JMSException - if committing failed
    • buildExceptionMessage

      public static String buildExceptionMessage(JMSException ex)
      Build a descriptive exception message for the given JMSException, incorporating a linked exception's message if appropriate.
      Parameters:
      ex - the JMSException to build a message for
      Returns:
      the descriptive message String
      See Also:
    • convertJmsAccessException

      public static JmsException convertJmsAccessException(JMSException ex)
      Convert the specified checked JMSException to a Spring runtime JmsException equivalent.
      Parameters:
      ex - the original checked JMSException to convert
      Returns:
      the Spring runtime JmsException wrapping the given exception