Return-Path: Delivered-To: apmail-jakarta-httpclient-commits-archive@www.apache.org Received: (qmail 31608 invoked from network); 3 May 2005 20:38:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 May 2005 20:38:28 -0000 Received: (qmail 93502 invoked by uid 500); 3 May 2005 20:40:08 -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 93486 invoked by uid 500); 3 May 2005 20:40:08 -0000 Delivered-To: apmail-jakarta-httpclient-cvs@jakarta.apache.org Received: (qmail 93476 invoked by uid 99); 3 May 2005 20:40:08 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 03 May 2005 13:40:07 -0700 Received: (qmail 31366 invoked by uid 65534); 3 May 2005 20:38:14 -0000 Message-ID: <20050503203814.31364.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r167987 - /jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java Date: Tue, 03 May 2005 20:38:13 -0000 To: httpclient-cvs@jakarta.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: olegk Date: Tue May 3 13:38:13 2005 New Revision: 167987 URL: http://svn.apache.org/viewcvs?rev=3D167987&view=3Drev Log: HTTP request executor demo Added: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examp= les/HttpRequestExecutorDemo.java (with props) Added: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/ex= amples/HttpRequestExecutorDemo.java URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src= /examples/org/apache/http/examples/HttpRequestExecutorDemo.java?rev=3D16798= 7&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examp= les/HttpRequestExecutorDemo.java (added) +++ jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examp= les/HttpRequestExecutorDemo.java Tue May 3 13:38:13 2005 @@ -0,0 +1,95 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * Copyright 1999-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 implie= d=2E + * See the License for the specific language governing permissions and + * limitations under the License. + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * 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.entity.EntityConsumer; +import org.apache.http.executor.HttpRequestExecutor; +import org.apache.http.impl.DefaultHttpClientConnection; +import org.apache.http.impl.DefaultHttpParams; +import org.apache.http.impl.HttpGetRequest; +import org.apache.http.interceptor.RequestConnControl; +import org.apache.http.interceptor.RequestContent; +import org.apache.http.interceptor.RequestTargetHost; +import org.apache.http.interceptor.RequestUserAgent; +import org.apache.http.params.HttpParams; +import org.apache.http.params.HttpProtocolParams; + +/** + *

+ *

+ * @author Oleg Kalnichevski + * + * @version $Revision$ + */ +public class HttpRequestExecutorDemo { + + public static void main(String[] args) throws Exception { + =20 + HttpParams params =3D new DefaultHttpParams(null); + =20 + new HttpProtocolParams(params) + .setVersion(HttpVersion.HTTP_1_1) + .setContentCharset("UTF-8") + .setUserAgent("Jakarta HTTP Demo"); + =20 + HttpRequestExecutor httpexecutor =3D new HttpRequestExecutor(param= s); + // Required request interceptors + httpexecutor.setRequestInterceptor(new RequestContent()); + httpexecutor.setRequestInterceptor(new RequestTargetHost()); + // Recommended request interceptors + httpexecutor.setRequestInterceptor(new RequestConnControl()); + httpexecutor.setRequestInterceptor(new RequestUserAgent()); + =20 + HttpHost host =3D new HttpHost("www.yahoo.com"); + HttpClientConnection conn =3D new DefaultHttpClientConnection(host= ); + try { + HttpGetRequest request1 =3D new HttpGetRequest("/"); + HttpResponse response1 =3D httpexecutor.execute(request1, conn= ); + System.out.println("<< Response: " + response1.getStatusLine()= ); + System.out.println(EntityConsumer.toString(response1.getEntity= ())); + System.out.println("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= "); + if (conn.isOpen()) { + System.out.println("Connection kept alive..."); + } + HttpGetRequest request2 =3D new HttpGetRequest("/stuff"); + HttpResponse response2 =3D httpexecutor.execute(request2, conn= ); + System.out.println("<< Response: " + response2.getStatusLine()= ); + System.out.println(EntityConsumer.toString(response2.getEntity= ())); + System.out.println("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= "); + } finally { + conn.close(); + } + } + =20 +} Propchange: jakarta/httpclient/trunk/http-common/src/examples/org/apache/ht= tp/examples/HttpRequestExecutorDemo.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Propchange: jakarta/httpclient/trunk/http-common/src/examples/org/apache/ht= tp/examples/HttpRequestExecutorDemo.java ---------------------------------------------------------------------------= --- svn:keywords =3D Date Author Id Revision HeadURL Propchange: jakarta/httpclient/trunk/http-common/src/examples/org/apache/ht= tp/examples/HttpRequestExecutorDemo.java ---------------------------------------------------------------------------= --- svn:mime-type =3D text/plain