use of org.apache.http.client.config.RequestConfig.Builder 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();
}
});
}
Aggregations