Search in sources :

Example 1 with Resource

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

the class ConfigurationDigester method getDigester.

private Digester getDigester(Configuration configuration) throws ConfigurationException, ParserConfigurationException, SAXException {
    XMLReader reader = XmlUtils.getXMLReader(configuration);
    Digester digester = new Digester(reader) {

        // override Digester.createSAXException() implementations to obtain a clear unduplicated message and a properly nested stacktrace on IBM JDK
        @Override
        public SAXException createSAXException(String message, Exception e) {
            return SaxException.createSaxException(message, getDocumentLocator(), e);
        }

        @Override
        public SAXException createSAXException(Exception e) {
            return SaxException.createSaxException(null, getDocumentLocator(), e);
        }
    };
    digester.setUseContextClassLoader(true);
    digester.push(configuration);
    Resource digesterRulesResource = Resource.getResource(configuration, getDigesterRules());
    loadDigesterRules(digester, digesterRulesResource);
    if (validation) {
        digester.setValidating(true);
        digester.setNamespaceAware(true);
        digester.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
        URL xsdUrl = ClassUtils.getResourceURL(CONFIGURATION_VALIDATION_SCHEMA);
        if (xsdUrl == null) {
            throw new ConfigurationException("cannot get URL from [" + CONFIGURATION_VALIDATION_SCHEMA + "]");
        }
        digester.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", xsdUrl.toExternalForm());
        XmlErrorHandler xeh = new XmlErrorHandler(CONFIGURATION_VALIDATION_SCHEMA);
        digester.setErrorHandler(xeh);
    }
    return digester;
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Digester(org.apache.commons.digester3.Digester) Resource(nl.nn.adapterframework.core.Resource) XMLReader(org.xml.sax.XMLReader) SaxException(nl.nn.adapterframework.xml.SaxException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) URL(java.net.URL)

Example 2 with Resource

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

the class ConfigurationDigester method digestConfiguration.

private void digestConfiguration(Configuration configuration) throws ConfigurationException {
    String configurationFile = ConfigurationUtils.getConfigurationFile(configuration.getClassLoader(), configuration.getName());
    Digester digester = null;
    Resource configurationResource = Resource.getResource(configuration, configurationFile);
    if (configurationResource == null) {
        throw new ConfigurationException("Configuration file [" + configurationFile + "] not found in ClassLoader [" + configuration.getClassLoader() + "]");
    }
    try {
        digester = getDigester(configuration);
        if (log.isDebugEnabled())
            log.debug("digesting configuration [" + configuration.getName() + "] configurationFile [" + configurationFile + "]");
        AppConstants appConstants = AppConstants.getInstance(configuration.getClassLoader());
        parseAndResolveEntitiesAndProperties(digester, configuration, configurationResource, appConstants);
        configLogger.info(configuration.getLoadedConfiguration());
    } catch (Throwable t) {
        // wrap exception to be sure it gets rendered via the IbisException-renderer
        String currentElementName = null;
        if (digester != null) {
            currentElementName = digester.getCurrentElementName();
        }
        throw new ConfigurationException("error during unmarshalling configuration from file [" + configurationFile + "] with digester-rules-file [" + getDigesterRules() + "] in element [" + currentElementName + "]", t);
    }
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Digester(org.apache.commons.digester3.Digester) Resource(nl.nn.adapterframework.core.Resource) AppConstants(nl.nn.adapterframework.util.AppConstants)

Example 3 with Resource

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

the class ClassLoaderEntityResolver method resolveEntity.

/**
 * @see org.xml.sax.EntityResolver#resolveEntity(String, String)
 */
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    if (log.isDebugEnabled())
        log.debug("Resolving publicId [" + publicId + "] systemId [" + systemId + "] in scope [" + scopeProvider + "]");
    Resource resource = Resource.getResource(scopeProvider, systemId);
    if (resource != null) {
        return resource.asInputSource();
    }
    // If nothing found, return a SAXException. If NULL is returned it can trigger default (fallback) behaviour using the internal EntityResolver.
    String message = "Cannot get resource for publicId [" + publicId + "] with systemId [" + systemId + "] in scope [" + scopeProvider + "]";
    throw new SAXException(message);
}
Also used : Resource(nl.nn.adapterframework.core.Resource) SAXException(org.xml.sax.SAXException)

Example 4 with Resource

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

the class FlowDiagramManager method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    Resource xsltSourceConfig = Resource.getResource(ADAPTER2DOT_XSLT);
    transformerPoolAdapter = TransformerPool.getInstance(xsltSourceConfig, 2);
    Resource xsltSourceIbis = Resource.getResource(CONFIGURATION2DOT_XSLT);
    transformerPoolConfig = TransformerPool.getInstance(xsltSourceIbis, 2);
    IFlowGenerator generator = getFlowGenerator();
    if (generator == null) {
        log.warn("no IFlowGenerator found. Unable to generate flow diagrams");
    } else {
        if (log.isDebugEnabled())
            log.debug("using IFlowGenerator [" + generator + "]");
        fileExtension = generator.getFileExtension();
    }
    noImageAvailable = ClassUtils.getResourceURL(NO_IMAGE_AVAILABLE);
    if (noImageAvailable == null) {
        throw new IllegalStateException("image [" + NO_IMAGE_AVAILABLE + "] not found");
    }
}
Also used : Resource(nl.nn.adapterframework.core.Resource)

Example 5 with Resource

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

the class FrankDigesterRulesTest method parseDigesterRulesXml.

@Test
public void parseDigesterRulesXml() {
    DummyDigesterRulesParser handler = new DummyDigesterRulesParser();
    Resource digesterRules = Resource.getResource("digester-rules.xml");
    try {
        XmlUtils.parseXml(digesterRules.asInputSource(), handler);
    } catch (IOException e) {
        throw new IllegalStateException("unable to open digesterRules file", e);
    } catch (SAXException e) {
        throw new IllegalStateException("unable to parse digesterRules file", e);
    }
    assertTrue("must at least have 33 patterns", handler.size() >= 33);
}
Also used : Resource(nl.nn.adapterframework.core.Resource) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

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