use of org.apache.commons.httpclient.HttpConnectionManager in project camel by apache.
the class GeoCoderEndpoint method createGeocoder.
Geocoder createGeocoder() throws InvalidKeyException {
HttpConnectionManager connectionManager = this.httpConnectionManager;
if (connectionManager == null) {
connectionManager = new MultiThreadedHttpConnectionManager();
}
HttpClient httpClient = new HttpClient(connectionManager);
if (proxyHost != null && proxyPort != null) {
httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
}
// validate that if proxy auth username is given then the proxy auth method is also provided
if (proxyAuthUsername != null && proxyAuthMethod == null) {
throw new IllegalArgumentException("Option proxyAuthMethod must be provided to use proxy authentication");
}
CompositeHttpConfigurer configurer = new CompositeHttpConfigurer();
if (proxyAuthMethod != null) {
configureProxyAuth(configurer, proxyAuthMethod, proxyAuthUsername, proxyAuthPassword, proxyAuthDomain, proxyAuthHost);
}
if (httpClientConfigurer != null) {
configurer.addConfigurer(httpClientConfigurer);
}
configurer.configureHttpClient(httpClient);
Geocoder geocoder;
if (clientId != null) {
geocoder = new AdvancedGeoCoder(httpClient, clientId, clientKey);
} else {
geocoder = new AdvancedGeoCoder(httpClient);
}
return geocoder;
}
use of org.apache.commons.httpclient.HttpConnectionManager in project camel by apache.
the class HttpComponent method createEndpoint.
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
String addressUri = "http://" + remaining;
if (uri.startsWith("https:")) {
addressUri = "https://" + remaining;
}
Map<String, Object> httpClientParameters = new HashMap<String, Object>(parameters);
// must extract well known parameters before we create the endpoint
HttpBinding binding = resolveAndRemoveReferenceParameter(parameters, "httpBinding", HttpBinding.class);
HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
UrlRewrite urlRewrite = resolveAndRemoveReferenceParameter(parameters, "urlRewrite", UrlRewrite.class);
// http client can be configured from URI options
HttpClientParams clientParams = new HttpClientParams();
Map<String, Object> httpClientOptions = IntrospectionSupport.extractProperties(parameters, "httpClient.");
IntrospectionSupport.setProperties(clientParams, httpClientOptions);
// validate that we could resolve all httpClient. parameters as this component is lenient
validateParameters(uri, httpClientOptions, null);
// http client can be configured from URI options
HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams();
// setup the httpConnectionManagerParams
Map<String, Object> httpConnectionManagerOptions = IntrospectionSupport.extractProperties(parameters, "httpConnectionManager.");
IntrospectionSupport.setProperties(connectionManagerParams, httpConnectionManagerOptions);
// validate that we could resolve all httpConnectionManager. parameters as this component is lenient
validateParameters(uri, httpConnectionManagerOptions, null);
// make sure the component httpConnectionManager is take effect
HttpConnectionManager thisHttpConnectionManager = httpConnectionManager;
if (thisHttpConnectionManager == null) {
// only set the params on the new created http connection manager
thisHttpConnectionManager = new MultiThreadedHttpConnectionManager();
thisHttpConnectionManager.setParams(connectionManagerParams);
}
// create the configurer to use for this endpoint (authMethods contains the used methods created by the configurer)
final Set<AuthMethod> authMethods = new LinkedHashSet<AuthMethod>();
HttpClientConfigurer configurer = createHttpClientConfigurer(parameters, authMethods);
addressUri = UnsafeUriCharactersEncoder.encodeHttpURI(addressUri);
URI endpointUri = URISupport.createRemainingURI(new URI(addressUri), httpClientParameters);
// create the endpoint and connectionManagerParams already be set
HttpEndpoint endpoint = createHttpEndpoint(endpointUri.toString(), this, clientParams, thisHttpConnectionManager, configurer);
// configure the endpoint with the common configuration from the component
if (getHttpConfiguration() != null) {
Map<String, Object> properties = new HashMap<>();
IntrospectionSupport.getProperties(getHttpConfiguration(), properties, null);
setProperties(endpoint, properties);
}
if (headerFilterStrategy != null) {
endpoint.setHeaderFilterStrategy(headerFilterStrategy);
} else {
setEndpointHeaderFilterStrategy(endpoint);
}
if (urlRewrite != null) {
// let CamelContext deal with the lifecycle of the url rewrite
// this ensures its being shutdown when Camel shutdown etc.
getCamelContext().addService(urlRewrite);
endpoint.setUrlRewrite(urlRewrite);
}
// prefer to use endpoint configured over component configured
if (binding == null) {
// fallback to component configured
binding = getHttpBinding();
}
if (binding != null) {
endpoint.setBinding(binding);
}
setProperties(endpoint, parameters);
// restructure uri to be based on the parameters left as we dont want to include the Camel internal options
URI httpUri = URISupport.createRemainingURI(new URI(addressUri), parameters);
// validate http uri that end-user did not duplicate the http part that can be a common error
String part = httpUri.getSchemeSpecificPart();
if (part != null) {
part = part.toLowerCase();
if (part.startsWith("//http//") || part.startsWith("//https//") || part.startsWith("//http://") || part.startsWith("//https://")) {
throw new ResolveEndpointFailedException(uri, "The uri part is not configured correctly. You have duplicated the http(s) protocol.");
}
}
endpoint.setHttpUri(httpUri);
endpoint.setHttpClientOptions(httpClientOptions);
return endpoint;
}
use of org.apache.commons.httpclient.HttpConnectionManager in project camel by apache.
the class WeatherComponent method createHttpClient.
private HttpClient createHttpClient(WeatherConfiguration configuration) {
HttpConnectionManager connectionManager = configuration.getHttpConnectionManager();
if (connectionManager == null) {
connectionManager = new MultiThreadedHttpConnectionManager();
}
HttpClient httpClient = new HttpClient(connectionManager);
if (configuration.getProxyHost() != null && configuration.getProxyPort() != null) {
httpClient.getHostConfiguration().setProxy(configuration.getProxyHost(), configuration.getProxyPort());
}
if (configuration.getProxyAuthUsername() != null && configuration.getProxyAuthMethod() == null) {
throw new IllegalArgumentException("Option proxyAuthMethod must be provided to use proxy authentication");
}
CompositeHttpConfigurer configurer = new CompositeHttpConfigurer();
if (configuration.getProxyAuthMethod() != null) {
configureProxyAuth(configurer, configuration.getProxyAuthMethod(), configuration.getProxyAuthUsername(), configuration.getProxyAuthPassword(), configuration.getProxyAuthDomain(), configuration.getProxyAuthHost());
}
configurer.configureHttpClient(httpClient);
return httpClient;
}
use of org.apache.commons.httpclient.HttpConnectionManager in project camel by apache.
the class MultiThreadedHttpGetTest method testHttpGetWithoutConversion.
@Test
public void testHttpGetWithoutConversion() throws Exception {
// This is needed as by default there are 2 parallel
// connections to some host and there is nothing that
// closes the http connection here.
// Need to set the httpConnectionManager
HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
httpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(5);
context.getComponent("http", HttpComponent.class).setHttpConnectionManager(httpConnectionManager);
String endpointName = "seda:withoutConversion?concurrentConsumers=5";
sendMessagesTo(endpointName, 5);
}
use of org.apache.commons.httpclient.HttpConnectionManager in project sling by apache.
the class JsonPipe method configureHttpClient.
/**
* Configure http client
*/
private void configureHttpClient() {
HttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
manager.setParams(params);
client = new HttpClient(manager);
client.getParams().setAuthenticationPreemptive(false);
}
Aggregations