Return-Path: Delivered-To: apmail-jakarta-httpclient-commits-archive@www.apache.org Received: (qmail 6000 invoked from network); 6 Feb 2006 20:30:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Feb 2006 20:30:31 -0000 Received: (qmail 46158 invoked by uid 500); 6 Feb 2006 20:30:30 -0000 Mailing-List: contact httpclient-commits-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: httpclient-dev@jakarta.apache.org Delivered-To: mailing list httpclient-commits@jakarta.apache.org Received: (qmail 46147 invoked by uid 99); 6 Feb 2006 20:30:29 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Feb 2006 12:30:29 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 06 Feb 2006 12:30:26 -0800 Received: (qmail 5794 invoked by uid 65534); 6 Feb 2006 20:30:06 -0000 Message-ID: <20060206203006.5793.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r375356 [1/2] - in /jakarta/httpcomponents/trunk/http-async: ./ src/ src/examples/ src/examples/org/ src/examples/org/apache/ src/examples/org/apache/http/ src/examples/org/apache/http/examples/ src/java/ src/java/org/ src/java/org/apache/ ... Date: Mon, 06 Feb 2006 20:30:01 -0000 To: httpclient-commits@jakarta.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.6 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: olegk Date: Mon Feb 6 12:29:56 2006 New Revision: 375356 URL: http://svn.apache.org/viewcvs?rev=375356&view=rev Log: HttpAsync (initial import). Contributed by Roland Weber Added: jakarta/httpcomponents/trunk/http-async/ jakarta/httpcomponents/trunk/http-async/LICENSE.txt (with props) jakarta/httpcomponents/trunk/http-async/build.xml (with props) jakarta/httpcomponents/trunk/http-async/checkstyle.xml (with props) jakarta/httpcomponents/trunk/http-async/license.regexp jakarta/httpcomponents/trunk/http-async/project.properties (with props) jakarta/httpcomponents/trunk/http-async/project.xml (with props) jakarta/httpcomponents/trunk/http-async/src/ jakarta/httpcomponents/trunk/http-async/src/examples/ jakarta/httpcomponents/trunk/http-async/src/examples/org/ jakarta/httpcomponents/trunk/http-async/src/examples/org/apache/ jakarta/httpcomponents/trunk/http-async/src/examples/org/apache/http/ jakarta/httpcomponents/trunk/http-async/src/examples/org/apache/http/examples/ jakarta/httpcomponents/trunk/http-async/src/examples/org/apache/http/examples/ElementalAsyncGet.java (with props) jakarta/httpcomponents/trunk/http-async/src/java/ jakarta/httpcomponents/trunk/http-async/src/java/org/ jakarta/httpcomponents/trunk/http-async/src/java/org/apache/ jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/ jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/ jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpDispatcher.java (with props) jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpHandle.java (with props) jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AsyncHttpProcessor.java (with props) jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpDispatcher.java (with props) jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpHandle.java (with props) jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/impl/ jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java (with props) jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/impl/SimpleHttpHandle.java (with props) jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/impl/package.html (with props) jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/package.html (with props) jakarta/httpcomponents/trunk/http-async/src/test/ jakarta/httpcomponents/trunk/http-async/src/test/org/ jakarta/httpcomponents/trunk/http-async/src/test/org/apache/ jakarta/httpcomponents/trunk/http-async/src/test/org/apache/http/ Added: jakarta/httpcomponents/trunk/http-async/LICENSE.txt URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-async/LICENSE.txt?rev=375356&view=auto ============================================================================== --- jakarta/httpcomponents/trunk/http-async/LICENSE.txt (added) +++ jakarta/httpcomponents/trunk/http-async/LICENSE.txt Mon Feb 6 12:29:56 2006 @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS \ No newline at end of file Propchange: jakarta/httpcomponents/trunk/http-async/LICENSE.txt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/trunk/http-async/LICENSE.txt ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/trunk/http-async/LICENSE.txt ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/httpcomponents/trunk/http-async/build.xml URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-async/build.xml?rev=375356&view=auto ============================================================================== --- jakarta/httpcomponents/trunk/http-async/build.xml (added) +++ jakarta/httpcomponents/trunk/http-async/build.xml Mon Feb 6 12:29:56 2006 @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Propchange: jakarta/httpcomponents/trunk/http-async/build.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/trunk/http-async/build.xml ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/trunk/http-async/build.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: jakarta/httpcomponents/trunk/http-async/checkstyle.xml URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-async/checkstyle.xml?rev=375356&view=auto ============================================================================== --- jakarta/httpcomponents/trunk/http-async/checkstyle.xml (added) +++ jakarta/httpcomponents/trunk/http-async/checkstyle.xml Mon Feb 6 12:29:56 2006 @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Propchange: jakarta/httpcomponents/trunk/http-async/checkstyle.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/trunk/http-async/checkstyle.xml ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/trunk/http-async/checkstyle.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: jakarta/httpcomponents/trunk/http-async/license.regexp URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-async/license.regexp?rev=375356&view=auto ============================================================================== --- jakarta/httpcomponents/trunk/http-async/license.regexp (added) +++ jakarta/httpcomponents/trunk/http-async/license.regexp Mon Feb 6 12:29:56 2006 @@ -0,0 +1,28 @@ +/\* + \* \$Header: .* + \* \$Revision: .* + \* \$Date: .* + \* + \* ==================================================================== + \* + \* Copyright (2004|[0-9]{4}\-2004) The Apache Software Foundation + \* + \* Licensed under the Apache License, Version 2.0 \(the "License"\); + \* you may not use this file except in compliance with the License. + \* You may obtain a copy of the License at + \* + \* http://www.apache.org/licenses/LICENSE-2.0 + \* + \* Unless required by applicable law or agreed to in writing, software + \* distributed under the License is distributed on an "AS IS" BASIS, + \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + \* See the License for the specific language governing permissions and + \* limitations under the License. + \* ==================================================================== + \* + \* This software consists of voluntary contributions made by many + \* individuals on behalf of the Apache Software Foundation. For more + \* information on the Apache Software Foundation, please see + \* . + \* + \*/ Added: jakarta/httpcomponents/trunk/http-async/project.properties URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-async/project.properties?rev=375356&view=auto ============================================================================== --- jakarta/httpcomponents/trunk/http-async/project.properties (added) +++ jakarta/httpcomponents/trunk/http-async/project.properties Mon Feb 6 12:29:56 2006 @@ -0,0 +1,14 @@ +maven.xdoc.jsl=../../commons-build/commons-site.jsl +maven.xdoc.date=left +maven.xdoc.version=${pom.currentVersion} +maven.checkstyle.properties=checkstyle.xml +maven.checkstyle.includes=**/*.java +maven.checkstyle.excludes=**/*.html +maven.javadoc.links=http://java.sun.com/j2se/1.4.1/docs/api/, http://jakarta.apache.org/commons/logging/apidocs/ +maven.changelog.factory=org.apache.maven.svnlib.SvnChangeLogFactory +maven.repo.list=asf +maven.repo.asf=scp://people.apache.org +maven.repo.asf.directory=/www/www.apache.org/dist/java-repository +maven.repo.asf.username=${maven.username} +maven.repo.asf.compress=true +maven.repo.asf.group=jakarta \ No newline at end of file Propchange: jakarta/httpcomponents/trunk/http-async/project.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/trunk/http-async/project.properties ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/trunk/http-async/project.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/httpcomponents/trunk/http-async/project.xml URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-async/project.xml?rev=375356&view=auto ============================================================================== --- jakarta/httpcomponents/trunk/http-async/project.xml (added) +++ jakarta/httpcomponents/trunk/http-async/project.xml Mon Feb 6 12:29:56 2006 @@ -0,0 +1,95 @@ + + + + 3 + http-async + Jakarta HttpComponents Asynchronous + 4.0 + + + Apache Software Foundation + http://www.apache.org/ + http://maven.apache.org/images/jakarta-logo-blue.gif + + + + 2006 + org.apache.http.async + http://jakarta.apache.org/images/jakarta-logo.gif + Components to send HTTP requests asynchronously and handle responses as they arrive. + Components to use HTTP asynchronously. + http://jakarta.apache.org/commons/httpclient/ + + people.apache.org + /www/jakarta.apache.org/httpclient/ + + + scm:svn:http://svn.apache.org/repos/asf/jakarta/httpclient/trunk/${pom.artifactId} + http://svn.apache.org/viewcvs.cgi/jakarta/httpclient/trunk/${pom.artifactId} + + + + + + + + + + + Oleg Kalnichevski + olegk + olegk -at- apache.org + + Java Developer + + + + + + + Roland Weber + rolweber + http-async -at- dubioso.net + + Java Developer + + + + + + + Apache License + http://www.apache.org/licenses/LICENSE-2.0 + repo + + + + + + + httpclient-dev@jakarta.apache.org + src/java + src/test + + + **/TestAll.java + + + + Propchange: jakarta/httpcomponents/trunk/http-async/project.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/trunk/http-async/project.xml ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/trunk/http-async/project.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: jakarta/httpcomponents/trunk/http-async/src/examples/org/apache/http/examples/ElementalAsyncGet.java URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-async/src/examples/org/apache/http/examples/ElementalAsyncGet.java?rev=375356&view=auto ============================================================================== --- jakarta/httpcomponents/trunk/http-async/src/examples/org/apache/http/examples/ElementalAsyncGet.java (added) +++ jakarta/httpcomponents/trunk/http-async/src/examples/org/apache/http/examples/ElementalAsyncGet.java Mon Feb 6 12:29:56 2006 @@ -0,0 +1,179 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.examples; + + +import org.apache.http.HttpClientConnection; +import org.apache.http.HttpHost; +import org.apache.http.HttpResponse; +import org.apache.http.HttpVersion; +import org.apache.http.Scheme; +import org.apache.http.ConnectionReuseStrategy; +import org.apache.http.impl.DefaultConnectionReuseStrategy; +import org.apache.http.impl.DefaultHttpClientConnection; +import org.apache.http.impl.DefaultHttpParams; +import org.apache.http.impl.io.PlainSocketFactory; +import org.apache.http.io.SocketFactory; +import org.apache.http.message.HttpGet; +import org.apache.http.params.HttpParams; +import org.apache.http.params.HttpProtocolParams; +import org.apache.http.async.HttpDispatcher; +import org.apache.http.async.HttpHandle; +import org.apache.http.async.AsyncHttpProcessor; +import org.apache.http.async.impl.SimpleHttpDispatcher; +import org.apache.http.protocol.RequestConnControl; +import org.apache.http.protocol.RequestContent; +import org.apache.http.protocol.RequestTargetHost; +import org.apache.http.protocol.RequestUserAgent; +import org.apache.http.util.EntityUtils; + + + +/** + * Example for using an asynchronous {@link HttpDispatcher dispatcher}. + * + * @version $Revision$ + */ +public class ElementalAsyncGet { + + /** + * Main entry point to this example. + * + * @param args command line arguments + */ + public static void main(String[] args) throws Exception { + + SocketFactory socketfactory = PlainSocketFactory.getSocketFactory(); + Scheme.registerScheme("http", new Scheme("http", socketfactory, 80)); + + HttpDispatcher dispatcher = createDispatcher(); + System.out.println("dispatcher " + dispatcher + "\n"); + + String[] targets = args; + if ((targets == null) || (targets.length < 1)) { + targets = new String[] { + "/", + "/manual/", + "/somewhere%20in%20pampa" + }; + } + + HttpHost host = new HttpHost("localhost", 80); + HttpHandle[] handles = new HttpHandle[targets.length]; + + for (int i = 0; i < targets.length; i++) { + + HttpGet request = new HttpGet(targets[i]); + System.out.println(">> Request URI: " + + request.getRequestLine().getUri()); + handles[i] = dispatcher.sendRequest(request, host, null); + System.out.println(">> Handle: " + handles[i]); + System.out.println("=============="); + + } // for targets + + System.out.println("\ndispatcher " + dispatcher + "\n"); + + // now pick up the responses + for (int i = 0; i < targets.length; i++) { + + if (handles[i] == null) { + System.out.println("<< No handle for " + targets[i]); + + } else { + // Blocking on a request after dispatching several of them + // is generally dangerous and may lead to deadlocks. With + // the simple dispatcher used here, blocking in order of + // sending is safe. Blocking in any other order is never safe. + + HttpResponse response = handles[i].awaitResponse(); + if (response != null) { + System.out.println + ("<< Response: " + response.getStatusLine()); + System.out.println + (EntityUtils.toString(response.getEntity())); + /* + byte [] data = new byte[100]; + int count = response.getEntity().getContent().read(data); + String s = new String(data, 0, count, "ISO-8859-1"); + System.out.println(s); + */ + } else { + System.out.println("<< Response: null"); + try { + handles[i].checkError(); + } catch (Exception x) { + x.printStackTrace(System.out); + } + } + System.out.println("--------------"); + handles[i].close(); + System.out.println(dispatcher); + System.out.println("=============="); + } + } // for handles + + } // main + + + /** + * Instantiates a dispatcher. + * + * @return the dispatcher + */ + private final static HttpDispatcher createDispatcher() { + + HttpParams params = new DefaultHttpParams(null); + HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); + HttpProtocolParams.setContentCharset(params, "UTF-8"); + HttpProtocolParams.setUserAgent(params, "Jakarta-HttpComponents/1.1"); + HttpProtocolParams.setUseExpectContinue(params, false); + + HttpClientConnection conn = new DefaultHttpClientConnection(); + + AsyncHttpProcessor proc = new AsyncHttpProcessor(); + // Required request interceptors + proc.addInterceptor(new RequestContent()); + proc.addInterceptor(new RequestTargetHost()); + // Recommended request interceptors + proc.addInterceptor(new RequestConnControl()); + proc.addInterceptor(new RequestUserAgent()); + // not supported: proc.addInterceptor(new RequestExpectContinue()); + + ConnectionReuseStrategy crs = new DefaultConnectionReuseStrategy(); + + HttpDispatcher hdp = new SimpleHttpDispatcher(conn, proc, crs, params); + + return hdp; + + } // createDispatcher + + +} // class ElementalAsyncGet Propchange: jakarta/httpcomponents/trunk/http-async/src/examples/org/apache/http/examples/ElementalAsyncGet.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/trunk/http-async/src/examples/org/apache/http/examples/ElementalAsyncGet.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/trunk/http-async/src/examples/org/apache/http/examples/ElementalAsyncGet.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpDispatcher.java URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpDispatcher.java?rev=375356&view=auto ============================================================================== --- jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpDispatcher.java (added) +++ jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpDispatcher.java Mon Feb 6 12:29:56 2006 @@ -0,0 +1,224 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.async; + + +import java.io.IOException; +import java.util.List; +import java.util.LinkedList; +import java.util.Collection; + +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.HttpMutableResponse; +import org.apache.http.HttpHost; +import org.apache.http.HttpClientConnection; +import org.apache.http.HttpException; +import org.apache.http.protocol.HttpContext; +import org.apache.http.params.HttpParams; + + + +/** + * Abstract base for implementations of {@link HttpDispatcher HttpDispatcher}. + * Provides access to protected methods in + * {@link AsyncHttpProcessor AsyncHttpProcessor}. + * + * @version $Revision$ $Date$ + * + * @since 4.0 + */ +public abstract class AbstractHttpDispatcher implements HttpDispatcher { + + + /** + * All handles linked to this dispatcher. + * This is assumed to be used as a set, but declared a collection to + * avoid the overhead of duplicate checking. A set implementation can + * be passed to the constructor if necessary. + */ + protected final Collection linked_handles; + + /** The monitor object for accessing the set of linked handles. */ + protected final Object linked_handle_monitor = + new String("AbstractHttpDispatcher.linked_handle_monitor"); + + + /** + * Initialize this new (abstract) dispatcher. + * + * @param linked the initial linked handles, or + * null to create an empty initial set. + * This can also be used to choose the implementation + * of {@link Collection Collection}. + */ + protected AbstractHttpDispatcher(Collection linked) { + + linked_handles = (linked != null) ? linked : new LinkedList(); + + } // constructor + + + + /** + * Perform postprocessing on a response. + * After postprocessing, the response is ready for the application. + * This method is meant to be called from handles, to perform + * postprocessing in an application thread. + * + * @param handle the calling handle + * @param response the response object to postprocess + * Note that {@link HttpHandle#getResponse handle.getResponse()} + * can not be used here, since it could call this method! + */ + protected abstract void postprocessResponse(AbstractHttpHandle handle, + HttpMutableResponse response) + throws HttpException, IOException + ; + + + /** + * Close a handle. + * + * @param handle the handle to close + * @param abort false if this is a smooth + * {@link HttpHandle#close close}, + * true if it is a hard + * {@link HttpHandle#abort abort} + * + * @throws HttpException in case of a problem + * @throws IOException in case of an IO problem + */ + protected abstract void closeHandle(AbstractHttpHandle handle, + boolean abort) + throws HttpException, IOException + ; + + + /** + * Prepare a request for sending. + * Maps to {@link AsyncHttpProcessor#prepareRequest proc.prepareRequest}. + * + * @param proc the processor to use for preparing + * @param request the request to prepare + * @param target the target host for the request + * @param params the default parameters + * @param context the parent context for sending the request, + * or null to use the default context + * + * @return a new context specific to the request + * + * @throws HttpException if the request can not be prepared + * @throws IOException in case of an IO problem + */ + protected static HttpContext prepareRequest(AsyncHttpProcessor proc, + HttpRequest request, + HttpHost target, + HttpParams params, + HttpContext context) + throws HttpException, IOException { + + return proc.prepareRequest(request, target, params, context); + + } // prepareRequest + + + /** + * Send a request. + * Maps to {@link AsyncHttpProcessor#transmitRequest proc.transmitRequest}. + * + * @param proc the processor to use for transmission + * @param request the request to send, already prepared + * @param context the request specific context returned by + * {@link #prepareRequest prepareRequest} + * when the request was prepared + * @param connection the connection over which to send the request + * + * @throws HttpException in case of a problem + * @throws IOException in case of an IO problem + */ + protected static void transmitRequest(AsyncHttpProcessor proc, + HttpRequest request, + HttpContext context, + HttpClientConnection connection) + throws HttpException, IOException { + + proc.transmitRequest(request, context, connection); + + } // transmitRequest + + + /** + * Wait for and receive a response. + * Maps to {@link AsyncHttpProcessor#obtainResponse proc.obtainResponse}. + * + * @param proc the processor to use for transmission + * @param request the request for which to obtain the response + * @param connection the connection over which the request was sent + * + * @return the response, not yet post-processed + * + * @throws HttpException in case of a problem + * @throws IOException in case of an IO problem + */ + protected static + HttpMutableResponse obtainResponse(AsyncHttpProcessor proc, + HttpRequest request, + HttpClientConnection connection) + throws HttpException, IOException { + + return proc.obtainResponse(request, connection); + + } // obtainResponse + + + /** + * Finish a response. + * Maps to {@link AsyncHttpProcessor#finishResponse proc.finishResponse}. + * + * @param response the response object to finish + * @param context the context obtained from + * {@link #prepareRequest prepareRequest} + * for the matching request + * + * @throws HttpException in case of a problem + * @throws IOException in case of an IO problem + */ + protected static void finishResponse(AsyncHttpProcessor proc, + HttpMutableResponse response, + HttpContext context) + throws HttpException, IOException { + + proc.finishResponse(response, context); + + } // finishResponse + + +} // class AbstractHttpDispatcher Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpDispatcher.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpDispatcher.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpDispatcher.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpHandle.java URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpHandle.java?rev=375356&view=auto ============================================================================== --- jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpHandle.java (added) +++ jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpHandle.java Mon Feb 6 12:29:56 2006 @@ -0,0 +1,243 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.async; + + +import java.io.IOException; + +import org.apache.http.HttpRequest; +import org.apache.http.HttpMutableResponse; +import org.apache.http.HttpHost; +import org.apache.http.HttpException; +import org.apache.http.protocol.HttpContext; + + + +/** + * Base class for implementations of {@link HttpHandle HttpHandle}. + * + * @version $Revision$ $Date$ + * + * @since 4.0 + */ +public abstract class AbstractHttpHandle implements HttpHandle { + + /** The dispatcher which created this handle. */ + protected final AbstractHttpDispatcher http_dispatcher; + + /** The request being dispatched. */ + protected final HttpRequest http_request; + + /** The context for request execution. */ + protected final HttpContext http_context; + + /** The link status for this handle. */ + private boolean is_linked; + + /** The exception indicating an execution problem, if there was one. */ + private Throwable execution_problem; + + + /** + * Create a new handle. + * The new handle is {@link #isLinked linked}. + * + * @param dispatcher the dispatcher creating this handle, + * or null + * @param request the request to be handled + * @param context the context for executing the request + */ + protected AbstractHttpHandle(AbstractHttpDispatcher dispatcher, + HttpRequest request, + HttpContext context) { + if (request == null) + throw new IllegalArgumentException("request must not be null"); + if (context == null) + throw new IllegalArgumentException("context must not be null"); + + http_dispatcher = dispatcher; + http_request = request; + http_context = context; + is_linked = true; + + } // constructor + + + // non-javadoc, see interface HttpHandle + public final HttpRequest getRequest() { + + return http_request; + } + + + // non-javadoc, see interface HttpHandle + public final HttpContext getContext() { + + return http_context; + } + + + /** + * Check whether this handle is still linked to the dispatcher. + * This method needs to be synchronized since it is called by + * background threads to detect {@link HttpHandle#close closed} + * or {@link HttpHandle#abort aborted} requests. + */ + public final synchronized boolean isLinked() { + + return is_linked; + } + + + /** + * Set the linking status of this handle. + * This method is not synchronized, but should only be called by + * synchronized methods in derived classes. It is used to specify + * the value returned by {@link #isLinked isLinked}. + * + * @param linked false if this handle is no longer linked, + * true otherwise + */ + protected final void setLinked(boolean linked) { + + is_linked = linked; + } + + + + // non-javadoc, see interface HttpHandle + public final void checkError() + throws HttpException, IOException { + + if (execution_problem == null) + return; + + if (execution_problem instanceof HttpException) { + throw (HttpException) execution_problem; + + } else if (execution_problem instanceof IOException) { + throw (IOException) execution_problem; + + } else { + HttpException hx = new HttpException + ("problem while executing request"); + hx.initCause(execution_problem); + throw hx; + } + } // checkError + + + /** + * Remember an execution problem. + * This sets the error for which {@link #checkError checkError} is looking. + * + * @param dart the exception indicating the problem, + * or null to unset the problem + */ + protected final void setError(Throwable dart) { + + execution_problem = dart; + + } // setError + + + /** + * Obtain the execution problem. + * + * @return the last exception passed to {@link #setError setError}, + * or null + */ + public final Throwable getError() { + + return execution_problem; + } + + + /** + * Checks the dispatcher. + * Simply returns if the argument is the same as the one + * given to the constructor. + * This does not check whether the handle is {@link #isLinked linked}. + * + * @param dispatcher the dispatcher performing the check, + * or null + * + * @throws IllegalArgumentException + * if this handle was not created for the argument dispatcher + */ + public final void checkDispatcher(HttpDispatcher dispatcher) { + + if (http_dispatcher != dispatcher) + throw new IllegalArgumentException + ("handle used with wrong dispatcher"); + } + + + /** + * Callback to the dispatcher to close this handle. + * Maps to + * {@link AbstractHttpDispatcher#closeHandle http_dispatcher.closeHandle}. + * Does nothing if the dispatcher has not been passed to the constructor. + * + * @param abort true if the handle is closed because of + * a call to {@link HttpHandle#abort abort}, or + * false if it is closed because of + * a call to {@link HttpHandle#close close} + * + * @throws HttpException in case of a problem + * @throws IOException in case of an IO problem + */ + protected final void dispatcherCloseHandle(boolean abort) + throws HttpException, IOException + { + if (http_dispatcher != null) + http_dispatcher.closeHandle(this, abort); + } + + + /** + * Callback to the dispatcher to postprocess the response. + * Maps to {@link AbstractHttpDispatcher#postprocessResponse + * http_dispatcher.postprocessResponse}. + * Does nothing if the dispatcher has not been passed to the constructor. + * + * @param response the response to postprocess + * + * @throws HttpException in case of a problem + * @throws IOException in case of an IO problem + */ + protected final void dispatcherPostprocess(HttpMutableResponse response) + throws HttpException, IOException + { + if (http_dispatcher != null) + http_dispatcher.postprocessResponse(this, response); + } + +} // class AbstractHttpHandle Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpHandle.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpHandle.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AbstractHttpHandle.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AsyncHttpProcessor.java URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AsyncHttpProcessor.java?rev=375356&view=auto ============================================================================== --- jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AsyncHttpProcessor.java (added) +++ jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AsyncHttpProcessor.java Mon Feb 6 12:29:56 2006 @@ -0,0 +1,322 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.async; + + +import java.io.IOException; + +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpMutableRequest; +import org.apache.http.HttpEntityEnclosingRequest; +import org.apache.http.HttpResponse; +import org.apache.http.HttpMutableResponse; +import org.apache.http.HttpClientConnection; +import org.apache.http.HttpStatus; +import org.apache.http.HttpException; +import org.apache.http.protocol.HttpContext; +import org.apache.http.protocol.HttpExecutionContext; +import org.apache.http.protocol.AbstractHttpProcessor; +import org.apache.http.params.HttpParams; +import org.apache.http.params.HttpConnectionParams; + + + +/** + * HTTP processor for asynchronously dispatched requests. + * This is the asynchronous equivalent to + * {@link org.apache.http.protocol.HttpRequestExecutor HttpRequestExecutor}. + * + * + * @version $Revision$ $Date$ + * + * @since 4.0 + */ +public class AsyncHttpProcessor extends AbstractHttpProcessor { + + /** The default (parent) context. */ + private HttpContext default_context; + + + /** + * Create a new HTTP processor with the given default context. + * + * @param context the default context + */ + public AsyncHttpProcessor(HttpContext context) { + + if (context == null) + throw new IllegalArgumentException + ("default context must not be null"); + + default_context = context; + } + + + /** + * Create a new HTTP processor with empty default context. + */ + public AsyncHttpProcessor() { + this(new HttpExecutionContext(null)); + } + + /** + * Obtain the default context. + * + * @return the default context, or null if there is none + */ + public final HttpContext getDefaultContext() { + + return default_context; + } + + + /** + * Prepare a request for sending. + * + * @param request the request to prepare + * @param target the target host for the request + * @param params the default parameters + * @param context the parent context for sending the request, + * or null to use the default context + * + * @return a new context specific to the request + * + * @throws HttpException if the request can not be prepared + * @throws IOException in case of an IO problem + */ + protected HttpContext prepareRequest(HttpRequest request, + HttpHost target, + HttpParams params, + HttpContext context) + throws HttpException, IOException { + + if (request == null) + throw new IllegalArgumentException("request must not be null"); + if (context == null) + context = default_context; + + // see also HttpRequestExecutor.execute(), initial part + + HttpExecutionContext hxc = new HttpExecutionContext(context); + hxc.setAttribute(HttpExecutionContext.HTTP_REQUEST, request); + //@@@ behavior if proxying - set real target or proxy, or both? + hxc.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, target); + + //@@@ Can't set connection in the context, it's not available yet. + //@@@ Is it required for one of the interceptors? + + // link default parameters + request.getParams().setDefaults(params); + + if (request instanceof HttpMutableRequest) + preprocessRequest((HttpMutableRequest) request, hxc); + + return hxc; + + } // prepareRequest + + + /** + * Send a request. + * + * @param request the request to send, already prepared + * @param context the request specific context returned by + * {@link #prepareRequest prepareRequest} + * when the request was prepared + * @param connection the connection over which to send the request + * + * @throws HttpException in case of a problem + * @throws IOException in case of an IO problem + */ + protected void transmitRequest(HttpRequest request, + HttpContext context, + HttpClientConnection connection) + throws HttpException, IOException { + + if (request == null) + throw new IllegalArgumentException("request must not be null"); + if (context == null) + throw new IllegalArgumentException("context must not be null"); + if (connection == null) + throw new IllegalArgumentException("connection must not be null"); + + HttpHost target = (HttpHost) + context.getAttribute(HttpExecutionContext.HTTP_TARGET_HOST); + if (target == null) + throw new IllegalStateException + ("target host missing in request context"); + + // see also HttpRequestExecutor.execute() and .doExecute() + // Retry handling should be implemented by caller, since the retry + // may be triggered by receiving the response, too. + + // make sure the connection is open and points to the target host + HttpParams params = request.getParams(); + if (target.equals(connection.getTargetHost())) { + + // host and port ok, check whether connection needs to be opened + if (HttpConnectionParams.isStaleCheckingEnabled(params)) { + if (connection.isOpen() && connection.isStale()) { + connection.close(); + } + } + if (!connection.isOpen()) { + connection.open(params); + //TODO: Implement secure tunnelling (@@@ HttpRequestExecutor) + } + + } else { + + // wrong target, point connection to target + if (connection.isOpen()) + connection.close(); + connection.setTargetHost(target); + connection.open(params); + + } // if connection points to target else + + + // this is the initial part of HttpRequestExecutor.doExecute, + // minus the handling of expect/continue handshakes + + context.setAttribute(HttpExecutionContext.HTTP_REQ_SENT, + Boolean.FALSE); + + connection.sendRequestHeader(request); + if (request instanceof HttpEntityEnclosingRequest) { + connection.sendRequestEntity((HttpEntityEnclosingRequest) request); + } + connection.flush(); + + context.setAttribute(HttpExecutionContext.HTTP_REQ_SENT, + Boolean.TRUE); + + } // transmitRequest + + + /** + * Wait for and receive a response. + * clarify sematics - will the response body be received? + * + * @param request the request for which to obtain the response + * @param connection the connection over which the request was sent + * + * @return the response, not yet post-processed + * + * @throws HttpException in case of a problem + * @throws IOException in case of an IO problem + */ + protected + HttpMutableResponse obtainResponse(HttpRequest request, + HttpClientConnection connection) + throws HttpException, IOException { + + if (request == null) + throw new IllegalArgumentException("request must not be null"); + if (connection == null) + throw new IllegalArgumentException("connection must not be null"); + + // see HttpRequestExecutor.doExecute, final part + HttpMutableResponse response = null; + int statuscode = 0; + + // skip 1xx responses + while (statuscode < HttpStatus.SC_OK) { + response = connection.receiveResponseHeader(request.getParams()); + + //@@@ does this actually receive, or just wrap the stream? + //@@@ how to make sure we get only a wrapped stream here? + //@@@ don't call receiveResponseEntity here at all? + //@@@ could there be 1xx responses with an entity? check RFC 2616 + if (canResponseHaveBody(request, response)) { + connection.receiveResponseEntity(response); + } + statuscode = response.getStatusLine().getStatusCode(); + + } // while intermediate response + + return response; + + } // obtainResponse + + + /** + * Decide whether a response comes with an entity. + * + * @param request the request responded to + * @param response the response, initialized from headers only + * + * @return true if the response should have an entity, or + * false if it doesn't + */ + //@@@ duplicated from HttpRequestExecutor.canResponseHaveBody + private boolean canResponseHaveBody(final HttpRequest request, + final HttpResponse response) { + if ("HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) { + return false; + } + int status = response.getStatusLine().getStatusCode(); + return status >= HttpStatus.SC_OK + && status != HttpStatus.SC_NO_CONTENT + && status != HttpStatus.SC_NOT_MODIFIED + && status != HttpStatus.SC_RESET_CONTENT; + } + + + /** + * Finish a response. + * This includes post-processing of the response object. + * It does not read the response entity (if any), nor allows + * re-use of the connection over which the response is coming in. + * + * @param response the response object to finish + * @param context the context obtained from + * {@link #prepareRequest prepareRequest} + * for the matching request + * + * @throws HttpException in case of a problem + * @throws IOException in case of an IO problem + */ + protected void finishResponse(HttpMutableResponse response, + HttpContext context) + throws HttpException, IOException { + + if (response == null) + throw new IllegalArgumentException("response must not be null"); + if (context == null) + throw new IllegalArgumentException("context must not be null"); + + postprocessResponse(response, context); + + } // finishResponse + + +} // class AsyncHttpProcessor Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AsyncHttpProcessor.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AsyncHttpProcessor.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/AsyncHttpProcessor.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpDispatcher.java URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpDispatcher.java?rev=375356&view=auto ============================================================================== --- jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpDispatcher.java (added) +++ jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpDispatcher.java Mon Feb 6 12:29:56 2006 @@ -0,0 +1,118 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.async; + + +import java.io.IOException; + +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpException; +import org.apache.http.protocol.HttpContext; + + +/** + * Asynchronous dispatcher for HTTP requests. + * A dispatcher schedules HTTP requests for asynchronous execution. + * It will generate a {@link HttpHandle handle} for each request, + * so that applications can access the responses as they arrive. + *
+ * Dispatchers are thread safe. An application can instantiate one + * dispatcher and use it from multiple threads. + *
+ * A dispatcher typically makes use of some background threads and + * client {@link org.apache.http.HttpClientConnection connections} + * for processing requests and responses. + * It is important to understand that callbacks from the dispatcher + * to the application are executed by shared background threads. + * For proper operation of a dispatcher, applications MUST make sure + * that callbacks return swiftly. Prolonged processing of responses + * MUST be delegated from the callbacks to application threads. + * + * @version $Revision$ $Date$ + * + * @since 4.0 + */ +public interface HttpDispatcher { + + + /** + * Send an HTTP request asynchronously. + * The dispatcher assumes responsibility for the request, which + * will eventually be executed. The returned handle can be used + * to synchronize with the execution, and to access the response. + *

+ * Note: The target argument is preliminary, until + * we've figured out a way to specify target host and an optional proxy. + *

+ * + * @param req the request to dispatch. + * It must not be modified while the responsibility + * remains with the dispatcher. + * @param target the host to which the request should be sent + * @param ctxt the context for dispatching this request, or + * null to use the + * {@link #getDefaultContext default context} + * + * @return the handle for the request + * + * @throws HttpException if the request can not be dispatched + * @throws IOException in case of an IO problem + */ + public HttpHandle sendRequest(HttpRequest req, + HttpHost target, + HttpContext ctxt) + throws HttpException, IOException + ; + + + /** + * Obtain the default context for {@link #sendRequest sending} requests. + * The default context can be modified directly, or it can be cloned to + * add request specific context information. Attributes that affect the + * behaviour of the dispatcher should not be modified directly as long + * as requests are being dispatched. + * + * @return the default context + */ + public HttpContext getDefaultContext() + ; + + + /** + * Aborts all current requests. + * This affects all requests for which the dispatcher still maintains + * a handle. Any exceptions will be reported via the respective handle. + */ + public void abortAll() + ; + + +} // interface HttpDispatcher Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpDispatcher.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpDispatcher.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpDispatcher.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpHandle.java URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpHandle.java?rev=375356&view=auto ============================================================================== --- jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpHandle.java (added) +++ jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpHandle.java Mon Feb 6 12:29:56 2006 @@ -0,0 +1,175 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.async; + + +import java.io.IOException; + +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.HttpException; +import org.apache.http.protocol.HttpContext; + + + +/** + * Represents a {@link HttpDispatcher dispatched} HTTP request. + * + * @version $Revision$ $Date$ + * + * @since 4.0 + */ +public interface HttpHandle { + + + /** + * Obtain the request. + * The request MUST NOT be modified while it is under control + * of the dispatcher. + * + * @return the request to this handle + */ + public HttpRequest getRequest() + ; + + + /** + * Obtain the response for the request, if there is one. + * This method does not block until the response is available. + * Use {@link #awaitResponse awaitResponse} to wait for the response. + * Use {@link #checkError checkError} to check for problems that + * may prevent the response from ever becoming available. + * + * @return the response to the request, or + * null if it is not (yet) available + */ + public HttpResponse getResponse() + ; + + + /** + * Obtain the context for the request. + * The context returned here is usually not the same that was passed to + * {@link HttpDispatcher#sendRequest HttpDispatcher.sendRequest}, + * but the attributes in that context are available in this one, too. + * + * @return the context for executing the request, + * never null + */ + public HttpContext getContext() + ; + + + /** + * Check whether this handle is still linked to the dispatcher. + * A handle is linked from the time it is created, until the + * response has been received in it's entirety, or until + * {@link #close close} is called. + * The link can be broken prematurely by error conditions, or + * by calling {@link #abort abort}. + *
+ * A handle that is not linked will no longer be recognized by + * the dispatcher, but the getters will still work. + * + * @return true if this handle is still linked, + * false otherwise + */ + public boolean isLinked() + ; + + + /** + * Obtain the response for the request. + * This method blocks until the response is available, or until + * there is an {@link #checkError error} condition. + * + * @return the response to the request + * + * @throws HttpException + * if there will be no response, for example because there + * was a problem executing the request + * @throws IOException + * in case of an IO problem + * @throws InterruptedException + * if the thread was interrupted while awaiting the response + */ + public HttpResponse awaitResponse() + throws HttpException, IOException, InterruptedException + ; + + + /** + * Close this handle. + * This indicates that the application is done retrieving the response, + * and the underlying connection can now be used by the dispatcher. + * The application does not have to read the response entity completely + * before closing the handle. + *
+ * After the call, this handle is no longer {@link #isLinked linked}. + * Unlike {@link #abort abort}, this method does not cancel request + * execution. Neither does it prevent connection keep-alive. + * + * @throws HttpException in case of a problem + * @throws IOException in case of an IO problem + */ + public void close() + throws HttpException, IOException + ; + + + /** + * Abort the request execution and {@link #close close} this handle. + * If the request is not yet dispatched, it will be cancelled before + * being sent. If it has been sent but the response is not yet received, + * the connection over which it was sent will be closed before the + * response is received. If the request has already been executed, + * the response is discarded. + *
+ * Note that aborting a request can affect other requests to the + * same host if pipelining is used. They may have to be repeated. + */ + public void abort() + ; + + + /** + * Check for problems during request execution. + * If there is no problem, this method simply returns. + * + * @throws HttpException + * if there was a logical problem executing the request + * @throws IOException + * if there was an IO problem executing the request + */ + public void checkError() + throws HttpException, IOException + ; + +} // interface HttpHandle Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpHandle.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpHandle.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/trunk/http-async/src/java/org/apache/http/async/HttpHandle.java ------------------------------------------------------------------------------ svn:mime-type = text/plain