Skip to content

Message Validation & Transformation

Note: It is recommended that the Neuron process documentation be reviewed before running this sample. The documentation thoroughly describes each process component individually and describes how to configure each one as well as how to construct a process and associate it with a Neuron Publisher or Subscriber. See the Configuration Notes section at the end of this document for more information.

Overview

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
  • Code
  • Trace
  • Cancel

Solution

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.

Note: This sample will use the Test feature built into the Neuron Process Designer. Testing in the designer allows you to see each step being executed. Trace messages can be seen within the 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.

Figure 1: Empty Validate-Schema process component as displayed in the Neuron Process Designer.
Figure 2: Completed Validate Book Message process as displayed in the Neuron Process Designer
Figure 3: Completed Validate Book Message – Code process as displayed in the Neuron Process Designer. Note the “warning” icon in the validate steps. This indicates that a schema and XSLT have not been set. When setting them in code, this is OK.
Note: All Validate-Schema process components default to having a Cancel process step in their “Invalid” branch. The Cancel process step can be removed if desired, as well as replaced with a ReThrow step to ensure the calling client receives the exception information.

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)

  1. From the Repository tab in Neuron Explorer copy the test message SchemaValidationSampleMessage from the Xml Documents area.
  2. Navigate to the Process Designer by selecting the Processes tab in the left panel of Neuron Explorer.
  3. 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.
  4. On the Process Designer toolbar click the Test button . This will open the Edit Test Message Dialog shown in Figure 4.
  1. Paste the test message into the message field of the Edit Test Message dialog as shown in Figure 4.
  2. Click the OK button on the Edit Test Message dialog. Once the dialog is closed the process will begin execution.
  3. 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.
Figure 5: Neuron Process Designer Trace Window displaying successful final message after execution traverses the “Valid” branch of the Validate Book Process.

Run the Sample (Validation Failure)

  1. Open the Edit Test Message dialog as in step 4 above.
  2. Change the message content by deleting the line: “<name>Snoopy</name>”.
  3. 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.
Figure 6: Neuron Process Designer Trace Window displaying validation failure message after execution traverses the “Invalid” branch of the Validate Book Process

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.

Configuration Notes

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.

Figure 7: The Neuron Process Designer displaying the Validate Book Message process. Property Grid at the bottom right displaying the properties for the Validate – Schema process step.
Was this article helpful?
Dislike 0
Previous: Retry Call to Web Service
Next: Exception Handling