Apache Http Client Maven



Client

Designed for extension while providing robust support for the base HTTP protocol, HttpClient may be of interest to anyone building HTTP-aware client applications such as web browsers, web service clients, or systems that leverage or extend the HTTP protocol for distributed communication.

The Apache HttpComponents project is responsible for creating and maintaining a toolset of low level Java components focused on HTTP and associated protocols.

  1. In case, you are not using maven or gradle or any other build mechanism in your project, then download the HttpClient jar file from this location and configure it into your classpath. How to send GET request using Apache HttpClient?
  2. Apache Http Client is used to connect to the HTTP server and perform all the activities against it. Here is the code that you can add into your pom.xml file: org.apache.httpcomponents httpclient 4.5.12.
  3. HttpClient is a HTTP/1.1 compliant HTTP agent implementation based on HttpCore. It also provides reusable components for client-side authentication, HTTP state management, and HTTP connection management. HttpComponents Client is a successor of and replacement for Commons HttpClient 3.x. Users of Commons HttpClient are strongly encouraged to.
  4. Name Email Dev Id Roles Organization; Ortwin Glueck: oglueck -at- apache.org: oglueck: Emeritus PMC: Oleg Kalnichevski: olegk -at- apache.org: olegk: Committer, PMC.

This project functions under the Apache Software Foundation (http://www.apache.org), and is part of a larger community of developers and users.

HttpComponents Overview

The Hyper-Text Transfer Protocol (HTTP) is perhaps the most significant protocol used on the Internet today. Web services, network-enabled appliances and the growth of network computing continue to expand the role of the HTTP protocol beyond user-driven web browsers, while increasing the number of applications that require HTTP support.

Designed for extension while providing robust support for the base HTTP protocol, the HttpComponents may be of interest to anyone building HTTP-aware client and server applications such as web browsers, web spiders, HTTP proxies, web service transport libraries, or systems that leverage or extend the HTTP protocol for distributed communication.

HttpComponents Structure

HttpComponents Core

HttpCore is a set of low level HTTP transport components that can be used to build custom client and server side HTTP services with a minimal footprint. HttpCore supports two I/O models: blocking I/O model based on the classic Java I/O and non-blocking, event driven I/O model based on Java NIO.

HttpComponents Client

Apache httpclient 5 maven

HttpClient is a HTTP/1.1 compliant HTTP agent implementation based on HttpCore. It also provides reusable components for client-side authentication, HTTP state management, and HTTP connection management. HttpComponents Client is a successor of and replacement for Commons HttpClient 3.x. Users of Commons HttpClient are strongly encouraged to upgrade.

Commons HttpClient (legacy)

Commons HttpClient 3.x codeline is at the end of life. All users of Commons HttpClient 3.x are strongly encouraged to upgrade to HttpClient 4.1.

Guide to Remote repository access through authenticated HTTPS

This document describes how to configure Maven to access a remote repository that sits behind an HTTPS server which requires client authentication with certificates.

The problem

There is a maven repository at https://my.server.com/maven. This server only serves clients authenticated through SSL protocol by a valid certificate signed by an approved certificate authority's certificate which we call the CACert. In the simplest case where the server is used internally by an identified community of users (e.g. corporate intranet), the server's certificate is the certificate authority as the server is used only internally.

So we assume that we have access to the trusted certificate in X.509 format stored in a file named:

The client's certificate has been issued by some means not described in this document in PKCS#12 format, which is the format that is accepted by browsers (at least Firefox and Internet Explorer) for import into their keystore. This file is named:

and we assume it is accessible when launching maven. This file contains the client's private key which may be very sensitive information so it is secured by a password:

The remote repository is referenced either through the pom.xml file:

The solution

Apache Httpclient Jar

For maven to use this repository, we should take the following steps:

  1. Create a store to hold the server's certificate usings Oracle's keytool,
  2. Define properties to be used by HttpClient for finding keys and certificate

Storing certificate

The following command line imports the certififcate authority's certificate into a JKS formatted key store named trust.jks, the trust store.

Note that it should be possible to import a full chain of certificates with only one root certificate being trusted but the author did not test it.

Setting properties

Http

The following properties must be set at start of maven to be accessible when HttpClient starts up.

javax.net.ssl.trustStore
the path to the keystore where trusted certificates are stored
javax.net.ssl.trustStoreType
the type of storage for this store, maybe either jks (default) or pkcs12
javax.net.ssl.trustStorePassword
the password protecting the store
javax.net.ssl.keyStore
the path to the keystore where user's private key is stored
javax.net.ssl.keyStoreType
the type of storage for this store, maybe either jks (default) or pkcs12
javax.net.ssl.keyStorePassword
the password protecting the store

Not all the properties must be set depending of your precise settings: type of store may left to default, password may be empty.

Maven 2.0

They may be set either on maven's command-line, in .mavenrc file or in MAVEN_OPTS environment variable. For the setting defined in this document, here is an example .mavenrc file:

Apache Http Client Fluent Maven

Links

Apache Async Http Client Maven

The following links may be useful in understanding SSL infrastructure management in Java:

Apache Httpclient Maven

  • HttpClient's SSL guide