Search in sources :

Example 1 with XmlConfigurationDocumentLoader

use of org.mule.runtime.config.api.XmlConfigurationDocumentLoader in project mule by mulesoft.

the class XmlConfigurationDocumentLoaderTestCase method testMalformedXmlCustomGatherer.

@Test
public void testMalformedXmlCustomGatherer() throws XPathExpressionException {
    // We will use a custom gathered that stores the errors but returns an empty list when asked
    final XmlGathererErrorHandlerTest xmlGathererErrorHandlerTest = new XmlGathererErrorHandlerTest();
    final XmlConfigurationDocumentLoader xmlConfigurationDocumentLoader = schemaValidatingDocumentLoader(() -> xmlGathererErrorHandlerTest);
    // Validates that the DOM was properly parsed even when it was non-XSD valid
    final Document document = getDocument("mule-config-malformed.xml", xmlConfigurationDocumentLoader);
    assertThat(document, not(isNull()));
    assertThat(document.getDocumentElement().getNodeName(), is("mule"));
    assertThat(document.getDocumentElement().getChildNodes().getLength(), is(3));
    final Node flow = document.getDocumentElement().getChildNodes().item(1);
    assertThat(flow.getNodeName(), is("flow"));
    assertThat(flow.getAttributes().getNamedItem("name").getNodeValue(), is("missing-inner-element"));
    // Asserts over the gathered errors
    assertThat(xmlGathererErrorHandlerTest.errors.size(), is(1));
    assertThat(xmlGathererErrorHandlerTest.errors.get(0).getColumnNumber(), is(COLUMN_NUMBER_ERROR));
    assertThat(xmlGathererErrorHandlerTest.errors.get(0).getLineNumber(), is(LINE_NUMBER_ERROR));
}
Also used : Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) XmlConfigurationDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader) Test(org.junit.Test)

Example 2 with XmlConfigurationDocumentLoader

use of org.mule.runtime.config.api.XmlConfigurationDocumentLoader in project mule by mulesoft.

the class XmlExtensionLoaderDelegate method getModuleDocument.

private Document getModuleDocument(ExtensionLoadingContext context, URL resource) {
    XmlConfigurationDocumentLoader xmlConfigurationDocumentLoader = validateXml ? schemaValidatingDocumentLoader() : schemaValidatingDocumentLoader(NoOpXmlErrorHandler::new);
    try {
        final Set<ExtensionModel> extensions = new HashSet<>(context.getDslResolvingContext().getExtensions());
        createTnsExtensionModel(resource, extensions).ifPresent(extensions::add);
        return xmlConfigurationDocumentLoader.loadDocument(extensions, resource.getFile(), resource.openStream());
    } catch (IOException e) {
        throw new MuleRuntimeException(createStaticMessage(format("There was an issue reading the stream for the resource %s", resource.getFile())));
    }
}
Also used : ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException) XmlConfigurationDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader) HashSet(java.util.HashSet)

Aggregations

XmlConfigurationDocumentLoader (org.mule.runtime.config.api.XmlConfigurationDocumentLoader)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1