Class JmsBinding


  • public class JmsBinding
    extends Object
    A Strategy used to convert between a Camel Exchange and Message to and from a JMS Message
    • Constructor Detail

      • JmsBinding

        public JmsBinding​(boolean mapJmsMessage,
                          boolean allowNullBody,
                          org.apache.camel.spi.HeaderFilterStrategy headerFilterStrategy,
                          JmsKeyFormatStrategy jmsJmsKeyFormatStrategy,
                          MessageCreatedStrategy messageCreatedStrategy)
    • Method Detail

      • extractBodyFromJms

        public Object extractBodyFromJms​(org.apache.camel.Exchange exchange,
                                         javax.jms.Message message)
        Extracts the body from the JMS message
        Parameters:
        exchange - the exchange
        message - the message to extract its body
        Returns:
        the body, can be null
      • extractHeadersFromJms

        public Map<String,​Object> extractHeadersFromJms​(javax.jms.Message jmsMessage,
                                                              org.apache.camel.Exchange exchange)
      • getObjectProperty

        public Object getObjectProperty​(javax.jms.Message jmsMessage,
                                        String name)
                                 throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • createByteArrayFromBytesMessage

        protected byte[] createByteArrayFromBytesMessage​(javax.jms.BytesMessage message)
                                                  throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • makeJmsMessage

        public javax.jms.Message makeJmsMessage​(org.apache.camel.Exchange exchange,
                                                org.apache.camel.Message camelMessage,
                                                javax.jms.Session session,
                                                Exception cause)
                                         throws javax.jms.JMSException
        Creates a JMS message from the Camel exchange and message
        Parameters:
        exchange - the current exchange
        camelMessage - the body to make a javax.jms.Message as
        session - the JMS session used to create the message
        cause - optional exception occurred that should be sent as reply instead of a regular body
        Returns:
        a newly created JMS Message instance containing the
        Throws:
        javax.jms.JMSException - if the message could not be created
      • appendJmsProperties

        public void appendJmsProperties​(javax.jms.Message jmsMessage,
                                        org.apache.camel.Exchange exchange,
                                        Map<String,​Object> headers)
                                 throws javax.jms.JMSException
        Appends the JMS headers from the Camel Message
        Throws:
        javax.jms.JMSException
      • appendJmsProperty

        public void appendJmsProperty​(javax.jms.Message jmsMessage,
                                      org.apache.camel.Exchange exchange,
                                      String headerName,
                                      Object headerValue)
                               throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • isStandardJMSHeader

        protected boolean isStandardJMSHeader​(String headerName)
        Is the given header a standard JMS header
        Parameters:
        headerName - the header name
        Returns:
        true if its a standard JMS header
      • getValidJMSHeaderValue

        protected Object getValidJMSHeaderValue​(String headerName,
                                                Object headerValue)
        Strategy to test if the given header is valid according to the JMS spec to be set as a property on the JMS message.

        This default implementation will allow:

        • any primitives and their counter Objects (Integer, Double etc.)
        • String and any other literals, Character, CharSequence
        • Boolean
        • Number
        • java.util.Date
        Parameters:
        headerName - the header name
        headerValue - the header value
        Returns:
        the value to use, null to ignore this header
      • createJmsMessage

        protected javax.jms.Message createJmsMessage​(Exception cause,
                                                     javax.jms.Session session)
                                              throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • createJmsMessage

        protected javax.jms.Message createJmsMessage​(org.apache.camel.Exchange exchange,
                                                     Object body,
                                                     Map<String,​Object> headers,
                                                     javax.jms.Session session,
                                                     org.apache.camel.CamelContext context)
                                              throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • getJMSMessageTypeForBody

        protected JmsMessageType getJMSMessageTypeForBody​(org.apache.camel.Exchange exchange,
                                                          Object body,
                                                          Map<String,​Object> headers,
                                                          javax.jms.Session session,
                                                          org.apache.camel.CamelContext context)
        Return the JmsMessageType
        Returns:
        type or null if no mapping was possible
      • createJmsMessageForType

        protected javax.jms.Message createJmsMessageForType​(org.apache.camel.Exchange exchange,
                                                            Object body,
                                                            javax.jms.Session session,
                                                            org.apache.camel.CamelContext context,
                                                            JmsMessageType type)
                                                     throws javax.jms.JMSException
        Create the Message
        Returns:
        jmsMessage or null if the mapping was not successfully
        Throws:
        javax.jms.JMSException
      • populateMapMessage

        protected void populateMapMessage​(javax.jms.MapMessage message,
                                          Map<?,​?> map,
                                          org.apache.camel.CamelContext context)
                                   throws javax.jms.JMSException
        Populates a MapMessage from a Map instance.
        Throws:
        javax.jms.JMSException
      • createMapFromMapMessage

        public Map<String,​Object> createMapFromMapMessage​(javax.jms.MapMessage message)
                                                         throws javax.jms.JMSException
        Extracts a Map from a MapMessage
        Throws:
        javax.jms.JMSException
      • shouldOutputHeader

        protected boolean shouldOutputHeader​(String headerName,
                                             Object headerValue,
                                             org.apache.camel.Exchange exchange)
        Strategy to allow filtering of headers which are put on the JMS message

        Note: Currently only supports sending java identifiers as keys