Class JMSFacade

java.lang.Object
org.frankframework.jndi.JndiBase
org.frankframework.jms.JMSFacade
All Implemented Interfaces:
HasPhysicalDestination, IConfigurable, IConfigurationAware, INamedObject, IScopeProvider, IXAEnabled, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware
Direct Known Subclasses:
JmsListenerBase, JmsMessageBrowser, JmsSender

public class JMSFacade extends JndiBase implements HasPhysicalDestination, IXAEnabled
Provides functions for jms connections, queues and topics and acts as a facade to hide for clients whether a Queue or Topic is used.
The destinationType field specifies which type should be used.
This class sends messages with JMS.
Author:
Gerrit van Brakel
  • Field Details

  • Constructor Details

    • JMSFacade

      public JMSFacade()
  • Method Details

    • setMessageClass

      public void setMessageClass(JMSFacade.MessageClass messageClass)
      The JMS Message class for the outgoing message. Currently supported are JMSFacade.MessageClass.TEXT for JMS TextMessage, JMSFacade.MessageClass.BYTES for JMS BytesMessage, or JMSFacade.MessageClass.AUTO for auto-determination based on whether the input Message is binary or character.

      Defaults to JMSFacade.MessageClass.AUTO, unless the default is overridden in AppConstants with property jms.messageClass.default

    • getLogPrefix

      protected String getLogPrefix()
    • configure

      public void configure() throws ConfigurationException
      Specified by:
      configure in interface IConfigurable
      Overrides:
      configure in class JndiBase
      Throws:
      ConfigurationException
    • getConnectionFactoryName

      public String getConnectionFactoryName() throws JmsException
      Throws:
      JmsException
    • getManagedConnectionFactory

      public Object getManagedConnectionFactory() throws JmsException
      Throws:
      JmsException
    • getConnectionFactoryInfo

      public String getConnectionFactoryInfo() throws JmsException
      Throws:
      JmsException
    • getJmsMessagingSource

      protected JmsMessagingSource getJmsMessagingSource() throws JmsException
      Throws:
      JmsException
    • getMessagingSourceFactory

      protected MessagingSourceFactory getMessagingSourceFactory()
    • getMessagingSource

      protected MessagingSource getMessagingSource() throws JmsException
      Throws:
      JmsException
    • createSession

      protected javax.jms.Session createSession() throws JmsException
      Returns a session on the connection for a topic or a queue
      Throws:
      JmsException
    • closeSession

      protected void closeSession(javax.jms.Session session)
    • open

      public void open() throws Exception
      Obtains a connection and a serviceQueue.
      Throws:
      Exception
    • close

      public void close()
      Releases references to serviceQueue and connection.
      Overrides:
      close in class JndiBase
    • createMessage

      @Nonnull public javax.jms.Message createMessage(javax.jms.Session session, String correlationID, Message message) throws javax.jms.JMSException, IOException
      Throws:
      javax.jms.JMSException
      IOException
    • createMessage

      @Nonnull public javax.jms.Message createMessage(javax.jms.Session session, String correlationID, Message message, JMSFacade.MessageClass messageClass) throws javax.jms.JMSException, IOException
      Throws:
      javax.jms.JMSException
      IOException
    • createBytesMessage

      @Nonnull protected javax.jms.Message createBytesMessage(javax.jms.Session session, String correlationID, Message message) throws javax.jms.JMSException, IOException
      Throws:
      javax.jms.JMSException
      IOException
    • createTextMessage

      @Nonnull protected javax.jms.TextMessage createTextMessage(javax.jms.Session session, String correlationID, Message message) throws javax.jms.JMSException, IOException
      Throws:
      javax.jms.JMSException
      IOException
    • setMessageCorrelationID

      public void setMessageCorrelationID(javax.jms.Message message, String correlationID) throws javax.jms.JMSException
      Throws:
      javax.jms.JMSException
    • getDestination

      public javax.jms.Destination getDestination() throws JmsException
      Throws:
      JmsException
    • getDestination

      public javax.jms.Destination getDestination(String destinationName)
    • getMessageConsumerForCorrelationId

      public javax.jms.MessageConsumer getMessageConsumerForCorrelationId(javax.jms.Session session, javax.jms.Destination destination, String correlationId) throws javax.jms.JMSException
      Gets a MessageConsumer object for either Topics or Queues.
      Returns:
      a MessageConsumer with the right filter (messageSelector)
      Throws:
      javax.jms.JMSException
    • getMessageConsumer

      public javax.jms.MessageConsumer getMessageConsumer(javax.jms.Session session, javax.jms.Destination destination, String selector) throws javax.jms.JMSException
      Create a MessageConsumer. In this overloaded function the selector is taken into account. This ensures that listeners (or other extensions of this class) do not influence how the selector is used: when a correlationID should be in the filter the getMessageConsumerForCorrelationId should be used, otherwise the getMessageConsumer function which has no attribute for selector. When a MessageSelector is set, it will be used when no correlation id is required.
      Parameters:
      session - the Session
      destination - the Destination
      selector - the MessageSelector
      Returns:
      MessageConsumer
      Throws:
      javax.jms.JMSException
    • getMessageConsumer

      public javax.jms.MessageConsumer getMessageConsumer(javax.jms.Session session, javax.jms.Destination destination) throws javax.jms.JMSException
      Create a MessageConsumer, on a specific session and for a specific destination. This functions hides wether we work via Topics or Queues and whether a messageSelector is set.
      Parameters:
      session - the Session
      destination - the Destination
      Returns:
      the MessageConsumer
      Throws:
      javax.jms.JMSException
    • getMessageProducer

      public javax.jms.MessageProducer getMessageProducer(javax.jms.Session session, javax.jms.Destination destination) throws javax.jms.JMSException
      Throws:
      javax.jms.JMSException
    • getPhysicalDestinationShortName

      public String getPhysicalDestinationShortName()
    • getPhysicalDestinationShortName

      public String getPhysicalDestinationShortName(boolean throwException) throws JmsException
      Throws:
      JmsException
    • getPhysicalDestinationName

      public String getPhysicalDestinationName()
      Specified by:
      getPhysicalDestinationName in interface HasPhysicalDestination
    • send

      public String send(javax.jms.Session session, javax.jms.Destination dest, String correlationId, Message message, String messageType, long timeToLive, int deliveryMode, int priority) throws javax.jms.JMSException, SenderException, IOException
      Throws:
      javax.jms.JMSException
      SenderException
      IOException
    • send

      public String send(javax.jms.Session session, javax.jms.Destination dest, String correlationId, Message message, String messageType, long timeToLive, int deliveryMode, int priority, boolean ignoreInvalidDestinationException) throws javax.jms.JMSException, SenderException, IOException
      Throws:
      javax.jms.JMSException
      SenderException
      IOException
    • send

      public String send(javax.jms.Session session, javax.jms.Destination dest, String correlationId, Message message, String messageType, long timeToLive, int deliveryMode, int priority, boolean ignoreInvalidDestinationException, Map<String,Object> properties) throws javax.jms.JMSException, SenderException, IOException
      Throws:
      javax.jms.JMSException
      SenderException
      IOException
    • send

      public String send(javax.jms.MessageProducer messageProducer, javax.jms.Message message) throws javax.jms.JMSException
      Send a message
      Parameters:
      messageProducer -
      message -
      Returns:
      messageID of sent message
      Throws:
      javax.jms.JMSException
    • send

      public String send(javax.jms.MessageProducer messageProducer, javax.jms.Message message, boolean ignoreInvalidDestinationException) throws javax.jms.JMSException
      Throws:
      javax.jms.JMSException
    • logMessageDetails

      protected void logMessageDetails(javax.jms.Message message, javax.jms.MessageProducer messageProducer) throws javax.jms.JMSException
      Throws:
      javax.jms.JMSException
    • send

      public String send(javax.jms.Session session, javax.jms.Destination dest, javax.jms.Message message) throws javax.jms.JMSException
      Send a message
      Parameters:
      session -
      dest - destination
      message -
      Returns:
      message ID of the sent message
      Throws:
      javax.jms.JMSException
    • send

      public String send(javax.jms.Session session, javax.jms.Destination dest, javax.jms.Message message, boolean ignoreInvalidDestinationException) throws javax.jms.JMSException
      Throws:
      javax.jms.JMSException
    • sendByQueue

      protected String sendByQueue(javax.jms.QueueSession session, javax.jms.Queue destination, javax.jms.Message message) throws javax.jms.JMSException
      Throws:
      javax.jms.JMSException
    • sendByTopic

      protected String sendByTopic(javax.jms.TopicSession session, javax.jms.Topic destination, javax.jms.Message message) throws javax.jms.JMSException
      Throws:
      javax.jms.JMSException
    • isSessionsArePooled

      public boolean isSessionsArePooled()
    • getContext

      public MessageContext getContext(javax.jms.Message message) throws javax.jms.JMSException
      Throws:
      javax.jms.JMSException
    • extractMessage

      public Message extractMessage(javax.jms.Message jmsMessage, Map<String,Object> context, boolean soap, String soapHeaderSessionKey, SoapWrapper soapWrapper) throws javax.jms.JMSException, SAXException, TransformerException, IOException, XmlException
      Extracts string from message obtained from getRawMessage(Map). May also extract other parameters from the message and put those in the threadContext.

      Supports only TextMessages and BytesMessage.

      Throws:
      javax.jms.JMSException
      SAXException
      TransformerException
      IOException
      XmlException
    • extractMessageBody

      protected Message extractMessageBody(Message message, Map<String,Object> context, SoapWrapper soapWrapper) throws SAXException, TransformerException, IOException, XmlException
      Throws:
      SAXException
      TransformerException
      IOException
      XmlException
    • checkTransactionManagerValidity

      public void checkTransactionManagerValidity()
    • toString

      public String toString()
      Overrides:
      toString in class JndiBase
    • setDestinationName

      public void setDestinationName(String destinationName)
      Name of the JMS destination (queue or topic) to use
    • setDestinationType

      public void setDestinationType(JMSFacade.DestinationType destinationType)
      Type of the messageing destination. This function also sets the useTopicFunctions field, that controls whether Topic functions are used or Queue functions.
      Default value
      QUEUE
    • setAcknowledgeMode

      public void setAcknowledgeMode(JMSFacade.AcknowledgeMode acknowledgeMode)
      If not transacted, the way the application informs the JMS provider that it has successfully received a message.
      Default value
      auto
    • setPersistent

      @Deprecated public void setPersistent(boolean value)
      Deprecated.
      Controls whether messages are processed persistently. When set true, the JMS provider ensures that messages aren't lost when the application might crash.
    • setSubscriberType

      public void setSubscriberType(JMSFacade.SubscriberType subscriberType)
      Only applicable for topics
      Default value
      DURABLE
    • setQueueConnectionFactoryName

      public void setQueueConnectionFactoryName(String name)
      Used when destinationType = QUEUE. The JNDI-name of the queueConnectionFactory to use to connect to a queue if isTransacted() returns false. The corresponding connection factory should be configured not to support XA transactions.
    • setTopicConnectionFactoryName

      public void setTopicConnectionFactoryName(String topicConnectionFactoryName)
      Used when destinationType = TOPIC. The JNDI-name of the connection factory to use to connect to a topic if isTransacted() returns false. The corresponding connection factory should be configured not to support XA transactions.
    • setJmsTransacted

      @Deprecated public void setJmsTransacted(boolean jmsTransacted)
      Deprecated.
      This attribute has been added to provide the pre-4.1 transaction functionality to configurations that relied this specific functionality. New configurations should not use it.
      Controls the use of JMS transacted session. In versions prior to 4.1, this attribute was called plainly 'transacted'. The transacted attribute, however, is now in uses to indicate the use of XA-transactions. XA transactions can be used in a pipeline to simultaneously (in one transaction) commit or rollback messages send to a number of queues, or even together with database actions.
      Since:
      4.1
    • setTransacted

      public void setTransacted(boolean transacted)
      Controls whether messages are send under transaction control. If set true, messages are committed or rolled back under control of an XA-transaction.
      Default value
      false
    • setCorrelationIdToHex

      public void setCorrelationIdToHex(boolean correlationIdToHex)
      Transform the value of the correlationid to a hexadecimal value if it starts with id: (preserving the id: part). Useful when sending messages to MQ which expects this value to be in hexadecimal format when it starts with id:, otherwise generating the error: MQJMS1044: String is not a valid hexadecimal number
      Default value
      false
    • setCorrelationIdToHexPrefix

      public void setCorrelationIdToHexPrefix(String correlationIdToHexPrefix)
      Prefix to check before executing correlationIdToHex. If empty (and correlationIdToHex equals true) all correlationid's are transformed, this is useful in case you want the entire correlationId to be transformed (for example when the receiving party doesn't allow characters like a colon to be present in the correlationId).
      Default value
      id:
    • setMessageTimeToLive

      public void setMessageTimeToLive(long ttl)
      The time in milliseconds it takes for the message to expire. If the message is not consumed before, it will be lost. Must be a positive value for request/reply type of messages, 0 disables the expiry timeout
      Default value
      0
    • setCorrelationIdMaxLength

      public void setCorrelationIdMaxLength(int i)
      If set (>=0) and the length of the correlationId exceeds this maximum length, the correlationId is trimmed from the left side of a string to this maximum length
      Default value
      -1
    • setMessageSelector

      public void setMessageSelector(String newMessageSelector)
      If set, the value of this attribute is used as a selector to filter messages.
      Default value
      0 (unlimited)
    • setAuthAlias

      public void setAuthAlias(String string)
      Alias used to obtain credentials for authentication to JMS server
    • setLookupDestination

      public void setLookupDestination(boolean b)
      If set false, the destinationName is used directly instead of performing a JNDI lookup
      Default value
      true
    • getDomain

      public String getDomain()
      Specified by:
      getDomain in interface HasPhysicalDestination
    • getMessageClass

      public JMSFacade.MessageClass getMessageClass()
    • isTransacted

      public boolean isTransacted()
      Description copied from interface: IXAEnabled
      indicates implementing object is under transaction control, using XA-transactions
      Specified by:
      isTransacted in interface IXAEnabled
    • isJmsTransacted

      public boolean isJmsTransacted()
    • getSubscriberType

      public JMSFacade.SubscriberType getSubscriberType()
    • getAcknowledgeMode

      public JMSFacade.AcknowledgeMode getAcknowledgeMode()
    • isPersistent

      public boolean isPersistent()
    • getMessageTimeToLive

      public long getMessageTimeToLive()
    • getDestinationName

      public String getDestinationName()
    • isUseTopicFunctions

      public boolean isUseTopicFunctions()
    • getAuthAlias

      public String getAuthAlias()
    • isLookupDestination

      public boolean isLookupDestination()
    • getDestinationType

      public JMSFacade.DestinationType getDestinationType()
    • setConnectionFactoryFactory

      public void setConnectionFactoryFactory(IConnectionFactoryFactory connectionFactoryFactory)
    • getConnectionFactoryFactory

      public IConnectionFactoryFactory getConnectionFactoryFactory()
    • setProxiedDestinationNames

      public void setProxiedDestinationNames(Map<String,String> proxiedDestinationNames)
    • getProxiedDestinationNames

      public Map<String,String> getProxiedDestinationNames()
    • getQueueConnectionFactoryName

      public String getQueueConnectionFactoryName()
    • getTopicConnectionFactoryName

      public String getTopicConnectionFactoryName()
    • getMessageSelector

      public String getMessageSelector()
    • isCorrelationIdToHex

      public boolean isCorrelationIdToHex()
    • getCorrelationIdToHexPrefix

      public String getCorrelationIdToHexPrefix()
    • getCorrelationIdMaxLength

      public int getCorrelationIdMaxLength()
    • getTxManager

      public org.springframework.transaction.PlatformTransactionManager getTxManager()
    • setTxManager

      public void setTxManager(org.springframework.transaction.PlatformTransactionManager txManager)