Using the Validate action to perform message validation

In this recipe, we will show how to use the Validate action to perform message validation. We will use the same proxy service setup we have used in the Using the For Each action to process a collection recipe, with a proxy service with a Messaging Service type interface accepting a customer element. We will use the Validate action in the proxy service to make sure that the messae passed in is a valid customer.

Getting ready

You can import the OSB project containing the base setup for this recipe into Eclipse OEPE from chapter-9getting-readyusing-validate-to-do-message-validation.

How to do it...

Let's add the Validate action to the proxy service we imported previously in the Getting, ready section. In Eclipse OEPE, perform the following steps:

  1. Open the MessageValidation proxy service and navigate to the Message Flow tab.
  2. Insert a new stage into the MessageProcessingPipelinePair and name itMessageValidationStage.
  3. Insert a Validate action into the stage.
  4. On the Properties tab of the Validate action, enter body into the In Variable field.
  5. Click <XPath> and enter ./cus:Customer into the Expression field. Click OK.
  6. Click Browse to the right of Against Resource and select the Customer (element) in the xsd/Customer.xsd XML Schema. Click OK.
  7. Select the Raise Error option.
  8. Deploy the project to the OSB server.

    Now let's test the validation of our proxy service. In the Service Bus console, perform the following steps:

  9. In the Project Explorer navigate to proxy folder inside the using-validate-to-do-message-validation project.
  10. Click on the Launch Test Console icon of the MessageValidation proxy service.
  11. Enter a message with an invalid CardIssuer (only the lowercase values visa and masercard are valid) and click Execute.
    How to do it...
  12. The Validate action will raise a validation error, which is shown in the following screenshot:
    How to do it...

How it works...

The Validate action can be used to check the content of any variable against an element or type of an XML schema. The validation can be configured to either save the Boolean result of the validation in a variable or to raise an error if the validation fails. An error will hold the error code BEA-382505 and the message will hold further details about the failed validation.

By using the XPath expression, it's also possible to only check fragments, inside a larger XML message, for validity.

The Validate action cannot be disabled, if it's included in the Message Flow tab, then it will always be executed. To programmatically exclude it, it can be wrapped inside an If Then action. Refer the Enabling/Disabling a Validate action dynamically recipe for how to achieve that.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset