Search in sources :

Example 11 with Resource

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

the class ConfigurationDigester method getStub4TesttoolContentHandler.

/**
 * Get the contenthandler to stub configurations
 * If stubbing is disabled, the input ContentHandler is returned as-is
 */
public ContentHandler getStub4TesttoolContentHandler(ContentHandler handler, Properties properties) throws IOException, TransformerConfigurationException {
    if (Boolean.parseBoolean(properties.getProperty(ConfigurationUtils.STUB4TESTTOOL_CONFIGURATION_KEY, "false"))) {
        Resource xslt = Resource.getResource(ConfigurationUtils.STUB4TESTTOOL_XSLT);
        TransformerPool tp = TransformerPool.getInstance(xslt);
        TransformerFilter filter = tp.getTransformerFilter(null, handler);
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put(ConfigurationUtils.STUB4TESTTOOL_XSLT_VALIDATORS_PARAM, Boolean.parseBoolean(properties.getProperty(ConfigurationUtils.STUB4TESTTOOL_VALIDATORS_DISABLED_KEY, "false")));
        XmlUtils.setTransformerParameters(filter.getTransformer(), parameters);
        return filter;
    }
    return handler;
}
Also used : TransformerFilter(nl.nn.adapterframework.xml.TransformerFilter) HashMap(java.util.HashMap) Resource(nl.nn.adapterframework.core.Resource) TransformerPool(nl.nn.adapterframework.util.TransformerPool)

Example 12 with Resource

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

the class HttpSenderBase method configure.

@Override
public void configure() throws ConfigurationException {
    super.configure();
    /**
     * TODO find out if this really breaks proxy authentication or not.
     */
    // httpClientBuilder.disableAuthCaching();
    httpClientBuilder.disableAutomaticRetries();
    Builder requestConfigBuilder = RequestConfig.custom();
    requestConfigBuilder.setConnectTimeout(getTimeout());
    requestConfigBuilder.setConnectionRequestTimeout(getTimeout());
    requestConfigBuilder.setSocketTimeout(getTimeout());
    if (paramList != null) {
        paramList.configure();
        if (StringUtils.isNotEmpty(getUrlParam())) {
            urlParameter = paramList.findParameter(getUrlParam());
            if (urlParameter != null)
                addParameterToSkip(urlParameter.getName());
        }
        // Add all HeaderParams to paramIgnoreList
        StringTokenizer st = new StringTokenizer(getHeadersParams(), ",");
        while (st.hasMoreElements()) {
            addParameterToSkip(st.nextToken());
        }
    }
    if (StringUtils.isNotEmpty(getContentType())) {
        fullContentType = ContentType.parse(getContentType());
        if (fullContentType != null && fullContentType.getCharset() == null) {
            fullContentType = fullContentType.withCharset(getCharSet());
        }
    }
    if (getMaxConnections() <= 0) {
        throw new ConfigurationException(getLogPrefix() + "maxConnections is set to [" + getMaxConnections() + "], which is not enough for adequate operation");
    }
    try {
        if (urlParameter == null) {
            if (StringUtils.isEmpty(getUrl())) {
                throw new ConfigurationException(getLogPrefix() + "url must be specified, either as attribute, or as parameter");
            }
            staticUri = getURI(getUrl());
        }
    } catch (URISyntaxException e) {
        throw new ConfigurationException(getLogPrefix() + "cannot interpret url [" + getUrl() + "]", e);
    }
    AuthSSLContextFactory.verifyKeystoreConfiguration(this, this);
    if (StringUtils.isNotEmpty(getAuthAlias()) || StringUtils.isNotEmpty(getUsername())) {
        credentials = new CredentialFactory(getAuthAlias(), getUsername(), getPassword());
    } else {
        credentials = new CredentialFactory(getClientAuthAlias(), getClientId(), getClientSecret());
    }
    if (StringUtils.isNotEmpty(getTokenEndpoint()) && StringUtils.isEmpty(getClientAuthAlias()) && StringUtils.isEmpty(getClientId())) {
        throw new ConfigurationException("To obtain accessToken at tokenEndpoint [" + getTokenEndpoint() + "] a clientAuthAlias or ClientId and ClientSecret must be specified");
    }
    HttpHost proxy = null;
    CredentialFactory pcf = null;
    if (StringUtils.isNotEmpty(getProxyHost())) {
        proxy = new HttpHost(getProxyHost(), getProxyPort());
        pcf = new CredentialFactory(getProxyAuthAlias(), getProxyUsername(), getProxyPassword());
        requestConfigBuilder.setProxy(proxy);
        httpClientBuilder.setProxy(proxy);
    }
    setupAuthentication(credentials, pcf, proxy, requestConfigBuilder);
    if (StringUtils.isNotEmpty(getStyleSheetName())) {
        try {
            Resource stylesheet = Resource.getResource(this, getStyleSheetName());
            if (stylesheet == null) {
                throw new ConfigurationException(getLogPrefix() + "cannot find stylesheet [" + getStyleSheetName() + "]");
            }
            transformerPool = TransformerPool.getInstance(stylesheet);
        } catch (IOException e) {
            throw new ConfigurationException(getLogPrefix() + "cannot retrieve [" + getStyleSheetName() + "]", e);
        } catch (TransformerConfigurationException te) {
            throw new ConfigurationException(getLogPrefix() + "got error creating transformer from file [" + getStyleSheetName() + "]", te);
        }
    }
    httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
    if (areCookiesDisabled()) {
        httpClientBuilder.disableCookieManagement();
    }
    // The redirect strategy used to only redirect GET, DELETE and HEAD.
    httpClientBuilder.setRedirectStrategy(new DefaultRedirectStrategy() {

        @Override
        protected boolean isRedirectable(String method) {
            return isFollowRedirects();
        }
    });
}
Also used : StringTokenizer(java.util.StringTokenizer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) HttpHost(org.apache.http.HttpHost) Builder(org.apache.http.client.config.RequestConfig.Builder) URIBuilder(org.apache.http.client.utils.URIBuilder) RegistryBuilder(org.apache.http.config.RegistryBuilder) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) Resource(nl.nn.adapterframework.core.Resource) DefaultRedirectStrategy(org.apache.http.impl.client.DefaultRedirectStrategy) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 13 with Resource

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

the class XmlSwitch method configure.

/**
 * If no {@link #setStyleSheetName(String) styleSheetName} is specified, the
 * switch uses the root node.
 */
@Override
public void configure() throws ConfigurationException {
    super.configure();
    if (getNotFoundForwardName() != null) {
        if (findForward(getNotFoundForwardName()) == null) {
            ConfigurationWarnings.add(this, log, "has a notFoundForwardName attribute. However, this forward [" + getNotFoundForwardName() + "] is not configured.");
        }
    }
    if (getEmptyForwardName() != null) {
        if (findForward(getEmptyForwardName()) == null) {
            ConfigurationWarnings.add(this, log, "has a emptyForwardName attribute. However, this forward [" + getEmptyForwardName() + "] is not configured.");
        }
    }
    if (StringUtils.isNotEmpty(getXpathExpression())) {
        if (StringUtils.isNotEmpty(getStyleSheetName())) {
            throw new ConfigurationException("cannot have both an xpathExpression and a styleSheetName specified");
        }
        transformerPool = TransformerPool.configureTransformer0(getLogPrefix(null), this, getNamespaceDefs(), getXpathExpression(), null, OutputType.TEXT, false, getParameterList(), getXsltVersion());
    } else if (StringUtils.isNotEmpty(getStyleSheetName())) {
        try {
            Resource stylesheet = Resource.getResource(this, getStyleSheetName());
            if (stylesheet == null) {
                throw new ConfigurationException("cannot find stylesheet [" + getStyleSheetName() + "]");
            }
            transformerPool = TransformerPool.getInstance(stylesheet, getXsltVersion());
        } catch (IOException e) {
            throw new ConfigurationException("cannot retrieve [" + styleSheetName + "]", e);
        } catch (TransformerConfigurationException te) {
            throw new ConfigurationException("got error creating transformer from file [" + styleSheetName + "]", te);
        }
    } else {
        try {
            transformerPool = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource(DEFAULT_SERVICESELECTION_XPATH, OutputType.TEXT));
        } catch (TransformerConfigurationException e) {
            throw new ConfigurationException("got error creating XPathEvaluator from string [" + DEFAULT_SERVICESELECTION_XPATH + "]", e);
        }
    }
    registerEvent(XML_SWITCH_FORWARD_FOUND_MONITOR_EVENT);
    registerEvent(XML_SWITCH_FORWARD_NOT_FOUND_MONITOR_EVENT);
}
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 14 with Resource

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

the class TransformerPool method configureStyleSheetTransformer.

public static TransformerPool configureStyleSheetTransformer(String logPrefix, IConfigurationAware scopeProvider, String styleSheetName, int xsltVersion) throws ConfigurationException {
    TransformerPool result;
    if (logPrefix == null) {
        logPrefix = "";
    }
    if (!StringUtils.isEmpty(styleSheetName)) {
        Resource styleSheet = null;
        try {
            styleSheet = Resource.getResource(scopeProvider, styleSheetName);
            if (styleSheet == null) {
                throw new ConfigurationException(logPrefix + " cannot find [" + styleSheetName + "] in scope [" + scopeProvider + "]");
            }
            if (log.isDebugEnabled())
                log.debug(logPrefix + "configuring stylesheet [" + styleSheetName + "] resource [" + styleSheet + "]");
            result = TransformerPool.getInstance(styleSheet, xsltVersion);
            if (xsltVersion != 0) {
                String xsltVersionInStylesheet = result.getConfigMap().get("stylesheet-version");
                int detectedXsltVersion = XmlUtils.interpretXsltVersion(xsltVersionInStylesheet);
                if (xsltVersion != detectedXsltVersion) {
                    ConfigurationWarnings.add(scopeProvider, log, logPrefix + "configured xsltVersion [" + xsltVersion + "] does not match xslt version [" + detectedXsltVersion + "] declared in stylesheet [" + styleSheet.getSystemId() + "]");
                }
            }
        } catch (IOException e) {
            throw new ConfigurationException(logPrefix + "cannot retrieve [" + styleSheetName + "] resource [" + styleSheet + "]", e);
        } catch (SAXException | TransformerException e) {
            throw new ConfigurationException(logPrefix + " got error creating transformer from file [" + styleSheetName + "]", e);
        }
        if (XmlUtils.isAutoReload()) {
            result.reloadResource = styleSheet;
        }
    } else {
        throw new ConfigurationException(logPrefix + " either xpathExpression or styleSheetName must be specified");
    }
    return result;
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Resource(nl.nn.adapterframework.core.Resource) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 15 with Resource

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

the class ConfigurationDigesterTest method testNewCanonicalizer.

@Test
public void testNewCanonicalizer() throws Exception {
    XmlWriter writer = new XmlWriter();
    ConfigurationDigester digester = new ConfigurationDigester();
    ContentHandler handler = digester.getConfigurationCanonicalizer(writer, FRANK_CONFIG_XSD, new XmlErrorHandler());
    Resource resource = Resource.getResource("/Digester/SimpleConfiguration/Configuration.xml");
    XmlUtils.parseXml(resource, handler);
    String result = writer.toString();
    String expected = TestFileUtils.getTestFile("/Digester/Canonicalized/SimpleConfiguration.xml");
    MatchUtils.assertXmlEquals(expected, result);
}
Also used : Resource(nl.nn.adapterframework.core.Resource) ConfigurationDigester(nl.nn.adapterframework.configuration.ConfigurationDigester) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) ContentHandler(org.xml.sax.ContentHandler) 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