Example usage for javax.xml.validation Validator getErrorHandler

List of usage examples for javax.xml.validation Validator getErrorHandler

Introduction

In this page you can find the example usage for javax.xml.validation Validator getErrorHandler.

Prototype

public abstract ErrorHandler getErrorHandler();

Source Link

Document

Gets the current ErrorHandler set to this Validator .

Usage

From source file:com.predic8.membrane.core.interceptor.schemavalidation.SOAPMessageValidatorInterceptor.java

private Outcome validateMessage(Exchange exc, Message msg) throws Exception {
    List<Exception> exceptions = new ArrayList<Exception>();
    for (Validator validator : validators) {
        validator.validate(getSOAPBody(msg.getBodyAsStream()));
        SchemaValidatorErrorHandler handler = (SchemaValidatorErrorHandler) validator.getErrorHandler();
        // the message must be valid for one schema embedded into WSDL 
        if (handler.noErrors()) {
            return Outcome.CONTINUE;
        }/*  w  ww. j a  v  a2s. c o  m*/
        exceptions.add(handler.getException());
        handler.reset();
    }
    exc.setResponse(HttpUtil.createSOAPFaultResponse(getErrorMsg(exceptions)));
    return Outcome.ABORT;
}

From source file:com.predic8.membrane.core.interceptor.schemavalidation.AbstractXMLSchemaValidator.java

public Outcome validateMessage(Exchange exc, Message msg, String source) throws Exception {
    List<Exception> exceptions = new ArrayList<Exception>();
    String preliminaryError = getPreliminaryError(xopr, msg);
    if (preliminaryError == null) {
        List<Validator> vals = validators.take();
        try {/*w w  w .j av a2  s .com*/
            // the message must be valid for one schema embedded into WSDL
            for (Validator validator : vals) {
                SchemaValidatorErrorHandler handler = (SchemaValidatorErrorHandler) validator.getErrorHandler();
                try {
                    validator.validate(getMessageBody(xopr.reconstituteIfNecessary(msg)));
                    if (handler.noErrors()) {
                        valid.incrementAndGet();
                        return Outcome.CONTINUE;
                    }
                    exceptions.add(handler.getException());
                } finally {
                    handler.reset();
                }
            }
        } catch (Exception e) {
            exceptions.add(e);
        } finally {
            validators.put(vals);
        }
    } else {
        exceptions.add(new Exception(preliminaryError));
    }
    if (skipFaults && isFault(msg)) {
        valid.incrementAndGet();
        return Outcome.CONTINUE;
    }
    if (failureHandler == FailureHandler.VOID) {
        exc.setProperty("error", getErrorMsg(exceptions));
    } else if (failureHandler != null) {
        failureHandler.handleFailure(getErrorMsg(exceptions), exc);
        exc.setResponse(createErrorResponse("validation error"));
    } else {
        exc.setResponse(createErrorResponse(getErrorMsg(exceptions)));
        exc.getResponse().getHeader().add(Header.VALIDATION_ERROR_SOURCE, source);
    }
    invalid.incrementAndGet();
    return Outcome.ABORT;
}