org.osesb.msgrouting.configuration
Class MessageRouterConfiguration

java.lang.Object
  extended by org.osesb.configuration.XMLConfiguration
      extended by org.osesb.msgrouting.configuration.MessageRouterConfiguration

public class MessageRouterConfiguration
extends XMLConfiguration

XML configuration for a MessageRouter.

MessageRouterConfiguration encapsulates:

  1. A configuration for a XMLMessageTypeHelper, which extracts message types from a XML message. XMLMessageTypeHelper(s) are configured by the <xmlMessagetypeHelperConfiguration> element of the MessageRouterConfiguration and the XMLMessageTypeHelperConfiguration class is used to encapsulate this configuration element.
  2. A map of message types to MessagePipelines, which is used to route messages to MessagePipeline(s) for processing. See the org.osesb.messagepipeline package. The map is configured by the <messagetype-to-messagepipeline-map> element of the MessageRouterConfiguration. A org.osesb.configuration.XMLMappedConfiguration is used to encapsulate this configuration element.

A message entering osESB through one of the transport handlers (see the org.osesb.transporthandlers package) must have a message type. Since osESB is configured mostly to handle XML messages (possibly with attachments) the message type is a QName where the namespaceURI is the namespace of the XML message and the local part is given by an element or attribute in the message.

Transport handlers and ClientGateway(s) use a MessageRouter to route messages to a org.osesb.messagepipeline.MessagePipeline for processing. The MessageRouter selects the MessagePipeline based on the message's messageType. The MessageRouter uses the <messagetype-to-messagepipeline-map> configuration element of a MessageRouterConfiguration to map message types to MessagePipelines.

Example <messagetype-to-messagepipeline-map> content model:

<messagetype-to-messagepipeline-map key-class="org.osesb.configuration.QNameMapEntry">
          <!-- Five different cdOrder messageTypes for testing MessageRouter and ClientGateway.
      See MessageRouter#main() and ClientGateway#main() -->
          <message-type namespaceURI="http://osesb.test.com/cdcatalog" localPart="cdOrder_1">
              <message-pipeline-configuration enabled=""
                                              configFile="org/osesb/msgrouting/test/deployabletestpackage1/message-pipeline-1-test-config.xml"/>
          </message-type>
          <!-- cdcatalog.xml -->
          <message-type namespaceURI="http://osesb.test.com/cdcatalog" localPart="cdOrder_2">
              <message-pipeline-configuration enabled=""
                                              configFile="org/osesb/msgrouting/test/deployabletestpackage1/message-pipeline-2-test-config.xml"/>
          </message-type>
          <!-- cdcatalog.xml -->
          <message-type namespaceURI="http://osesb.test.com/cdcatalog" localPart="cdOrder_3">
              <message-pipeline-configuration enabled=""
                                              configFile="org/osesb/msgrouting/test/deployabletestpackage1/message-pipeline-3-test-config.xml"/>
          </message-type>
          <!-- cdcatalog.xml -->
          <message-type namespaceURI="http://osesb.test.com/cdcatalog" localPart="cdOrder_4">
              <message-pipeline-configuration enabled=""
                                              configFile="org/osesb/msgrouting/test/deployabletestpackage1/message-pipeline-4-test-config.xml"/>
          </message-type>
          <!-- cdcatalog.xml -->
          <message-type namespaceURI="http://osesb.test.com/cdcatalog" localPart="cdOrder_5">
              <message-pipeline-configuration enabled=""
                                              configFile="org/osesb/msgrouting/test/deployabletestpackage1/message-pipeline-5-test-config.xml"/>
          </message-type>
          <!-- attachments-1.xml -->
          <message-type namespaceURI="http://osesb.test.com/attachment" localPart="processAttachments">
              <message-pipeline-configuration enabled=""
                                              configFile="org/osesb/msgrouting/test/deployabletestpackage1/message-pipeline-6-test-config.xml"/>
          </message-type>
      </messagetype-to-messagepipeline-map>
 

See the org.osesb.messagepipeline package. See the org.osesb.transporthandlers package in the transport-handlers module.

There are two ways that the message type for message is determined:

  1. Transport handlers and ClientGateway(s) can be configured with a static messageType. In this case all messages arriving at a transport handler will be assigned the same message type and all messages sent to osESB by a ClientGateway are assigned the same message type.
  2. If a transport handler or ClientGateway is not configured with a static message type, then the configured MessageRouter uses a XMLMessageTypeHelper to extract a message type from the incoming XML message.

The optional XMLMessageTypeHelper is configured by the <xmlMessagetypeHelperConfiguration> content model element of the MessageRouterConfiguration, which looks like:

<xmlMessagetypeHelperConfiguration>
              <!-- The MessagetypeHelper class. -->
              <helper-class>org.osesb.msgrouting.test.CustomTestXMLMessageTypeHelper_Test2</helper-class>
              <!--
                  A fully qualified helper configuration class name is optional.

                  If <helper-config> is empty, then this element is not used.
                  If <helper-config> is not empty, then the specified class is
                  constructed from the <helper-config> element. If <helper-config>
                  is not empty and this element is not specified, then a XMLConfiguration
                  is constructed from the <helper-config> element.

                  If a helper configuration is constructed, then it is passed
                  to the constructor of the <helper-class> when the helper class
                  is constructed by MessageRouter.
              -->
              <helper-config-class>org.osesb.msgrouting.configuration.XMLMessageTypeXPathExpressionListConfiguratio</helper-config-class>
              <helper-config>...the configuration content model for the helper class...</helper-config>
      </xmlMessagetypeHelperConfiguration>
 

DefaultXMLMessageTypeHelper is the default XMLMessageTypeHelper class and is constructed with a XMLMessageTypeXPathExpressionListConfiguration. DefaultXMLMessageTypeHelper applies the configured XPath expressions to a XML message until a messageType is determined. DefaultXMLMessageTypeHelper#getMessagetype() returns the messageType as a QName, where the namespaceURI is the XML document namespace (if any) and the localPart is the value for the element or attribute that is given by a XPath expression.

To configure a MessageRouter with a different XMLMessageTypeHelper, create a class that extends AbstractXMLMessageTypeHelper and use the <xmlMessagetypeHelperConfiguration> content model element of the MessageRouterConfiguration.

Since:
Version .9

Field Summary
static java.lang.String MESSAGEROUTERCONFIG_CONTENTMODEL
          Content model tag for a Router configuration.
static java.lang.String MESSAGETYPE_TO_MESSAGEPIPELINE_MAP_CONFIG_CONTENTMODEL
          XMLMessageTypeToMessagePipelineConfiguration content model tag.
protected  XMLMessageTypeHelperConfiguration xmlMessageTypeHelperConfiguration
          xmlMessageTypeHelperConfiguration, which encapsulates the <xmlMessagetypeHelperConfiguration> configuration element, which configures an optional XMLMessageTypeHelper.
protected  XMLMappedConfiguration xmlMessageTypeToMessagePipelineConfiguration
          xmlMessageTypeToMessagePipelineConfiguration, which encapsulates the <messagetype-to-messagepipeline-map> configuration element, which is a map of message types to MessagePipelines.
 
Fields inherited from class org.osesb.configuration.XMLConfiguration
configFilePath, configurationProperties, constructedFromConfigFile, contentModelElement, ftpClientConfiguration, jaxrpcClientConfiguration, jdbcConfiguration, jmsClientConfiguration, log, rootConfigurationAttributes, smtpClientConfiguration, systemProperties, thisClassName
 
Constructor Summary
MessageRouterConfiguration(org.w3c.dom.Element contentModelElement)
          Creates a new instance of MessageRouterConfiguration given the content model Element.
MessageRouterConfiguration(java.lang.String configFile)
          Creates a new instance of MessageRouterConfiguration given a XML configuration file.
MessageRouterConfiguration(java.lang.String configFile, java.lang.String xpathExpression)
          Creates a new instance of MessageRouterConfiguration given a XML configuration file and a XPath expression that evaluates to the element that marks the beginning of the configuration.
 
Method Summary
 XMLMessageTypeHelperConfiguration getXMLMessageTypeHelperConfiguration()
          Returns the xmlMessageTypeHelperConfiguration, , which encapsulates the <xmlMessagetypeHelperConfiguration> configuration element, which configures an optional XMLMessageTypeHelper.
 XMLMappedConfiguration getXMLMessageTypeToMessagePipelineConfiguration()
          Returns the xmlMessageTypeToMessagePipelineConfiguration, which encapsulates the <messagetype-to-messagepipeline-map> configuration element.
protected  void loadXMLMessageTypeHelperConfiguration()
          Loads the xmlMessageTypeHelperConfiguration, which configures an optional XMLMessageTypeHelper.
protected  void loadXMLMessageTypeToMessagePipelineConfiguration()
          Loads the xmlMessageTypeToMessagePipelineConfiguration, which configures a map of message types to MessagePipelines.
static void main(java.lang.String[] args)
          main() - For testing and sandbboxing.
 void setConfigFilePath(java.lang.String configFile)
          Set the configuration file name.
 void setDebugFlag(boolean debugFlag)
          Set the debugFlag.
 java.lang.String toString()
          Returns the String representation of this MessageRouterConfiguration.
 
Methods inherited from class org.osesb.configuration.XMLConfiguration
checkXMLConfigurationClass, clear, doEncryptionInstructions, getBooleanConfigurationProperty, getBooleanRootConfigurationAttribute, getConfigFilePath, getConfigurationAttribute, getConfigurationAttributes, getConfigurationElement, getConfigurationElements, getConfigurationProperties, getConfigurationProperty, getConfigurationProperty, getContentModelElement, getDebugFlag, getDocument, getEncryptionInstructions, getFTPClientConfiguration, getIntConfigurationProperty, getIntRootConfigurationAttribute, getJAXRPCClientConfiguration, getJDBCConfiguration, getJMSClientConfiguration, getLongConfigurationProperty, getLongRootConfigurationAttribute, getName, getRootConfigurationAttribute, getRootConfigurationAttributes, getSMTPClientConfiguration, getSystemProperties, getSystemProperty, isConfigurationElementEmpty, loadConfiguration, loadExternalConfiguration, loadFTPClientConfiguration, loadJAXRPCClientConfiguration, loadJDBCConfiguration, loadJMSClientConfiguration, loadPropertiesFromContentModel, loadSMTPClientConfiguration, loadSystemProperties, mergeConfigurationProperties, setConfigurationProperty, setFTPClientConfiguration, setJAXRPCClientConfiguration, setJDBCConfiguration, setJMSClientConfiguration, setName, setRootConfigurationAttribute, setSMTPClientConfiguration, setSystemProperties, setSystemProperty, writeConfigurationFile, writeConfigurationFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

xmlMessageTypeHelperConfiguration

protected XMLMessageTypeHelperConfiguration xmlMessageTypeHelperConfiguration
xmlMessageTypeHelperConfiguration, which encapsulates the <xmlMessagetypeHelperConfiguration> configuration element, which configures an optional XMLMessageTypeHelper.


xmlMessageTypeToMessagePipelineConfiguration

protected XMLMappedConfiguration xmlMessageTypeToMessagePipelineConfiguration
xmlMessageTypeToMessagePipelineConfiguration, which encapsulates the <messagetype-to-messagepipeline-map> configuration element, which is a map of message types to MessagePipelines.


MESSAGEROUTERCONFIG_CONTENTMODEL

public static final java.lang.String MESSAGEROUTERCONFIG_CONTENTMODEL
Content model tag for a Router configuration.

See Also:
Constant Field Values

MESSAGETYPE_TO_MESSAGEPIPELINE_MAP_CONFIG_CONTENTMODEL

public static java.lang.String MESSAGETYPE_TO_MESSAGEPIPELINE_MAP_CONFIG_CONTENTMODEL
XMLMessageTypeToMessagePipelineConfiguration content model tag.

Constructor Detail

MessageRouterConfiguration

public MessageRouterConfiguration(java.lang.String configFile)
                           throws java.lang.Exception
Creates a new instance of MessageRouterConfiguration given a XML configuration file. The root element of the XML configuration file is the starting element for the configuration.

Parameters:
configFile - The path to the XML configuration file, which is specified as a resource path or as a file system path that is relative to the path specified by the ConfigurationConstants.CONFIG_PATH_SYSTEMPROPERTY System Property.
Throws:
java.lang.Exception - if there is a problem reading or parsing the configuration file.

MessageRouterConfiguration

public MessageRouterConfiguration(java.lang.String configFile,
                                  java.lang.String xpathExpression)
                           throws java.lang.Exception
Creates a new instance of MessageRouterConfiguration given a XML configuration file and a XPath expression that evaluates to the element that marks the beginning of the configuration.

An empty xpathExpression implies that the root element of the XML configuration file is the starting element for the configuration.

Parameters:
configFile - The XML configuration document to parse.
xpathExpression - A XPath expression that evaluates to the element that marks the beginning of the configuration. If following the framework convention for MessageRouterConfiguration(s), xpathExpression should have 'message-router-configuration' as the last Element in the path.
Throws:
java.lang.Exception - if there is a problem reading or parsing the configuration file.

MessageRouterConfiguration

public MessageRouterConfiguration(org.w3c.dom.Element contentModelElement)
                           throws java.lang.Exception
Creates a new instance of MessageRouterConfiguration given the content model Element.

Parameters:
contentModelElement - The top level Element for the for the configuration.
Throws:
java.lang.Exception - if there is a fatal error transversing the configuration content model enclosed by contentModelElement.
Method Detail

loadXMLMessageTypeHelperConfiguration

protected final void loadXMLMessageTypeHelperConfiguration()
                                                    throws java.lang.Exception
Loads the xmlMessageTypeHelperConfiguration, which configures an optional XMLMessageTypeHelper.

There are two ways that the message type for message is determined:

  1. Transport handlers and ClientGateway(s) can be configured with a static messageType. In this case all messages arriving at a transport handler will be assigned the same message type and all messages sent to osESB by a ClientGateway are assigned the same message type.
  2. If a transport handler or ClientGateway is not configured with a static message type, then the configured MessageRouter uses a XMLMessageTypeHelper to extract a message type from the incoming XML message.

The optional XMLMessageTypeHelper is configured by the <xmlMessagetypeHelperConfiguration> content model element of the MessageRouterConfiguration.

Note that this method should not be overridden as it is invoked from this class's constructor.

Throws:
java.lang.Exception - if there is a fatal error transversing the DOM that contains the configuration content model.

loadXMLMessageTypeToMessagePipelineConfiguration

protected final void loadXMLMessageTypeToMessagePipelineConfiguration()
                                                               throws java.lang.Exception
Loads the xmlMessageTypeToMessagePipelineConfiguration, which configures a map of message types to MessagePipelines.

MessageRouter routes messages to a org.osesb.messagepipeline.MessagePipeline for processing. The MessageRouter selects the MessagePipeline based on the message's messageType. The MessageRouter uses the <messagetype-to-messagepipeline-map> configuration element of a MessageRouterConfiguration to map message types to MessagePipelines.

Note that this method should not be overridden as it is invoked from this class's constructor.

Throws:
java.lang.Exception - if there is a fatal error transversing the DOM that contains the configuration content model.

getXMLMessageTypeHelperConfiguration

public XMLMessageTypeHelperConfiguration getXMLMessageTypeHelperConfiguration()
Returns the xmlMessageTypeHelperConfiguration, , which encapsulates the <xmlMessagetypeHelperConfiguration> configuration element, which configures an optional XMLMessageTypeHelper.

Returns:
the xmlMessageTypeHelperConfiguration, , which encapsulates the <xmlMessagetypeHelperConfiguration> configuration element, which configures an optional XMLMessageTypeHelper.

getXMLMessageTypeToMessagePipelineConfiguration

public XMLMappedConfiguration getXMLMessageTypeToMessagePipelineConfiguration()
Returns the xmlMessageTypeToMessagePipelineConfiguration, which encapsulates the <messagetype-to-messagepipeline-map> configuration element.

Returns:
the xmlMessageTypeToMessagePipelineConfiguration, which encapsulates the <messagetype-to-messagepipeline-map> configuration element.

setConfigFilePath

public void setConfigFilePath(java.lang.String configFile)
Set the configuration file name.

Overrides:
setConfigFilePath in class XMLConfiguration
Parameters:
configFile - the configuration file name.

setDebugFlag

public void setDebugFlag(boolean debugFlag)
Set the debugFlag.

Overrides:
setDebugFlag in class XMLConfiguration
Parameters:
debugFlag - the debugFlag.

toString

public java.lang.String toString()
Returns the String representation of this MessageRouterConfiguration.

Overrides:
toString in class XMLConfiguration
Returns:
the String representation of this MessageRouterConfiguration.

main

public static void main(java.lang.String[] args)
main() - For testing and sandbboxing.