Apache Httpclient Logging



  • Context Logging Context logging contains information about the internal operation of HttpClient as it performs HTTP requests. Each class has its own log named according to the class's fully qualified name. For example the class HttpClient has a log named org.apache.commons.httpclient.HttpClient.
  • Org.apache.http.client HttpClient. A Handler object accepts a logging request and exports the desired messages to a target, for example.
httpclient-logging-connection-discarded

In this quick article, we will discuss step by step how to use Apache HttpClient 4.5 to make an HTTP POST request. The HTTP POST request method requests that the server accepts the entity enclosed in the request as a new subordinate of the web resource identified by the URI. How to view the request of Apache HttpClient before send the request Many occations, we are using Apache HttpClinet to send requests in applications. So sometimes we needs to observe the request of the http client.

http-outgoing-58: Shutdown connection
Connection discarded
http-outgoing-58: Close connection
Connection released: [id: 58][route: {}->http://myhost:8080[total kept alive: 6; route allocated: 4 of 50; total allocated: 6 of 100]

commented Nov 26, 2015

Connections will periodically be shut-down and discarded from the pool by HttpClient. This will decrement the allocation counts. In general, this behavior is normal and should be expected. However, if you see this happening on a continual basis for the majority of your requests, it might be because you are closing your connections improperly, thereby negating the benefits of the connection pooling.

For more information, please see How to Read HttpClient Logging and Prevent Connection Leaks.

commented Mar 16, 2018

Apache Httpclient Https

Hi,

I got the similer issue.

15:36:38.955 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-1: Shutdown connection
15:36:38.955 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection discarded
15:36:38.956 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-1: Close connection
15:36:38.956 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 1][route: {}->http://172.17.0.1:7272][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]

commented Mar 16, 2018

Hi Vishal,
I am also facing the same problem. Any lead ?

commented May 11, 2020

Hi I am facing the same issue, Do we have an update on this ?

HttpclientHttpclient
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

First, we'll show how to send a custom cookie with an HttpClient request. Then, we'll see how to get it from the response.

Apache httpclient log raw request

Please note that the code examples presented here are based on HttpClient 4.3.x and above, so they won't work on older versions of the API.

First, we create a basic cookie store and a basic cookie with the name custom_cookie and value test_value. Then, we create an HttpClientContext instance that will hold the cookie store. Finally, we pass the created context as an argument to the execute() method.

3. Accessing Cookies

Apache

Now that we've sent a custom cookie in a request, let's see how to read it from the response:

Apache Httpclient Api

To get our custom cookie from the response, we must first get the cookie store from the context. Then, we use the getCookies method to get the cookies list. We can then make use of Java streams to iterate over it and search for our cookie. Additionally, we log all cookie names from the store: