Schema Validation

This provides an optional setting to validate an incoming XML file against a Schema object generated from the relevant XSD files. In the event that schema validation fails, the file will not be debulked.

Validation prior to debulking is only possible for XML files.

Validation can be enabled for each Debulking Configuration by providing validate-before-debulk.schema-bean-name config path within the configuration. The value provided should match the Spring bean name that provides the relevant javax.xml.validation.Schema object to validate against. In the event that no bean name is provided, or the relevant bean is not configured/available, the Debulker will fail to start.

Customising Schema Validation

The schema validation process can be customised in two ways:

Custom Error Handler

The implementation XSDValidator supports injecting a custom ErrorHandler. If none is provided, the validator will not use any error handler explicitly, and will rely on its default behaviour (which typically throws validation exceptions when schema violations occur).

@Bean
ErrorHandler customErrorHandler() {
    // Return a custom implementation of ErrorHandler
    return new CustomErrorHandler();
}

A custom error handler can be used to:

  • Control how validation errors are reported

  • Log more meaningful messages

  • Suppress or escalate specific types of validation issues

If the custom error handler swallows exceptions (e.g. by extending DefaultHandler without overriding error() or fatalError()), schema validation failures might be silently ignored.

Overriding the XSDValidator Bean

For more extensive customisation, the entire XSDValidator bean can be overridden by defining a custom bean in the application configuration:

@Bean
XSDValidator customXsdValidator(DebulkingContext debulkingContext,
                               ErrorHandler errorHandler) {
    // Return a custom implementation or a customised instance of XSDValidator
    return new CustomXSDValidator(debulkingContext, errorHandler);
}

This approach allows for complete control over the validation process, including how validation errors are handled and reported.