Commons Http Client is a HTTP agent implementation in java supporting
client-side authentication, HTTP state management and HTTP connection management.
This requires the libraries httpclient-4.1.2.jar, httpcore-4.1.2.jar,
httpmime-4.1.2.jar, httpclient-cache-4.1.2.jar, commons-codec.jar and
commons-logging-1.1.1.jar to be in classpath.
The following example shows how to access a JSP page protected through digest authentication in Tomcat v6.0.
Configure a new tomcat user venakat and role btc in tomcat-users.xml as shown below,
try {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("venkat", "mypassword");
AuthScope authscope = new AuthScope("localhost", 8080, "My Test Realm");
httpclient.getCredentialsProvider().setCredentials(authscope, credentials);