Class JMSUtils


  • public class JMSUtils
    extends BaseUtils
    Miscallaneous methods used for the JMS transport
    • Constructor Detail

      • JMSUtils

        public JMSUtils()
    • Method Detail

      • isJMSService

        public static boolean isJMSService​(AxisService service)
        Should this service be enabled over the JMS transport?
        Parameters:
        service - the Axis service
        Returns:
        true if JMS should be enabled
      • getProperty

        public static String getProperty​(javax.jms.Message message,
                                         String property)
        Get a String property from the JMS message
        Parameters:
        message - JMS message
        property - property name
        Returns:
        property value
      • getDestination

        public static String getDestination​(String url)
        Return the destination name from the given URL
        Parameters:
        url - the URL
        Returns:
        the destination name
      • setSOAPEnvelope

        public static void setSOAPEnvelope​(javax.jms.Message message,
                                           MessageContext msgContext,
                                           String contentType)
                                    throws AxisFault,
                                           javax.jms.JMSException
        Set the SOAPEnvelope to the Axis2 MessageContext, from the JMS Message passed in
        Parameters:
        message - the JMS message read
        msgContext - the Axis2 MessageContext to be populated
        contentType - content type for the message
        Throws:
        AxisFault
        javax.jms.JMSException
      • setReplyDestination

        public static javax.jms.Destination setReplyDestination​(javax.jms.Destination replyDestination,
                                                                javax.jms.Session session,
                                                                javax.jms.Message message)
        Set the JMS ReplyTo for the message
        Parameters:
        replyDestination - the JMS Destination where the reply is expected
        session - the session to use to create a temp Queue if a response is expected but a Destination has not been specified
        message - the JMS message where the final Destinatio would be set as the JMS ReplyTo
        Returns:
        the JMS ReplyTo Destination for the message
      • setTransportHeaders

        public static void setTransportHeaders​(MessageContext msgContext,
                                               javax.jms.Message message)
                                        throws javax.jms.JMSException
        Set transport headers from the axis message context, into the JMS message
        Parameters:
        msgContext - the axis message context
        message - the JMS Message
        Throws:
        javax.jms.JMSException - on exception
      • loadTransportHeaders

        public static void loadTransportHeaders​(javax.jms.Message message,
                                                MessageContext responseMsgCtx)
                                         throws AxisFault
        Read the transport headers from the JMS Message and set them to the axis2 message context
        Parameters:
        message - the JMS Message received
        responseMsgCtx - the axis message context
        Throws:
        AxisFault - on error
      • getTransportHeaders

        public static Map<String,​Object> getTransportHeaders​(javax.jms.Message message)
        Extract transport level headers for JMS from the given message into a Map
        Parameters:
        message - the JMS message
        Returns:
        a Map of the transport headers
      • createConsumer

        public static javax.jms.MessageConsumer createConsumer​(javax.jms.Session session,
                                                               javax.jms.Destination dest,
                                                               String messageSelector)
                                                        throws javax.jms.JMSException
        Create a MessageConsumer for the given Destination
        Parameters:
        session - JMS Session to use
        dest - Destination for which the Consumer is to be created
        messageSelector - the message selector to be used if any
        Returns:
        a MessageConsumer for the specified Destination
        Throws:
        javax.jms.JMSException
      • createTemporaryDestination

        public static javax.jms.Destination createTemporaryDestination​(javax.jms.Session session)
                                                                throws javax.jms.JMSException
        Create a temp queue or topic for synchronous receipt of responses, when a reply destination is not specified
        Parameters:
        session - the JMS Session to use
        Returns:
        a temporary Queue or Topic, depending on the session
        Throws:
        javax.jms.JMSException
      • getBodyLength

        public static long getBodyLength​(javax.jms.BytesMessage bMsg)
        Return the body length in bytes for a bytes message
        Parameters:
        bMsg - the JMS BytesMessage
        Returns:
        length of body in bytes
      • getMessageSize

        public static long getMessageSize​(javax.jms.Message message)
                                   throws javax.jms.JMSException
        Get the length of the message in bytes
        Parameters:
        message -
        Returns:
        message size (or approximation) in bytes
        Throws:
        javax.jms.JMSException
      • createConnection

        public static javax.jms.Connection createConnection​(javax.jms.ConnectionFactory conFac,
                                                            String user,
                                                            String pass,
                                                            boolean jmsSpec11,
                                                            Boolean isQueue)
                                                     throws javax.jms.JMSException
        This is a JMS spec independent method to create a Connection. Please be cautious when making any changes
        Parameters:
        conFac - the ConnectionFactory to use
        user - optional user name
        pass - optional password
        jmsSpec11 - should we use JMS 1.1 API ?
        isQueue - is this to deal with a Queue?
        Returns:
        a JMS Connection as requested
        Throws:
        javax.jms.JMSException - on errors, to be handled and logged by the caller
      • createSession

        public static javax.jms.Session createSession​(javax.jms.Connection connection,
                                                      boolean transacted,
                                                      int ackMode,
                                                      boolean jmsSpec11,
                                                      Boolean isQueue)
                                               throws javax.jms.JMSException
        This is a JMS spec independent method to create a Session. Please be cautious when making any changes
        Parameters:
        connection - the JMS Connection
        transacted - should the session be transacted?
        ackMode - the ACK mode for the session
        jmsSpec11 - should we use the JMS 1.1 API?
        isQueue - is this Session to deal with a Queue?
        Returns:
        a Session created for the given information
        Throws:
        javax.jms.JMSException - on errors, to be handled and logged by the caller
      • createConsumer

        public static javax.jms.MessageConsumer createConsumer​(javax.jms.Session session,
                                                               javax.jms.Destination destination,
                                                               Boolean isQueue,
                                                               String subscriberName,
                                                               String messageSelector,
                                                               boolean pubSubNoLocal,
                                                               boolean isDurable,
                                                               boolean jmsSpec11)
                                                        throws javax.jms.JMSException
        This is a JMS spec independent method to create a MessageConsumer. Please be cautious when making any changes
        Parameters:
        session - JMS session
        destination - the Destination
        isQueue - is the Destination a queue?
        subscriberName - optional client name to use for a durable subscription to a topic
        messageSelector - optional message selector
        pubSubNoLocal - should we receive messages sent by us during pub-sub?
        isDurable - is this a durable topic subscription?
        jmsSpec11 - should we use JMS 1.1 API ?
        Returns:
        a MessageConsumer to receive messages
        Throws:
        javax.jms.JMSException - on errors, to be handled and logged by the caller
      • createProducer

        public static javax.jms.MessageProducer createProducer​(javax.jms.Session session,
                                                               javax.jms.Destination destination,
                                                               Boolean isQueue,
                                                               boolean jmsSpec11)
                                                        throws javax.jms.JMSException
        This is a JMS spec independent method to create a MessageProducer. Please be cautious when making any changes
        Parameters:
        session - JMS session
        destination - the Destination
        isQueue - is the Destination a queue?
        jmsSpec11 - should we use JMS 1.1 API ?
        Returns:
        a MessageProducer to send messages to the given Destination
        Throws:
        javax.jms.JMSException - on errors, to be handled and logged by the caller
      • getDestinationTypeAsString

        public static String getDestinationTypeAsString​(int destType)
        Return a String representation of the destination type
        Parameters:
        destType - the destination type indicator int
        Returns:
        a descriptive String
      • lookupDestination

        public static javax.jms.Destination lookupDestination​(Context context,
                                                              String destinationName,
                                                              String destinationType)
                                                       throws NamingException
        Return the JMS destination with the given destination name looked up from the context
        Parameters:
        context - the Context to lookup
        destinationName - name of the destination to be looked up
        destinationType - type of the destination to be looked up
        Returns:
        the JMS destination, or null if it does not exist
        Throws:
        NamingException