Search in sources :

Example 1 with DefaultLSResourceResolver

use of org.apache.camel.component.validator.DefaultLSResourceResolver in project camel by apache.

the class XmlSignatureProcessor method getSchema.

protected Schema getSchema(Message message) throws SAXException, XmlSignatureException, IOException {
    String schemaResourceUri = getSchemaResourceUri(message);
    if (schemaResourceUri == null || schemaResourceUri.isEmpty()) {
        return null;
    }
    InputStream is = ResourceHelper.resolveResourceAsInputStream(getConfiguration().getCamelContext().getClassResolver(), schemaResourceUri);
    if (is == null) {
        throw new XmlSignatureException("XML Signature component is wrongly configured: No XML schema found for specified schema resource URI " + schemaResourceUri);
    }
    byte[] bytes = null;
    try {
        bytes = IOConverter.toBytes(is);
    } finally {
        // and make sure to close the input stream after the schema has been loaded
        IOHelper.close(is);
    }
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    schemaFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
    schemaFactory.setResourceResolver(new DefaultLSResourceResolver(getConfiguration().getCamelContext(), getConfiguration().getSchemaResourceUri()));
    LOG.debug("Instantiating schema for validation");
    return schemaFactory.newSchema(new BytesSource(bytes));
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) BytesSource(org.apache.camel.BytesSource) XmlSignatureException(org.apache.camel.component.xmlsecurity.api.XmlSignatureException) InputStream(java.io.InputStream) DefaultLSResourceResolver(org.apache.camel.component.validator.DefaultLSResourceResolver)

Aggregations

InputStream (java.io.InputStream)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 BytesSource (org.apache.camel.BytesSource)1 DefaultLSResourceResolver (org.apache.camel.component.validator.DefaultLSResourceResolver)1 XmlSignatureException (org.apache.camel.component.xmlsecurity.api.XmlSignatureException)1