diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientAbortMethod.java b/httpclient/src/examples/org/apache/http/examples/client/ClientAbortMethod.java index c92ac9ef7..1b01f1c3f 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientAbortMethod.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientAbortMethod.java @@ -40,7 +40,7 @@ public class ClientAbortMethod { public final static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try { - HttpGet httpget = new HttpGet("http://www.apache.org/"); + HttpGet httpget = new HttpGet("http://httpbin.org/get"); System.out.println("Executing request " + httpget.getURI()); CloseableHttpResponse response = httpclient.execute(httpget); diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientAuthentication.java b/httpclient/src/examples/org/apache/http/examples/client/ClientAuthentication.java index e4c50e7db..d4c8fc850 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientAuthentication.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientAuthentication.java @@ -45,20 +45,20 @@ public class ClientAuthentication { public static void main(String[] args) throws Exception { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( - new AuthScope("localhost", 443), - new UsernamePasswordCredentials("username", "password")); + new AuthScope("httpbin.org", 80), + new UsernamePasswordCredentials("user", "passwd")); CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credsProvider) .build(); try { - HttpGet httpget = new HttpGet("http://localhost/"); + HttpGet httpget = new HttpGet("http://httpbin.org/basic-auth/user/passwd"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); - EntityUtils.consume(response.getEntity()); + System.out.println(EntityUtils.toString(response.getEntity())); } finally { response.close(); } diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientChunkEncodedPost.java b/httpclient/src/examples/org/apache/http/examples/client/ClientChunkEncodedPost.java index dbf4d8966..39a4fad00 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientChunkEncodedPost.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientChunkEncodedPost.java @@ -49,7 +49,7 @@ public class ClientChunkEncodedPost { } CloseableHttpClient httpclient = HttpClients.createDefault(); try { - HttpPost httppost = new HttpPost("http://localhost/"); + HttpPost httppost = new HttpPost("http://httpbin.org/post"); File file = new File(args[0]); @@ -69,7 +69,7 @@ public class ClientChunkEncodedPost { try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); - EntityUtils.consume(response.getEntity()); + System.out.println(EntityUtils.toString(response.getEntity())); } finally { response.close(); } diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java b/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java index ac6aa394c..4ad7230a7 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java @@ -81,6 +81,7 @@ import org.apache.http.message.BasicLineParser; import org.apache.http.message.LineParser; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.CharArrayBuffer; +import org.apache.http.util.EntityUtils; /** * This example demonstrates how to customize and configure the most common aspects @@ -221,7 +222,7 @@ public class ClientConfiguration { .build(); try { - HttpGet httpget = new HttpGet("http://www.apache.org/"); + HttpGet httpget = new HttpGet("http://httpbin.org/get"); // Request configuration can be overridden at the request level. // They will take precedence over the one set at the client level. RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig) @@ -242,13 +243,9 @@ public class ClientConfiguration { System.out.println("executing request " + httpget.getURI()); CloseableHttpResponse response = httpclient.execute(httpget, context); try { - HttpEntity entity = response.getEntity(); - System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); - if (entity != null) { - System.out.println("Response content length: " + entity.getContentLength()); - } + System.out.println(EntityUtils.toString(response.getEntity())); System.out.println("----------------------------------------"); // Once the request has been executed the local context can diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientConnectionRelease.java b/httpclient/src/examples/org/apache/http/examples/client/ClientConnectionRelease.java index 84d680d53..65ee4bfcc 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientConnectionRelease.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientConnectionRelease.java @@ -45,7 +45,7 @@ public class ClientConnectionRelease { public final static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try { - HttpGet httpget = new HttpGet("http://localhost/"); + HttpGet httpget = new HttpGet("http://httpbin.org/get"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientCustomContext.java b/httpclient/src/examples/org/apache/http/examples/client/ClientCustomContext.java index 19757624c..a3d14b465 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientCustomContext.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientCustomContext.java @@ -56,7 +56,7 @@ public class ClientCustomContext { // Bind custom cookie store to the local context localContext.setCookieStore(cookieStore); - HttpGet httpget = new HttpGet("http://localhost/"); + HttpGet httpget = new HttpGet("http://httpbin.org/cookies"); System.out.println("Executing request " + httpget.getRequestLine()); // Pass local context as a parameter diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientCustomPublicSuffixList.java b/httpclient/src/examples/org/apache/http/examples/client/ClientCustomPublicSuffixList.java index 0246caf59..5f52cd8b8 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientCustomPublicSuffixList.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientCustomPublicSuffixList.java @@ -73,7 +73,7 @@ public class ClientCustomPublicSuffixList { .build(); try { - HttpGet httpget = new HttpGet("https://remotehost/"); + HttpGet httpget = new HttpGet("https://httpbin.org/"); System.out.println("executing request " + httpget.getRequestLine()); diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientCustomSSL.java b/httpclient/src/examples/org/apache/http/examples/client/ClientCustomSSL.java index eb162873a..fbcf71b16 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientCustomSSL.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientCustomSSL.java @@ -63,9 +63,9 @@ public class ClientCustomSSL { .build(); try { - HttpGet httpget = new HttpGet("https://localhost/"); + HttpGet httpget = new HttpGet("https://httpbin.org/"); - System.out.println("executing request " + httpget.getRequestLine()); + System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientEvictExpiredConnections.java b/httpclient/src/examples/org/apache/http/examples/client/ClientEvictExpiredConnections.java index b349709ac..2c788ac69 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientEvictExpiredConnections.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientEvictExpiredConnections.java @@ -68,7 +68,7 @@ public class ClientEvictExpiredConnections { try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); - EntityUtils.consume(response.getEntity()); + System.out.println(EntityUtils.toString(response.getEntity())); } finally { response.close(); } diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java b/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java index e2740db32..33cc2ba04 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java @@ -45,7 +45,7 @@ public class ClientExecuteProxy { public static void main(String[] args)throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try { - HttpHost target = new HttpHost("localhost", 443, "https"); + HttpHost target = new HttpHost("httpbin.org", 443, "https"); HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http"); RequestConfig config = RequestConfig.custom() @@ -60,7 +60,7 @@ public class ClientExecuteProxy { try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); - EntityUtils.consume(response.getEntity()); + System.out.println(EntityUtils.toString(response.getEntity())); } finally { response.close(); } diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java b/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java index 3cf62d768..04ec10ccc 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java @@ -67,7 +67,7 @@ public class ClientExecuteSOCKS { HttpClientContext context = HttpClientContext.create(); context.setAttribute("socks.address", socksaddr); - HttpHost target = new HttpHost("localhost", 80, "http"); + HttpHost target = new HttpHost("httpbin.org", 80, "http"); HttpGet request = new HttpGet("/"); System.out.println("Executing request " + request + " to " + target + " via SOCKS proxy " + socksaddr); diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java b/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java index b0986cd6d..d43b35c7b 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java @@ -52,11 +52,11 @@ import org.apache.http.util.EntityUtils; public class ClientPreemptiveBasicAuthentication { public static void main(String[] args) throws Exception { - HttpHost target = new HttpHost("localhost", 80, "http"); + HttpHost target = new HttpHost("httpbin.org", 80, "http"); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope(target.getHostName(), target.getPort()), - new UsernamePasswordCredentials("username", "password")); + new UsernamePasswordCredentials("user", "passwd")); CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credsProvider).build(); try { @@ -72,7 +72,7 @@ public class ClientPreemptiveBasicAuthentication { HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); - HttpGet httpget = new HttpGet("/"); + HttpGet httpget = new HttpGet("http://httpbin.org/hidden-basic-auth/user/passwd"); System.out.println("Executing request " + httpget.getRequestLine() + " to target " + target); for (int i = 0; i < 3; i++) { @@ -80,7 +80,7 @@ public class ClientPreemptiveBasicAuthentication { try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); - EntityUtils.consume(response.getEntity()); + System.out.println(EntityUtils.toString(response.getEntity())); } finally { response.close(); } diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java b/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java index fd2e1182a..0bec3e95d 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java @@ -53,11 +53,11 @@ import org.apache.http.util.EntityUtils; public class ClientPreemptiveDigestAuthentication { public static void main(String[] args) throws Exception { - HttpHost target = new HttpHost("localhost", 80, "http"); + HttpHost target = new HttpHost("httpbin.org", 80, "http"); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope(target.getHostName(), target.getPort()), - new UsernamePasswordCredentials("username", "password")); + new UsernamePasswordCredentials("user", "passwd")); CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credsProvider) .build(); @@ -78,7 +78,7 @@ public class ClientPreemptiveDigestAuthentication { HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); - HttpGet httpget = new HttpGet("/"); + HttpGet httpget = new HttpGet("http://httpbin.org/digest-auth/auth/user/passwd"); System.out.println("Executing request " + httpget.getRequestLine() + " to target " + target); for (int i = 0; i < 3; i++) { @@ -86,7 +86,7 @@ public class ClientPreemptiveDigestAuthentication { try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); - EntityUtils.consume(response.getEntity()); + System.out.println(EntityUtils.toString(response.getEntity())); } finally { response.close(); } diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java b/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java index d4431f148..a3e83b541 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java @@ -47,18 +47,21 @@ public class ClientProxyAuthentication { public static void main(String[] args) throws Exception { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( - new AuthScope("localhost", 8080), - new UsernamePasswordCredentials("username", "password")); + new AuthScope("localhost", 8888), + new UsernamePasswordCredentials("squid", "squid")); + credsProvider.setCredentials( + new AuthScope("httpbin.org", 80), + new UsernamePasswordCredentials("user", "passwd")); CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credsProvider).build(); try { - HttpHost target = new HttpHost("www.verisign.com", 443, "https"); - HttpHost proxy = new HttpHost("localhost", 8080); + HttpHost target = new HttpHost("httpbin.org", 80, "http"); + HttpHost proxy = new HttpHost("localhost", 8888); RequestConfig config = RequestConfig.custom() .setProxy(proxy) .build(); - HttpGet httpget = new HttpGet("/"); + HttpGet httpget = new HttpGet("/basic-auth/user/passwd"); httpget.setConfig(config); System.out.println("Executing request " + httpget.getRequestLine() + " to " + target + " via " + proxy); @@ -67,7 +70,7 @@ public class ClientProxyAuthentication { try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); - EntityUtils.consume(response.getEntity()); + System.out.println(EntityUtils.toString(response.getEntity())); } finally { response.close(); } diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java b/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java index e9f9740b0..41328185a 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java @@ -64,7 +64,7 @@ public class ClientWithRequestFuture { }; // Simple request ... - HttpGet request1 = new HttpGet("http://google.com"); + HttpGet request1 = new HttpGet("http://httpbin.org/get"); HttpRequestFutureTask futureTask1 = requestExecService.execute(request1, HttpClientContext.create(), handler); Boolean wasItOk1 = futureTask1.get(); @@ -72,7 +72,7 @@ public class ClientWithRequestFuture { // Cancel a request try { - HttpGet request2 = new HttpGet("http://google.com"); + HttpGet request2 = new HttpGet("http://httpbin.org/get"); HttpRequestFutureTask futureTask2 = requestExecService.execute(request2, HttpClientContext.create(), handler); futureTask2.cancel(true); @@ -83,7 +83,7 @@ public class ClientWithRequestFuture { } // Request with a timeout - HttpGet request3 = new HttpGet("http://google.com"); + HttpGet request3 = new HttpGet("http://httpbin.org/get"); HttpRequestFutureTask futureTask3 = requestExecService.execute(request3, HttpClientContext.create(), handler); Boolean wasItOk3 = futureTask3.get(10, TimeUnit.SECONDS); @@ -107,7 +107,7 @@ public class ClientWithRequestFuture { }; // Simple request with a callback - HttpGet request4 = new HttpGet("http://google.com"); + HttpGet request4 = new HttpGet("http://httpbin.org/get"); // using a null HttpContext here since it is optional // the callback will be called when the task completes, fails, or is cancelled HttpRequestFutureTask futureTask4 = requestExecService.execute(request4, diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientWithResponseHandler.java b/httpclient/src/examples/org/apache/http/examples/client/ClientWithResponseHandler.java index 401fdc99f..ec58d589b 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientWithResponseHandler.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientWithResponseHandler.java @@ -47,7 +47,7 @@ public class ClientWithResponseHandler { public final static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try { - HttpGet httpget = new HttpGet("http://localhost/"); + HttpGet httpget = new HttpGet("http://httpbin.org/"); System.out.println("Executing request " + httpget.getRequestLine()); diff --git a/httpclient/src/examples/org/apache/http/examples/client/QuickStart.java b/httpclient/src/examples/org/apache/http/examples/client/QuickStart.java index dd5863adf..cf5fed1c8 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/QuickStart.java +++ b/httpclient/src/examples/org/apache/http/examples/client/QuickStart.java @@ -45,7 +45,7 @@ public class QuickStart { public static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try { - HttpGet httpGet = new HttpGet("http://targethost/homepage"); + HttpGet httpGet = new HttpGet("http://httpbin.org/get"); CloseableHttpResponse response1 = httpclient.execute(httpGet); // The underlying HTTP connection is still held by the response object // to allow the response content to be streamed directly from the network socket. @@ -64,7 +64,7 @@ public class QuickStart { response1.close(); } - HttpPost httpPost = new HttpPost("http://targethost/login"); + HttpPost httpPost = new HttpPost("http://httpbin.org/post"); List nvps = new ArrayList (); nvps.add(new BasicNameValuePair("username", "vip")); nvps.add(new BasicNameValuePair("password", "secret")); diff --git a/httpclient/src/test/resources/commons-logging.properties b/httpclient/src/test/resources/commons-logging.properties index 2fa1b3b72..831ac3669 100644 --- a/httpclient/src/test/resources/commons-logging.properties +++ b/httpclient/src/test/resources/commons-logging.properties @@ -23,4 +23,4 @@ # . # Disable logging for unit tests -org.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog +# org.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog