Search in sources :

Example 1 with DefaultValidationErrorHandler

use of org.apache.camel.processor.validation.DefaultValidationErrorHandler in project camel by apache.

the class XmlSignerProcessor method getMessageBodyNode.

protected Node getMessageBodyNode(Message message) throws Exception {
    //NOPMD
    InputStream is = message.getMandatoryBody(InputStream.class);
    Boolean isPlainText = isPlainText(message);
    Node node;
    if (isPlainText != null && isPlainText) {
        node = getTextNode(message, is);
    } else {
        ValidatorErrorHandler errorHandler = new DefaultValidationErrorHandler();
        Schema schema = getSchemaForSigner(message, errorHandler);
        Document doc = parseInput(is, getConfiguration().getDisallowDoctypeDecl(), schema, errorHandler);
        // throws ValidationException
        errorHandler.handleErrors(message.getExchange(), schema, null);
        node = doc.getDocumentElement();
        LOG.debug("Root element of document to be signed: {}", node);
    }
    return node;
}
Also used : InputStream(java.io.InputStream) Node(org.w3c.dom.Node) Schema(javax.xml.validation.Schema) ValidatorErrorHandler(org.apache.camel.processor.validation.ValidatorErrorHandler) DefaultValidationErrorHandler(org.apache.camel.processor.validation.DefaultValidationErrorHandler) Document(org.w3c.dom.Document)

Example 2 with DefaultValidationErrorHandler

use of org.apache.camel.processor.validation.DefaultValidationErrorHandler in project camel by apache.

the class XmlVerifierProcessor method parseInput.

protected Document parseInput(InputStream is, Message message) throws Exception {
    //NOPMD
    try {
        ValidatorErrorHandler errorHandler = new DefaultValidationErrorHandler();
        Schema schema = getSchema(message);
        DocumentBuilder db = XmlSignatureHelper.newDocumentBuilder(getConfiguration().getDisallowDoctypeDecl(), schema);
        db.setErrorHandler(errorHandler);
        Document doc = db.parse(is);
        // throws ValidationException
        errorHandler.handleErrors(message.getExchange(), schema, null);
        return doc;
    } catch (SAXException e) {
        throw new XmlSignatureFormatException("Message has wrong format, it is not a XML signature document. Check the sent message.", e);
    }
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) XmlSignatureFormatException(org.apache.camel.component.xmlsecurity.api.XmlSignatureFormatException) Schema(javax.xml.validation.Schema) ValidatorErrorHandler(org.apache.camel.processor.validation.ValidatorErrorHandler) DefaultValidationErrorHandler(org.apache.camel.processor.validation.DefaultValidationErrorHandler) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 3 with DefaultValidationErrorHandler

use of org.apache.camel.processor.validation.DefaultValidationErrorHandler in project camel by apache.

the class JingValidator method process.

public void process(Exchange exchange) throws Exception {
    Jaxp11XMLReaderCreator xmlCreator = new Jaxp11XMLReaderCreator();
    DefaultValidationErrorHandler errorHandler = new DefaultValidationErrorHandler();
    PropertyMapBuilder mapBuilder = new PropertyMapBuilder();
    mapBuilder.put(ValidateProperty.XML_READER_CREATOR, xmlCreator);
    mapBuilder.put(ValidateProperty.ERROR_HANDLER, errorHandler);
    PropertyMap propertyMap = mapBuilder.toPropertyMap();
    Validator validator = getSchema().createValidator(propertyMap);
    Message in = exchange.getIn();
    SAXSource saxSource = in.getBody(SAXSource.class);
    if (saxSource == null) {
        Source source = exchange.getIn().getMandatoryBody(Source.class);
        saxSource = ExchangeHelper.convertToMandatoryType(exchange, SAXSource.class, source);
    }
    InputSource bodyInput = saxSource.getInputSource();
    // now lets parse the body using the validator
    XMLReader reader = xmlCreator.createXMLReader();
    reader.setContentHandler(validator.getContentHandler());
    reader.setDTDHandler(validator.getDTDHandler());
    reader.setErrorHandler(errorHandler);
    reader.parse(bodyInput);
    errorHandler.handleErrors(exchange, schema);
}
Also used : InputSource(org.xml.sax.InputSource) Jaxp11XMLReaderCreator(com.thaiopensource.xml.sax.Jaxp11XMLReaderCreator) PropertyMap(com.thaiopensource.util.PropertyMap) SAXSource(javax.xml.transform.sax.SAXSource) Message(org.apache.camel.Message) PropertyMapBuilder(com.thaiopensource.util.PropertyMapBuilder) DefaultValidationErrorHandler(org.apache.camel.processor.validation.DefaultValidationErrorHandler) Validator(com.thaiopensource.validate.Validator) InputSource(org.xml.sax.InputSource) Source(javax.xml.transform.Source) SAXSource(javax.xml.transform.sax.SAXSource) XMLReader(org.xml.sax.XMLReader)

Aggregations

DefaultValidationErrorHandler (org.apache.camel.processor.validation.DefaultValidationErrorHandler)3 Schema (javax.xml.validation.Schema)2 ValidatorErrorHandler (org.apache.camel.processor.validation.ValidatorErrorHandler)2 Document (org.w3c.dom.Document)2 PropertyMap (com.thaiopensource.util.PropertyMap)1 PropertyMapBuilder (com.thaiopensource.util.PropertyMapBuilder)1 Validator (com.thaiopensource.validate.Validator)1 Jaxp11XMLReaderCreator (com.thaiopensource.xml.sax.Jaxp11XMLReaderCreator)1 InputStream (java.io.InputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 Source (javax.xml.transform.Source)1 SAXSource (javax.xml.transform.sax.SAXSource)1 Message (org.apache.camel.Message)1 XmlSignatureFormatException (org.apache.camel.component.xmlsecurity.api.XmlSignatureFormatException)1 Node (org.w3c.dom.Node)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1 XMLReader (org.xml.sax.XMLReader)1