Search in sources :

Example 1 with SchemaService

use of org.apache.oozie.service.SchemaService in project oozie by apache.

the class V2ValidateServlet method validate.

private void validate(String xml) throws Exception {
    SchemaService schemaService = Services.get().get(SchemaService.class);
    Schema[] schemas = { schemaService.getSchema(SchemaService.SchemaName.WORKFLOW), schemaService.getSchema(SchemaService.SchemaName.COORDINATOR), schemaService.getSchema(SchemaService.SchemaName.BUNDLE), schemaService.getSchema(SchemaService.SchemaName.SLA_ORIGINAL) };
    Exception exception = null;
    for (int i = 0; i < schemas.length; i++) {
        try {
            validateSchema(schemas[i], new StringReader(xml));
            exception = null;
            break;
        } catch (SAXException e) {
            if (i == 0) {
                exception = e;
            }
            // If invalid, move to next schema validation.
            if (!e.getMessage().contains("cvc-elt.1")) {
                exception = e;
                break;
            }
        } catch (Exception e) {
            exception = e;
            break;
        }
    }
    if (exception != null) {
        throw exception;
    }
}
Also used : SchemaService(org.apache.oozie.service.SchemaService) Schema(javax.xml.validation.Schema) StringReader(java.io.StringReader) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) OozieCLIException(org.apache.oozie.cli.OozieCLIException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException)

Aggregations

IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ServletException (javax.servlet.ServletException)1 Schema (javax.xml.validation.Schema)1 OozieCLIException (org.apache.oozie.cli.OozieCLIException)1 SchemaService (org.apache.oozie.service.SchemaService)1 SAXException (org.xml.sax.SAXException)1