Search in sources :

Example 1 with XMLStreamReader2

use of org.codehaus.stax2.XMLStreamReader2 in project cxf by apache.

the class Stax2ValidationUtils method setupValidation.

/**
 * {@inheritDoc}
 *
 * @throws XMLStreamException
 */
public boolean setupValidation(XMLStreamReader reader, Endpoint endpoint, ServiceInfo serviceInfo) throws XMLStreamException {
    // Gosh, this is bad, but I don't know a better solution, unless we're willing
    // to require the stax2 API no matter what.
    XMLStreamReader effectiveReader = reader;
    if (effectiveReader instanceof DepthXMLStreamReader) {
        effectiveReader = ((DepthXMLStreamReader) reader).getReader();
    }
    final XMLStreamReader2 reader2 = (XMLStreamReader2) effectiveReader;
    XMLValidationSchema vs = getValidator(endpoint, serviceInfo);
    if (vs == null) {
        return false;
    }
    reader2.setValidationProblemHandler(new ValidationProblemHandler() {

        public void reportProblem(XMLValidationProblem problem) throws XMLValidationException {
            throw new Fault(new Message("READ_VALIDATION_ERROR", LOG, problem.getMessage()), Fault.FAULT_CODE_CLIENT);
        }
    });
    reader2.validateAgainst(vs);
    return true;
}
Also used : XMLValidationProblem(org.codehaus.stax2.validation.XMLValidationProblem) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) ValidationProblemHandler(org.codehaus.stax2.validation.ValidationProblemHandler) XMLValidationException(org.codehaus.stax2.validation.XMLValidationException) Message(org.apache.cxf.common.i18n.Message) XMLStreamReader2(org.codehaus.stax2.XMLStreamReader2) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) XMLValidationSchema(org.codehaus.stax2.validation.XMLValidationSchema)

Aggregations

XMLStreamReader (javax.xml.stream.XMLStreamReader)1 Message (org.apache.cxf.common.i18n.Message)1 Fault (org.apache.cxf.interceptor.Fault)1 DepthXMLStreamReader (org.apache.cxf.staxutils.DepthXMLStreamReader)1 XMLStreamReader2 (org.codehaus.stax2.XMLStreamReader2)1 ValidationProblemHandler (org.codehaus.stax2.validation.ValidationProblemHandler)1 XMLValidationException (org.codehaus.stax2.validation.XMLValidationException)1 XMLValidationProblem (org.codehaus.stax2.validation.XMLValidationProblem)1 XMLValidationSchema (org.codehaus.stax2.validation.XMLValidationSchema)1