From 65b8b329eccf731a972d5d82f41ee08755228768 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sat, 28 Feb 2009 12:05:44 +0000 Subject: [PATCH] Cleaned up execute direct and execute via proxy examples git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@748828 13f79535-47bb-0310-9956-ffa450edef68 --- .../examples/client/ClientExecuteDirect.java | 141 ++++------------ .../examples/client/ClientExecuteProxy.java | 151 ++++-------------- 2 files changed, 62 insertions(+), 230 deletions(-) diff --git a/module-client/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java b/module-client/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java index bfe96f0b8..1a021d8e4 100644 --- a/module-client/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java +++ b/module-client/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java @@ -31,7 +31,6 @@ package org.apache.http.examples.client; - import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpHost; @@ -43,7 +42,6 @@ import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; -import org.apache.http.conn.scheme.SocketFactory; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; import org.apache.http.message.BasicHttpRequest; @@ -52,134 +50,53 @@ import org.apache.http.params.HttpParams; import org.apache.http.params.HttpProtocolParams; import org.apache.http.util.EntityUtils; - - /** - * How to send a request directly using {@link HttpClient HttpClient}. - * - * - * - * - * @version $Revision$ - * + * How to send a request directly using {@link HttpClient}. + * * @since 4.0 */ public class ClientExecuteDirect { - /** - * The default parameters. - * Instantiated in {@link #setup setup}. - */ - private static HttpParams defaultParameters = null; + public static void main(String[] args) throws Exception { - /** - * The scheme registry. - * Instantiated in {@link #setup setup}. - */ - private static SchemeRegistry supportedSchemes; + HttpHost target = new HttpHost("www.apache.org", 80, "http"); - - /** - * Main entry point to this example. - * - * @param args ignored - */ - public final static void main(String[] args) - throws Exception { - - final HttpHost target = new HttpHost("issues.apache.org", 80, "http"); - - setup(); // some general setup - - HttpClient client = createHttpClient(); - - HttpRequest req = createRequest(); - - System.out.println("executing request to " + target); - HttpEntity entity = null; - try { - HttpResponse rsp = client.execute(target, req); - entity = rsp.getEntity(); - - System.out.println("----------------------------------------"); - System.out.println(rsp.getStatusLine()); - Header[] headers = rsp.getAllHeaders(); - for (int i=0; i - * @version $Revision$ + * How to send a request via proxy using {@link HttpClient}. * * @since 4.0 */ public class ClientExecuteProxy { - /** - * The default parameters. - * Instantiated in {@link #setup setup}. - */ - private static HttpParams defaultParameters = null; - - /** - * The scheme registry. - * Instantiated in {@link #setup setup}. - */ - private static SchemeRegistry supportedSchemes; - - - /** - * Main entry point to this example. - * - * @param args ignored - */ - public final static void main(String[] args) - throws Exception { + public static void main(String[] args)throws Exception { // make sure to use a proxy that supports CONNECT - final HttpHost target = - new HttpHost("issues.apache.org", 443, "https"); - final HttpHost proxy = - new HttpHost("127.0.0.1", 8666, "http"); + HttpHost target = new HttpHost("issues.apache.org", 443, "https"); + HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http"); - setup(); // some general setup - - HttpClient client = createHttpClient(); - - client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); - - HttpRequest req = createRequest(); - - System.out.println("executing request to " + target + " via " + proxy); - HttpEntity entity = null; - try { - HttpResponse rsp = client.execute(target, req); - entity = rsp.getEntity(); - - System.out.println("----------------------------------------"); - System.out.println(rsp.getStatusLine()); - Header[] headers = rsp.getAllHeaders(); - for (int i=0; i