Apache Http Client Maven

Posted on  by admin

Wechatpay-apache-httpclient - An Apache HttpClient decorator for WeChat Pay's API com.github.wechatpay-apiv3: wechatpay-apache-httpclient - Maven Central Repository Search Maven Central Repository Search Quick Stats Report A Vulnerability. Anonymous Access with Maven. This project's source can be checked out anonymously from SVN with the following instruction set on a single line. DefaultHttpClient is the standard HttpClient and uses the SingleClientConnManager class to handle HTTP connections. SingleClientConnManager is not thread-safe, this means that access to it via several threads will create problems. The HttpClient uses a HttpUriRequest to send and receive data.

  1. Apache Commons Httpclient
  2. Apache Httpcomponents
  3. Apache Http Client 4.5 Maven

Apache Commons Httpclient

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.

In this quick article, we will discuss step by step how to use Apache HttpClient 4.5 to make an HTTP PUT request. The HTTP PUT Request Method requests that the server accepts and stores the entity enclosed in the supplied URI. If the URI refers to an already existing resource, it is modified; if the URI does not point to an existing resource, then the server can create the resource with that URI. Apache HttpClient is very widely used for sending HTTP requests from java program itself. If you are using Maven, then you can add below dependencies and it will include all other required dependencies for using Apache HttpClient.

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 maven

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

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

the path to the keystore where trusted certificates are stored
the type of storage for this store, maybe either jks (default) or pkcs12
the password protecting the store
the path to the keystore where user's private key is stored
the type of storage for this store, maybe either jks (default) or pkcs12
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

Apache Httpcomponents

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

  • HttpClient's SSL guide

Apache Http Client 4.5 Maven

Maven Getting Started Guide

This guide is intended as a reference for those working with Maven for the first time, but is also intended to serve as a cookbook with self-contained references and solutions for common use cases. For first time users, it is recommended that you step through the material in a sequential fashion. For users more familiar with Maven, this guide endeavours to provide a quick solution for the need at hand. It is assumed at this point that you have downloaded Maven and installed Maven on your local machine. If you have not done so please refer to the Download and Installation instructions.

Ok, so you now have Maven installed and we're ready to go. Before we jump into our examples we'll very briefly go over what Maven is and how it can help you with your daily work and collaborative efforts with team members. Maven will, of course, work for small projects, but Maven shines in helping teams operate more effectively by allowing team members to focus on what the stakeholders of a project require. You can leave the build infrastructure to Maven!