Search in sources :

Example 16 with Resource

use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.

the class ConfigurationDigesterTest method testFixedValueAttributeResolverWithFrankConfig.

@Test
public void testFixedValueAttributeResolverWithFrankConfig() throws Exception {
    URL schemaURL = TestFileUtils.getTestFileURL(FRANK_CONFIG_XSD);
    ValidatorHandler validatorHandler = XmlUtils.getValidatorHandler(schemaURL);
    XmlWriter writer = new XmlWriter();
    validatorHandler.setContentHandler(writer);
    validatorHandler.setErrorHandler(new XmlErrorHandler());
    Resource resource = Resource.getResource("/Digester/PreParsedConfiguration.xml");
    assertNotNull(resource);
    XmlUtils.parseXml(resource, validatorHandler);
    String expected = TestFileUtils.getTestFile("/Digester/resolvedPreParsedConfiguration.xml");
    assertEquals(expected, writer.toString().trim());
}
Also used : ValidatorHandler(javax.xml.validation.ValidatorHandler) Resource(nl.nn.adapterframework.core.Resource) URL(java.net.URL) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) Test(org.junit.Test)

Example 17 with Resource

use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.

the class ConfigurationDigesterTest method testNewConfigurationPreParser.

// Both OLD and NEW configuration parsers should set the same values for 'loadedConfiguration': properties resolved, secrets hidden
// The new configuration parser returns the configuration with all property not yet resolved
@Test
public void testNewConfigurationPreParser() throws Exception {
    ConfigurationDigester digester = new ConfigurationDigester();
    Resource resource = Resource.getResource("/Digester/SimpleConfiguration/Configuration.xml");
    Properties properties = new Properties();
    properties.setProperty("HelloWorld.active", "false");
    properties.setProperty("HelloBeautifulWorld.active", "!false");
    // new style non-escaped property values
    properties.setProperty("digester.property", "[ >\"< ]");
    properties.setProperty("secret", "GEHEIM");
    properties.setProperty("properties.hide", "secret");
    Configuration configuration = new TestConfiguration();
    XmlWriter loadedConfigWriter = new XmlWriter();
    digester.parseAndResolveEntitiesAndProperties(loadedConfigWriter, configuration, resource, properties);
    String result = loadedConfigWriter.toString();
    String expected = TestFileUtils.getTestFile("/Digester/Loaded/SimpleConfigurationUnresolved.xml");
    MatchUtils.assertXmlEquals(expected, result);
    String storedResult = configuration.getLoadedConfiguration();
    String storedExpected = TestFileUtils.getTestFile("/Digester/Loaded/SimpleConfigurationResolvedAndHidden.xml");
    MatchUtils.assertXmlEquals(storedExpected, storedResult);
    loadedConfigWriter = new XmlWriter();
    properties.setProperty(STUB4TESTTOOL_CONFIGURATION_KEY, "true");
    digester.parseAndResolveEntitiesAndProperties(loadedConfigWriter, configuration, resource, properties);
    String stubbedExpected = TestFileUtils.getTestFile("/Digester/Loaded/SimpleConfigurationStubbed.xml");
    MatchUtils.assertXmlEquals(stubbedExpected, loadedConfigWriter.toString());
}
Also used : TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) Configuration(nl.nn.adapterframework.configuration.Configuration) Resource(nl.nn.adapterframework.core.Resource) TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) Properties(java.util.Properties) ConfigurationDigester(nl.nn.adapterframework.configuration.ConfigurationDigester) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) Test(org.junit.Test)

Example 18 with Resource

use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.

the class XsltProviderListener method init.

public void init() throws ListenerException {
    try {
        Resource stylesheet;
        if (fromClasspath) {
            stylesheet = Resource.getResource(filename);
        } else {
            File file = new File(filename);
            stylesheet = Resource.getResource(null, file.toURI().toURL().toExternalForm(), "file");
        }
        transformerPool = TransformerPool.getInstance(stylesheet, getXsltVersion());
    } catch (Exception e) {
        throw new ListenerException("Exception creating transformer pool for file '" + filename + "': " + e.getMessage(), e);
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) Resource(nl.nn.adapterframework.core.Resource) File(java.io.File) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ListenerException(nl.nn.adapterframework.core.ListenerException)

Example 19 with Resource

use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.

the class EsbJmsTransactionalStorage method configure.

@Override
public void configure() throws ConfigurationException {
    super.configure();
    String exceptionLogString = "/xml/xsl/esb/exceptionLog.xsl";
    String auditLogString = "/xml/xsl/esb/auditLog.xsl";
    try {
        Resource exceptionLogResource = Resource.getResource(this, exceptionLogString);
        if (exceptionLogResource == null) {
            throw new ConfigurationException(getLogPrefix() + "cannot find stylesheet [" + exceptionLogString + "]");
        }
        exceptionLogTp = TransformerPool.getInstance(exceptionLogResource, 2);
    } catch (IOException e) {
        throw new ConfigurationException(getLogPrefix() + "cannot retrieve [" + exceptionLogString + "]", e);
    } catch (TransformerConfigurationException te) {
        throw new ConfigurationException(getLogPrefix() + "got error creating transformer from file [" + exceptionLogString + "]", te);
    }
    try {
        Resource auditLogResource = Resource.getResource(this, auditLogString);
        if (auditLogResource == null) {
            throw new ConfigurationException(getLogPrefix() + "cannot find stylesheet [" + auditLogString + "]");
        }
        auditLogTp = TransformerPool.getInstance(auditLogResource, 2);
    } catch (IOException e) {
        throw new ConfigurationException(getLogPrefix() + "cannot retrieve [" + auditLogString + "]", e);
    } catch (TransformerConfigurationException te) {
        throw new ConfigurationException(getLogPrefix() + "got error creating transformer from file [" + auditLogString + "]", te);
    }
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Resource(nl.nn.adapterframework.core.Resource) IOException(java.io.IOException)

Example 20 with Resource

use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.

the class WsdlGeneratorPipe method createPipeLineFromXsdFile.

private PipeLine createPipeLineFromXsdFile(File xsdFile) throws ConfigurationException {
    PipeLine pipeLine = new PipeLine();
    EsbSoapValidator inputValidator;
    inputValidator = createValidator(xsdFile, null, null, 1, 1, pipeLine);
    pipeLine.setInputValidator(inputValidator);
    String countRoot = null;
    try {
        String countRootXPath = "count(*/*[local-name()='element'])";
        TransformerPool tp = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource(countRootXPath, OutputType.TEXT));
        Resource xsdResource = Resource.getResource(xsdFile.getPath());
        countRoot = tp.transform(xsdResource.asSource());
        if (StringUtils.isNotEmpty(countRoot)) {
            log.debug("counted [" + countRoot + "] root elements in xsd file [" + xsdFile.getName() + "]");
            int cr = Integer.parseInt(countRoot);
            if (cr > 1) {
                EsbSoapValidator outputValidator;
                outputValidator = createValidator(xsdFile, null, null, 2, 1, pipeLine);
                pipeLine.setOutputValidator(outputValidator);
            }
        }
    } catch (Exception e) {
        throw new ConfigurationException(e);
    }
    return pipeLine;
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Resource(nl.nn.adapterframework.core.Resource) PipeLine(nl.nn.adapterframework.core.PipeLine) TransformerPool(nl.nn.adapterframework.util.TransformerPool) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Aggregations

Resource (nl.nn.adapterframework.core.Resource)27 Test (org.junit.Test)12 IOException (java.io.IOException)10 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)7 XmlWriter (nl.nn.adapterframework.xml.XmlWriter)7 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)6 SAXException (org.xml.sax.SAXException)6 TransformerException (javax.xml.transform.TransformerException)4 TransformerPool (nl.nn.adapterframework.util.TransformerPool)4 URL (java.net.URL)3 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ValidatorHandler (javax.xml.validation.ValidatorHandler)2 ConfigurationDigester (nl.nn.adapterframework.configuration.ConfigurationDigester)2 CredentialFactory (nl.nn.adapterframework.util.CredentialFactory)2 Digester (org.apache.commons.digester3.Digester)2 QueueInfo (com.tibco.tibjms.admin.QueueInfo)1 TibjmsAdmin (com.tibco.tibjms.admin.TibjmsAdmin)1 TibjmsAdminException (com.tibco.tibjms.admin.TibjmsAdminException)1 File (java.io.File)1