Message Validation & Transformation
This sample demonstrates the Validate – Schema and Transform – Xslt Neuron Process steps. To assure messages on the bus are in the form and format expected it is often necessary to perform some type of validation before allowing them to flow through the bus. Schema validation is the process of checking to assure an XML document conforms to a defined structure. In Neuron, a Validate – Schema process step can be used to accomplish this goal. Once a message has been validated, it is often necessary to convert the message into a new format that is required for the subscriber receiving the message. In Neuron, a Transform – Xslt process step can be used to accomplish this.
Process Components Demonstrated:
- Validate – Schema
- Transform – Xslt
The Validate Book Message process depicted in Figure 2 has a Validate – Schema process component named “validate book” with two branches that serve as a container for all other steps in the process. The branch on the left labeled “Valid” will be followed if the validation is successful and the branch on the right labeled “Invalid” will be followed if the validation fails. Having the two branches allows for different processes to take place based on success or failure.
The “Valid” branch on the left contains a Transform – Xslt process step named “message to html” and a Trace process step. The “message to html” step will be used to convert the good message to an html format suitable for embedding in a web site for example. The Trace process step will be used to display the message in the Process Designer’s trace window during testing.
The “Invalid” branch on the right contains a Code process step named “display exception” and Cancel process step named “end message”. The “display exception” step will be used to display the validation exception in the Process Designer’s trace window during testing. While testing the process we will purposefully alter the incoming message so that validation fails and we can see the error that occurs in the Validate – Schema process step. The “end message” process step ends the process and ends the delivery of the original message. A Cancel process step does not cause the process to abort and log an error. Instead it is used to simply end the process and the message transfer.
Running the Sample
Open the Sample
To open this sample, see the topic Using the Neuron Samples and select the Message Validation and Transformation sample.
Run the Sample (Successful Validation)
- From the Repository tab in Neuron Explorer copy the test message SchemaValidationSampleMessage from the Xml Documents area.
- Navigate to the Process Designer by selecting the Processes tab in the left panel of Neuron Explorer.
- Select the Validate Book Message process from the list on the left of the designer.
Note: Maximize Neuron Explorer and drag the process to the left of the designer so that the trace message will be easier to view on the designer as the process runs.
- On the Process Designer toolbar click the Test button . This will open the Edit Test Message Dialog shown in Figure 4.
- Paste the test message into the message field of the Edit Test Message dialog as shown in Figure 4.
- Click the OK button on the Edit Test Message dialog. Once the dialog is closed the process will begin execution.
- As the process runs each step will be highlight in green as it is executed. As you visually follow the execution note the sequence of steps. The final view after the Trace step is executed is shown in Figure 5.
Run the Sample (Validation Failure)
- Open the Edit Test Message dialog as in step 4 above.
- Change the message content by deleting the line: “<name>Snoopy</name>”.
- Click the OK button on the Edit Test Message dialog. This time the process execution will follow the “Invalid” branch. The result is shown in Figure 6 below.
As an exercise try running this sample process live using the Neuron Test Client. The sample configuration file has two Parties that can be used to accomplish this. The BookMessagePublisher Party can be used to run the process in the OnPublish mode and the BookSubscriber can be used to receive the final message if validation is successful.
Set Schema and XSLT in Code
To set the schema used for validation and the XSLT used for transformation in code, execute steps 1 – 10 above, but instead select the Validate Book Message – Code process. This process includes a code step where the schema and XSLT documents are set in code, referenced from the Data tab, XML Schemas and XML Schemas areas. If you want to try this process with the Neuron Test Client, you’ll have to configure the BookMessagePublisher to use the Validate Book Message – Code process.
All processes with the exception of the Code process step are configured by selecting and setting their properties in the property grid located at the bottom right of the process designer. The Code process step is configured by selecting the “Edit” option from the short cut menu that is available when right-clicking the Code step in the process designer. See the process documentation for more information.