Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Questo contenuto non è disponibile nella lingua selezionata.
11.4. Supported Validators
11.4.1. Java Copia collegamentoCollegamento copiato negli appunti!
Copia collegamentoCollegamento copiato negli appunti!
11.4.1.1. Use a Java Validator Copia collegamentoCollegamento copiato negli appunti!
Copia collegamentoCollegamento copiato negli appunti!
Procedure 11.2. Create a Java Validator
- Implement the
org.switchyard.validate.Validator
interface. - Add a <validate.java> definition to your
switchyard.xml
file. - Alternatively, annotate one or more methods to your Java class with @Validator:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow When using the @Validator annotation, the SwitchYard Maven plug-in automatically generates the <validate.java> definitions for you and add them to theswitchyard.xml
file packaged in your application.The Java class above produces this <validate.java> definition:<validate.java bean="MyValidatorBean" name="{urn:switchyard-quickstart-demo:orders:1.0}submitOrder"/>
<validate.java bean="MyValidatorBean" name="{urn:switchyard-quickstart-demo:orders:1.0}submitOrder"/>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
11.4.1.2. Java Validator Reference Copia collegamentoCollegamento copiato negli appunti!
Copia collegamentoCollegamento copiato negli appunti!
The optional name element of the @Validator annotation can be used to specify the qualified type name used during validator registration. If not supplied, the full class name of the method parameter is used as the type.
The CDI bean name specified by @Named annotation is used to resolve validator class. If you fail to specify it, then the validator's class name is used instead:
<validates> <validate.java class="org.switchyard.quickstarts.demos.orders.MyValidator" name="{urn:switchyard-quickstart-demo:orders:1.0}submitOrder"/> </transforms>
<validates>
<validate.java class="org.switchyard.quickstarts.demos.orders.MyValidator"
name="{urn:switchyard-quickstart-demo:orders:1.0}submitOrder"/>
</transforms>
Note
Each of the <validate.java> definitions have either a bean attribute or a class attribute. These two attributes are mutually exclusive.
11.4.1.3. ValidationResult Copia collegamentoCollegamento copiato negli appunti!
Copia collegamentoCollegamento copiato negli appunti!
ValidationResult is a simple interface which represents the result of validation. It has two methods,
isValid()
and getDetail()
.
11.4.1.4. Java Validation Failure Copia collegamentoCollegamento copiato negli appunti!
Copia collegamentoCollegamento copiato negli appunti!
If Java validation fails, the message exchange process stops immediately and a
HandlerException
is thrown along with a validation failure message which is returned by ValidationResult.getDetail()
. Make sure that you return a ValidationResult
with failure detail message when you want to indicate a validation failure in your Java Validator, instead of throwing a RuntimeException
.
11.4.1.5. ValidationResult Properties Copia collegamentoCollegamento copiato negli appunti!
Copia collegamentoCollegamento copiato negli appunti!
isValid()
returns whether the validation succeeded or not. _getDetail()
returns an error message if validation fails.
There are three convenience methods available for
org.switchyard.validate.BaseValidator
. These are validResult()
, invalidResult()
and invalidResult(String)
Use them to generate ValidationResult objects.
11.4.2. XML Copia collegamentoCollegamento copiato negli appunti!
Copia collegamentoCollegamento copiato negli appunti!
11.4.2.1. Use an XML Validator Copia collegamentoCollegamento copiato negli appunti!
Copia collegamentoCollegamento copiato negli appunti!
The XML validator allows you to perform a validation against its schema definition. It support DTD, XML_SCHEMA, and RELAX_NG schema types. You can configure an XML validator by specifying the schema Type, the name QName, and the path to the schema file. Here is an example:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
If you specify the
failOnWarning
attribute as true, the validation fails if any warning is detected during validation. If the XML content to be validated has namespace prefix, then you need to specify namespaceAware
as true.
11.4.2.2. XML Catalog Copia collegamentoCollegamento copiato negli appunti!
Copia collegamentoCollegamento copiato negli appunti!
You can use XML catalog to decouple the schema file location from schema definition itself. This schema is
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
Here is the
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
orders.xsd
which has a import element. It refers to logical name orders.base by the schemaLocation
attribute:
catalog.xml
file that resolves actual schema location from logical name orders.base:
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> <system systemId="orders.base" uri="orders-base.xsd"/> </catalog>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<system systemId="orders.base" uri="orders-base.xsd"/>
</catalog>
11.4.2.3. XML Validation Failure Copia collegamentoCollegamento copiato negli appunti!
Copia collegamentoCollegamento copiato negli appunti!
If XML validation fails, the message exchange process stops immediately and a
HandlerException
is thrown along with a validation failure message. XMLValidator collects a set of validation failures through the SAX ErrorHandler
, and uses the getMessage()
of each received SAXParseException
as a failure detail with extracting root cause, if exists.