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;
}
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();
}
});
}
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);
}
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;
}
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);
}
Aggregations