Notable changes and features included in the 5.0 series are:
* Support for the HTTP/2 protocol and conformance to requirements and recommendations of the latest HTTP/2 protocol specification documents (RFC 7540, RFC 7541.) Supported features: ** HPACK header compression ** Stream multiplexing (client and server) ** Flow control ** Response push ** Message trailers ** Expect-continue handshake ** Connection validation (ping) ** Application-layer protocol negotiation (ALPN) ** TLS 1.2 security features * Improved conformance to requirements and recommendations of the latest HTTP/1.1 protocol specification documents (RFC 7230, RFC 7231.) * New connection pool implementation with lax connection limit guarantees and better performance under higher concurrency due to absence of a global pool lock. * Support for Reactive Streams API [http://www.reactive-streams.org/] * Package name space changed to 'org.apache.hc.client5'. * Maven group id changed to 'org.apache.httpcomponents.client5'.
HttpClient 5.0 releases can be co-located with earlier major versions on the same classpath due to the change in package names and Maven module coordinates.
public String admin_userName="admin"; public String admin_userPwd="adminX"; StringformUserFiledName="j_username"; String formPwdFiledName="j_password"; BasicCookieStorecookieStore=newBasicCookieStore();
log.debug("====> Post login cookies:"); final List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { log.debug("===> Cookie None"); } else { for (inti=0; i < cookies.size(); i++) { log.debug("- " + cookies.get(i).toString()); } } return loginResponse.getCode(); } }
privatevoidinitCookie(CloseableHttpClient httpClient, BasicCookieStore cookieStore,String hostUrl)throws IOException { HttpGethttpget=newHttpGet(hostUrl); try (finalCloseableHttpResponseresponse1= httpClient.execute(httpget)) { finalHttpEntityentity= response1.getEntity(); log.debug("Login form get: " + response1.getCode() + " " + response1.getReasonPhrase()); EntityUtils.consume(entity); log.debug("Initial set of cookies:"); final List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { log.warn(" get user cookies is None"); } else { for (inti=0; i < cookies.size(); i++) { log.debug("get user cookies - " + cookies.get(i).toString()); } } } }
// Create an HttpClient with the PoolingHttpClientConnectionManager. // This connection manager must be used if more than one thread will // be using the HttpClient. finalPoolingHttpClientConnectionManagercm=newPoolingHttpClientConnectionManager(); cm.setMaxTotal(100); try (finalCloseableHttpClienthttpclient= HttpClients.custom() .setConnectionManager(cm) .build()) { // create an array of URIs to perform GETs on final String[] urisToGet = { "http://hc.apache.org/", "http://hc.apache.org/httpcomponents-core-ga/", "http://hc.apache.org/httpcomponents-client-ga/", }; // create a thread for each URI final GetThread[] threads = newGetThread[urisToGet.length]; for (inti=0; i < threads.length; i++) { finalHttpGethttpget=newHttpGet(urisToGet[i]); threads[i] = newGetThread(httpclient, httpget, i + 1); } // start the threads for (final GetThread thread : threads) { thread.start(); } // join the threads for (final GetThread thread : threads) { thread.join(); }