apache-httpcomponents

Spring configurable, high performance, metered http client instances

谁说胖子不能爱 提交于 2019-12-04 10:10:31
Coming from DropWizard I am used to its HttpClientConfiguration and I am baffled that in Spring Boot I cannot find some support for controlling in a similar manner http clients instances to be used, by RestTemplates for example. To work in production the underlying client implementation should be high performance (e.g. non blocking io, with connection reuse and pooling). Then I need to set timeouts or authentication, possibly metrics gathering, cookie settings, SSL certificates settings. All of the above should be easy to set up in different variants for different instances to be used in

Importing a newer Apache HttpClient jar in Android

喜你入骨 提交于 2019-12-04 06:54:16
I'm trying to send an HTTP/HTTPS post request from my Android client. Question Why does my code fail? So far I created an apache class/HttpClient call. Everything worked fine: HttpClient httpClient = new DefaultHttpClient(); I've read that this method has been deprecated, so I've switched to the new recommended method: HttpClient httpClient = HttpClientBuilder.create().build(); Eclipse didn't have this class, so I had to download Apache HttpClient 4.3.3. I imported it to my project by copying it into the libs folder and adding them to my build path (imported httpclient, httpclient-cache,

How to find mimetype of response

你说的曾经没有我的故事 提交于 2019-12-04 00:11:12
问题 I am working with a GET request made using Apache HTTP client (v4- the latest version; not the older v3)... How do I obtain the mimetype of the response? In the older v3 of apache http client, mime type was obtained using following code-- String mimeType = response.getMimeType(); How do I get the mimetype using v4 of apache http client? 回答1: A "Content-type" HTTP header should give you mime type information: Header contentType = response.getFirstHeader("Content-Type"); or as Header

Setting time out in apache http client

 ̄綄美尐妖づ 提交于 2019-12-03 22:32:14
I'm using Apache http client 4.3.2 to send get requests. What I have done is: private final RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(1000) .setConnectionRequestTimeout(1000) .setSocketTimeout(1000) .build(); private final HttpClient client = HttpClientBuilder.create() .disableAuthCaching() .disableAutomaticRetries() .disableConnectionState() .disableContentCompression() .disableCookieManagement() .disableRedirectHandling() .setDefaultRequestConfig(requestConfig) .build(); And when sending request: HttpGet request = null; try { request = new HttpGet(url); if

maven dependency pulling a wrong dependency

耗尽温柔 提交于 2019-12-03 18:08:09
问题 I have a dependency as follows: <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.2</version> <scope>compile</scope> </dependency> This is pulling down another dependency httpcore.4.1.4 which throws a ClassDefNotFound, when i deploy httpcore.4.2 everything works. I added both of the dependencies as follows: <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.2</version> <scope>compile<

Using Proxy with HttpComponentsClientHttpRequestFactory and RestTemplate

非 Y 不嫁゛ 提交于 2019-12-03 16:52:19
问题 Can some one guide me how can I configure HttpComponentsClientHttpRequestFactory to use proxy server. All examples I have seen are using SimpleClientHttpRequestFactory . 回答1: If you do not mind using Apache Http Client it is not very complicated and there are 2 possibilities: If single proxy for all targets is enough for you: HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create() .setProxy(new HttpHost("myproxy

Default timeout for HttpComponent Client

柔情痞子 提交于 2019-12-03 10:41:18
I can't find any documentation on the default httpParams for httpclient 4.1 ? What's the default socket timeout when I do a GET ? According to the documentation , the http.socket.timeout parameter controls the SO_TIMEOUT value, and: If this parameter is not set, read operations will not time out (infinite timeout). Chandru The accepted answer is not applicable for newer versions of HttpClient. Versions 4.3.X and above use the system default which is usually 60 secs. Taken from HttpClient javadoc. public int getSocketTimeout() Defines the socket timeout (SO_TIMEOUT) in milliseconds, which is

HttpComponents PoolingHttpClientConnectionManager maxPerRoute and maxTotal?

前提是你 提交于 2019-12-03 08:40:02
问题 Can someone please explain to me what setMaxPerRoute(max) and setMaxTotal(max) do in reference to HttpComponents PoolingHttpClientConnectionManager? 回答1: These settings control connection pool size. setMaxTotal(max) defines the overal connection limit for a conneciton pool. setMaxPerRoute(max) defines a connection limit per one HTTP route. In simple cases you can understand this as a per target host limit. Under the hood things are a bit more interesting: HttpClient maintains a couple of

Using Proxy with HttpComponentsClientHttpRequestFactory and RestTemplate

孤街醉人 提交于 2019-12-03 05:54:14
Can some one guide me how can I configure HttpComponentsClientHttpRequestFactory to use proxy server. All examples I have seen are using SimpleClientHttpRequestFactory . If you do not mind using Apache Http Client it is not very complicated and there are 2 possibilities: If single proxy for all targets is enough for you: HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create() .setProxy(new HttpHost("myproxy.com", 80, "http")) .build()); restTemplate = new RestTemplate(clientHttpRequestFactory); Or if you want to

Apache HttpClient (4.1 and newer): how to do basic authentication?

ぐ巨炮叔叔 提交于 2019-12-03 02:14:45
问题 How do I add basic authentication for the default client of the httpClient library? I have seen examples where they use client.getCredentialProvider() , however I think all of this methods are for library version 4.0.1 or 3.x. Is there a new example of how to do this? Thanks a lot. 回答1: We do basic authentication with HttpClient , but we do not use CredentialProvider . Here's the code: HttpClient client = factory.getHttpClient(); //or any method to get a client instance Credentials