Return-Path: Delivered-To: apmail-hc-commits-archive@www.apache.org Received: (qmail 36446 invoked from network); 13 Oct 2009 15:39:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 Oct 2009 15:39:22 -0000 Received: (qmail 96947 invoked by uid 500); 13 Oct 2009 15:39:22 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 96914 invoked by uid 500); 13 Oct 2009 15:39:22 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 96905 invoked by uid 99); 13 Oct 2009 15:39:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Oct 2009 15:39:22 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Oct 2009 15:39:19 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DDE6723888EA; Tue, 13 Oct 2009 15:38:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r824810 - in /httpcomponents/httpclient/trunk/httpclient/src: examples/org/apache/http/examples/conn/ main/java/org/apache/http/impl/client/ test/java/org/apache/http/localserver/ Date: Tue, 13 Oct 2009 15:38:58 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091013153858.DDE6723888EA@eris.apache.org> Author: olegk Date: Tue Oct 13 15:38:57 2009 New Revision: 824810 URL: http://svn.apache.org/viewvc?rev=824810&view=rev Log: HTTPCLIENT-824: Use synchronized SyncBasicHttpParams instead of non-synchronized BasicHttpParams where HttpParams can be accessed simultaneously by multiple threads Modified: httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/conn/ManagerConnectDirect.java httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/conn/ManagerConnectProxy.java httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/conn/OperatorConnectDirect.java httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/conn/OperatorConnectProxy.java httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/LocalTestServer.java httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java Modified: httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/conn/ManagerConnectDirect.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/conn/ManagerConnectDirect.java?rev=824810&r1=824809&r2=824810&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/conn/ManagerConnectDirect.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/conn/ManagerConnectDirect.java Tue Oct 13 15:38:57 2009 @@ -27,7 +27,6 @@ package org.apache.http.examples.conn; - import org.apache.http.Header; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; @@ -43,14 +42,12 @@ import org.apache.http.conn.ManagedClientConnection; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; import org.apache.http.message.BasicHttpRequest; -import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpParams; import org.apache.http.params.HttpProtocolParams; +import org.apache.http.params.SyncBasicHttpParams; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.BasicHttpContext; - - /** * How to open a direct connection using * {@link ClientConnectionManager ClientConnectionManager}. @@ -58,41 +55,38 @@ * The subsequent message exchange in this example should not * be used as a template. * - * - * * @since 4.0 */ public class ManagerConnectDirect { /** - * 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 final static void main(String[] args) throws Exception { - final HttpHost target = new HttpHost("jakarta.apache.org", 80, "http"); + HttpHost target = new HttpHost("www.apache.org", 80, "http"); - setup(); // some general setup + // Register the "http" protocol scheme, it is required + // by the default operator to look up socket factories. + SchemeRegistry supportedSchemes = new SchemeRegistry(); + SocketFactory sf = PlainSocketFactory.getSocketFactory(); + supportedSchemes.register(new Scheme("http", sf, 80)); - ClientConnectionManager clcm = createManager(); + // Prepare parameters. + // Since this example doesn't use the full core framework, + // only few parameters are actually required. + HttpParams params = new SyncBasicHttpParams(); + HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); + HttpProtocolParams.setUseExpectContinue(params, false); + + ClientConnectionManager clcm = new ThreadSafeClientConnManager(supportedSchemes); - HttpRequest req = createRequest(target); - HttpContext ctx = createContext(); + HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1); + req.addHeader("Host", target.getHostName()); + + HttpContext ctx = new BasicHttpContext(); System.out.println("preparing route to " + target); HttpRoute route = new HttpRoute @@ -103,7 +97,7 @@ ManagedClientConnection conn = connRequest.getConnection(0, null); try { System.out.println("opening connection"); - conn.open(route, ctx, getParams()); + conn.open(route, ctx, params); System.out.println("sending request"); conn.sendRequestHeader(req); @@ -130,9 +124,9 @@ System.out.println("shutting down connection"); try { conn.shutdown(); - } catch (Exception x) { + } catch (Exception ex) { System.out.println("problem during shutdown"); - x.printStackTrace(System.out); + ex.printStackTrace(); } } @@ -140,73 +134,7 @@ clcm.releaseConnection(conn, -1, null); } - } // main - - - private final static ClientConnectionManager createManager() { - - return new ThreadSafeClientConnManager(supportedSchemes); - } - - - /** - * Performs general setup. - * This should be called only once. - */ - private final static void setup() { - - // Register the "http" protocol scheme, it is required - // by the default operator to look up socket factories. - supportedSchemes = new SchemeRegistry(); - SocketFactory sf = PlainSocketFactory.getSocketFactory(); - supportedSchemes.register(new Scheme("http", sf, 80)); - - // Prepare parameters. - // Since this example doesn't use the full core framework, - // only few parameters are actually required. - HttpParams params = new BasicHttpParams(); - HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); - HttpProtocolParams.setUseExpectContinue(params, false); - defaultParameters = params; - - } // setup - - - private final static HttpParams getParams() { - return defaultParameters; - } - - - /** - * Creates a request to execute in this example. - * In a real application, request interceptors should be used - * to add the required headers. - * - * @param target the target server for the request - * - * @return a request without an entity - */ - private final static HttpRequest createRequest(HttpHost target) { - - HttpRequest req = new BasicHttpRequest - ("OPTIONS", "*", HttpVersion.HTTP_1_1); - - req.addHeader("Host", target.getHostName()); - - return req; - } - - - /** - * Creates a context for executing a request. - * Since this example doesn't really use the execution framework, - * the context can be left empty. - * - * @return a new, empty context - */ - private final static HttpContext createContext() { - return new BasicHttpContext(null); } -} // class ManagerConnectDirect +} Modified: httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/conn/ManagerConnectProxy.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/conn/ManagerConnectProxy.java?rev=824810&r1=824809&r2=824810&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/conn/ManagerConnectProxy.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/conn/ManagerConnectProxy.java Tue Oct 13 15:38:57 2009 @@ -27,7 +27,6 @@ package org.apache.http.examples.conn; - import org.apache.http.Header; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; @@ -44,14 +43,12 @@ import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; import org.apache.http.message.BasicHttpRequest; -import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpParams; import org.apache.http.params.HttpProtocolParams; +import org.apache.http.params.SyncBasicHttpParams; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.BasicHttpContext; - - /** * How to open a secure connection through a proxy using * {@link ClientConnectionManager ClientConnectionManager}. @@ -59,45 +56,42 @@ * The message exchange, both subsequently and for tunnelling, * should not be used as a template. * - * - * * @since 4.0 */ public class ManagerConnectProxy { /** - * 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 final 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", 8666, "http"); - setup(); // some general setup + // Register the "http" and "https" protocol schemes, they are + // required by the default operator to look up socket factories. + SchemeRegistry supportedSchemes = new SchemeRegistry(); + SocketFactory sf = PlainSocketFactory.getSocketFactory(); + supportedSchemes.register(new Scheme("http", sf, 80)); + sf = SSLSocketFactory.getSocketFactory(); + supportedSchemes.register(new Scheme("https", sf, 80)); - ClientConnectionManager clcm = createManager(); + // Prepare parameters. + // Since this example doesn't use the full core framework, + // only few parameters are actually required. + HttpParams params = new SyncBasicHttpParams(); + HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); + HttpProtocolParams.setUseExpectContinue(params, false); + + ClientConnectionManager clcm = new ThreadSafeClientConnManager(supportedSchemes); + + HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1); + req.addHeader("Host", target.getHostName()); - HttpRequest req = createRequest(target); - HttpContext ctx = createContext(); + HttpContext ctx = new BasicHttpContext(); System.out.println("preparing route to " + target + " via " + proxy); HttpRoute route = new HttpRoute @@ -109,9 +103,12 @@ ManagedClientConnection conn = connRequest.getConnection(0, null); try { System.out.println("opening connection"); - conn.open(route, ctx, getParams()); + conn.open(route, ctx, params); - HttpRequest connect = createConnect(target); + String authority = target.getHostName() + ":" + target.getPort(); + HttpRequest connect = new BasicHttpRequest("CONNECT", authority, HttpVersion.HTTP_1_1); + connect.addHeader("Host", authority); + System.out.println("opening tunnel to " + target); conn.sendRequestHeader(connect); // there is no request entity @@ -120,7 +117,11 @@ System.out.println("receiving confirmation for tunnel"); HttpResponse connected = conn.receiveResponseHeader(); System.out.println("----------------------------------------"); - printResponseHeader(connected); + System.out.println(connected.getStatusLine()); + Header[] headers = connected.getAllHeaders(); + for (int i = 0; i < headers.length; i++) { + System.out.println(headers[i]); + } System.out.println("----------------------------------------"); int status = connected.getStatusLine().getStatusCode(); if ((status < 200) || (status > 299)) { @@ -130,10 +131,10 @@ System.out.println("receiving response body (ignored)"); conn.receiveResponseEntity(connected); - conn.tunnelTarget(false, getParams()); + conn.tunnelTarget(false, params); System.out.println("layering secure connection"); - conn.layerProtocol(ctx, getParams()); + conn.layerProtocol(ctx, params); // finally we have the secure connection and can send the request @@ -146,7 +147,11 @@ HttpResponse rsp = conn.receiveResponseHeader(); System.out.println("----------------------------------------"); - printResponseHeader(rsp); + System.out.println(rsp.getStatusLine()); + headers = rsp.getAllHeaders(); + for (int i = 0; i < headers.length; i++) { + System.out.println(headers[i]); + } System.out.println("----------------------------------------"); System.out.println("closing connection"); @@ -158,9 +163,9 @@ System.out.println("shutting down connection"); try { conn.shutdown(); - } catch (Exception x) { + } catch (Exception ex) { System.out.println("problem during shutdown"); - x.printStackTrace(System.out); + ex.printStackTrace(); } } @@ -168,108 +173,7 @@ clcm.releaseConnection(conn, -1, null); } - } // main - - - private final static ClientConnectionManager createManager() { - - return new ThreadSafeClientConnManager(supportedSchemes); - } - - - /** - * Performs general setup. - * This should be called only once. - */ - private final static void setup() { - - // Register the "http" and "https" protocol schemes, they are - // required by the default operator to look up socket factories. - supportedSchemes = new SchemeRegistry(); - SocketFactory sf = PlainSocketFactory.getSocketFactory(); - supportedSchemes.register(new Scheme("http", sf, 80)); - sf = SSLSocketFactory.getSocketFactory(); - supportedSchemes.register(new Scheme("https", sf, 80)); - - // Prepare parameters. - // Since this example doesn't use the full core framework, - // only few parameters are actually required. - HttpParams params = new BasicHttpParams(); - HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); - HttpProtocolParams.setUseExpectContinue(params, false); - defaultParameters = params; - - } // setup - - - private final static HttpParams getParams() { - return defaultParameters; - } - - - /** - * Creates a request to tunnel a connection. - * In a real application, request interceptors should be used - * to add the required headers. - * - * @param target the target server for the tunnel - * - * @return a CONNECT request without an entity - */ - private final static HttpRequest createConnect(HttpHost target) { - - // see RFC 2817, section 5.2 - final String authority = target.getHostName()+":"+target.getPort(); - - HttpRequest req = new BasicHttpRequest - ("CONNECT", authority, HttpVersion.HTTP_1_1); - - req.addHeader("Host", authority); - - return req; - } - - - /** - * Creates a request to execute in this example. - * In a real application, request interceptors should be used - * to add the required headers. - * - * @param target the target server for the request - * - * @return a request without an entity - */ - private final static HttpRequest createRequest(HttpHost target) { - - HttpRequest req = new BasicHttpRequest - ("OPTIONS", "*", HttpVersion.HTTP_1_1); - - req.addHeader("Host", target.getHostName()); - - return req; - } - - - /** - * Creates a context for executing a request. - * Since this example doesn't really use the execution framework, - * the context can be left empty. - * - * @return a new, empty context - */ - private final static HttpContext createContext() { - return new BasicHttpContext(null); - } - - - private final static void printResponseHeader(HttpResponse rsp) { - - System.out.println(rsp.getStatusLine()); - Header[] headers = rsp.getAllHeaders(); - for (int i=0; iElementalHttpServer example in HttpCore. - * - * - * - * */ public class LocalTestServer { @@ -178,7 +174,7 @@ * @return default parameters */ protected HttpParams newDefaultParams() { - HttpParams params = new BasicHttpParams(); + HttpParams params = new SyncBasicHttpParams(); params .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000) Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java?rev=824810&r1=824809&r2=824810&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java Tue Oct 13 15:38:57 2009 @@ -36,16 +36,15 @@ import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.scheme.SocketFactory; import org.apache.http.impl.DefaultHttpClientConnection; -import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpParams; import org.apache.http.params.HttpProtocolParams; +import org.apache.http.params.SyncBasicHttpParams; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.BasicHttpProcessor; import org.apache.http.protocol.HttpRequestExecutor; import org.apache.http.protocol.RequestConnControl; import org.apache.http.protocol.RequestContent; - /** * Base class for tests using {@link LocalTestServer LocalTestServer}. * Note that the test server will be {@link #setUp set up} before each @@ -104,7 +103,7 @@ protected void setUp() throws Exception { if (defaultParams == null) { - defaultParams = new BasicHttpParams(); + defaultParams = new SyncBasicHttpParams(); HttpProtocolParams.setVersion (defaultParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset