HTTPCLIENT-715: changed more tests and examples to not use RoutedRequest

git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@603977 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Roland Weber 2007-12-13 18:54:50 +00:00
parent 389cd303f2
commit c86b3b02bd
6 changed files with 25 additions and 89 deletions

View File

@ -39,13 +39,12 @@ import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion; import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.RoutedRequest;
import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.HttpRoute;
import org.apache.http.conn.PlainSocketFactory; import org.apache.http.conn.PlainSocketFactory;
import org.apache.http.conn.Scheme; import org.apache.http.conn.Scheme;
import org.apache.http.conn.SchemeRegistry; import org.apache.http.conn.SchemeRegistry;
import org.apache.http.conn.SocketFactory; import org.apache.http.conn.SocketFactory;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
@ -101,17 +100,14 @@ public class ClientExecuteProxy {
HttpClient client = createHttpClient(); HttpClient client = createHttpClient();
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
HttpRequest req = createRequest(); HttpRequest req = createRequest();
final HttpRoute route = new HttpRoute
(target, null, proxy,
supportedSchemes.getScheme(target).isLayered());
final RoutedRequest roureq = new RoutedRequest.Impl(req, route);
System.out.println("executing request to " + target + " via " + proxy); System.out.println("executing request to " + target + " via " + proxy);
HttpEntity entity = null; HttpEntity entity = null;
try { try {
HttpResponse rsp = client.execute(roureq, null); HttpResponse rsp = client.execute(target, req, null);
entity = rsp.getEntity(); entity = rsp.getEntity();
System.out.println("----------------------------------------"); System.out.println("----------------------------------------");

View File

@ -36,6 +36,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.RoutedRequest; import org.apache.http.client.RoutedRequest;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.HttpRoute; import org.apache.http.conn.HttpRoute;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
/** /**
@ -54,16 +55,17 @@ public class ClientProxyAuthentication {
HttpHost targetHost = new HttpHost("www.verisign.com", 443, "https"); HttpHost targetHost = new HttpHost("www.verisign.com", 443, "https");
HttpHost proxy = new HttpHost("localhost", 8080); HttpHost proxy = new HttpHost("localhost", 8080);
HttpRoute route = new HttpRoute(targetHost, null, proxy, true);
httpclient.getParams().setParameter
(ConnRoutePNames.DEFAULT_PROXY, proxy);
HttpGet httpget = new HttpGet("/"); HttpGet httpget = new HttpGet("/");
RoutedRequest routedReq = new RoutedRequest.Impl(httpget, route);
System.out.println("executing request: " + httpget.getRequestLine()); System.out.println("executing request: " + httpget.getRequestLine());
System.out.println("using route: " + route); System.out.println("via proxy: " + proxy);
System.out.println("to target: " + targetHost);
HttpResponse response = httpclient.execute(routedReq, null); HttpResponse response = httpclient.execute(targetHost, httpget, null);
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------"); System.out.println("----------------------------------------");

View File

@ -195,28 +195,4 @@ public interface HttpClient {
; ;
/**
* Executes a request along the given route.
*
* @param roureq the request to execute along with the route
* @param context the context to use for the execution, or
* <code>null</code> to use the
* {@link #getDefaultContext default context}
*
* @return the response to the request. See
* {@link #execute(HttpUriRequest,HttpContext)}
* for details.
*
* @deprecated pass just the target instead of a route
*
* @throws HttpException in case of a problem
* @throws IOException in case of an IO problem
* @throws InterruptedException in case of an interrupt
* <br/><i @@@>timeout exceptions?</i>
*/
HttpResponse execute(RoutedRequest roureq, HttpContext context)
throws HttpException, IOException, InterruptedException
;
} // interface HttpClient } // interface HttpClient

View File

@ -49,7 +49,6 @@ import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpRequestRetryHandler; import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.RedirectHandler; import org.apache.http.client.RedirectHandler;
import org.apache.http.client.RoutedRequest;
import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.HttpRoutePlanner; import org.apache.http.conn.HttpRoutePlanner;
@ -457,32 +456,6 @@ public abstract class AbstractHttpClient implements HttpClient {
} }
//@@@ to be removed with HTTPCLIENT-715
public final HttpResponse execute(RoutedRequest roureq,
HttpContext context)
throws HttpException, IOException, InterruptedException {
//throw new UnsupportedOperationException("@@@ execute(roureq,context)");
if (roureq == null) {
throw new IllegalArgumentException
("Routed request must not be null.");
}
if (roureq.getRequest() == null) {
throw new IllegalArgumentException
("Request must not be null.");
}
if (roureq.getRoute() == null) {
throw new IllegalArgumentException
("Route must not be null.");
}
//@@@ this is a temporary violation of the API
//@@@ this method will be removed with HTTPCLIENT-715
return execute(roureq.getRoute().getTargetHost(),
roureq.getRequest(), context);
}
// non-javadoc, see interface HttpClient // non-javadoc, see interface HttpClient
public final HttpResponse execute(HttpHost target, HttpRequest request) public final HttpResponse execute(HttpHost target, HttpRequest request)
throws HttpException, IOException, InterruptedException { throws HttpException, IOException, InterruptedException {
@ -543,7 +516,7 @@ public abstract class AbstractHttpClient implements HttpClient {
* and the client parameters. * and the client parameters.
* <br/> * <br/>
* This method is called by the default implementation of * This method is called by the default implementation of
* {@link #execute(RoutedRequest,HttpContext)} * {@link #execute(HttpHost,HttpRequest,HttpContext)}
* to obtain the parameters for the * to obtain the parameters for the
* {@link DefaultClientRequestDirector}. * {@link DefaultClientRequestDirector}.
* *

View File

@ -41,7 +41,6 @@ import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.apache.http.ProtocolVersion; import org.apache.http.ProtocolVersion;
import org.apache.http.client.CookieStore; import org.apache.http.client.CookieStore;
import org.apache.http.client.RoutedRequest;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.params.ClientPNames; import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.CookiePolicy; import org.apache.http.client.params.CookiePolicy;
@ -110,8 +109,7 @@ public class TestCookie2Support extends ServerTestBase {
HttpGet httpget = new HttpGet("/test/"); HttpGet httpget = new HttpGet("/test/");
RoutedRequest request1 = new RoutedRequest.Impl(httpget, getDefaultRoute()); HttpResponse response1 = client.execute(getServerHttp(), httpget, context);
HttpResponse response1 = client.execute(request1, context);
HttpEntity e1 = response1.getEntity(); HttpEntity e1 = response1.getEntity();
if (e1 != null) { if (e1 != null) {
e1.consumeContent(); e1.consumeContent();
@ -121,8 +119,7 @@ public class TestCookie2Support extends ServerTestBase {
assertNotNull(cookies); assertNotNull(cookies);
assertEquals(1, cookies.length); assertEquals(1, cookies.length);
RoutedRequest request2 = new RoutedRequest.Impl(httpget, getDefaultRoute()); HttpResponse response2 = client.execute(getServerHttp(), httpget, context);
HttpResponse response2 = client.execute(request2, context);
HttpEntity e2 = response2.getEntity(); HttpEntity e2 = response2.getEntity();
if (e2 != null) { if (e2 != null) {
e2.consumeContent(); e2.consumeContent();
@ -163,8 +160,7 @@ public class TestCookie2Support extends ServerTestBase {
HttpGet httpget = new HttpGet("/test/"); HttpGet httpget = new HttpGet("/test/");
RoutedRequest request1 = new RoutedRequest.Impl(httpget, getDefaultRoute()); HttpResponse response1 = client.execute(getServerHttp(), httpget, context);
HttpResponse response1 = client.execute(request1, context);
HttpEntity e1 = response1.getEntity(); HttpEntity e1 = response1.getEntity();
if (e1 != null) { if (e1 != null) {
e1.consumeContent(); e1.consumeContent();
@ -174,8 +170,7 @@ public class TestCookie2Support extends ServerTestBase {
assertNotNull(cookies); assertNotNull(cookies);
assertEquals(2, cookies.length); assertEquals(2, cookies.length);
RoutedRequest request2 = new RoutedRequest.Impl(httpget, getDefaultRoute()); HttpResponse response2 = client.execute(getServerHttp(), httpget, context);
HttpResponse response2 = client.execute(request2, context);
HttpEntity e2 = response2.getEntity(); HttpEntity e2 = response2.getEntity();
if (e2 != null) { if (e2 != null) {
e2.consumeContent(); e2.consumeContent();
@ -214,8 +209,7 @@ public class TestCookie2Support extends ServerTestBase {
HttpGet httpget = new HttpGet("/test/"); HttpGet httpget = new HttpGet("/test/");
RoutedRequest request1 = new RoutedRequest.Impl(httpget, getDefaultRoute()); HttpResponse response1 = client.execute(getServerHttp(), httpget, context);
HttpResponse response1 = client.execute(request1, context);
HttpEntity e1 = response1.getEntity(); HttpEntity e1 = response1.getEntity();
if (e1 != null) { if (e1 != null) {
e1.consumeContent(); e1.consumeContent();
@ -225,8 +219,7 @@ public class TestCookie2Support extends ServerTestBase {
assertNotNull(cookies); assertNotNull(cookies);
assertEquals(1, cookies.length); assertEquals(1, cookies.length);
RoutedRequest request2 = new RoutedRequest.Impl(httpget, getDefaultRoute()); HttpResponse response2 = client.execute(getServerHttp(), httpget, context);
HttpResponse response2 = client.execute(request2, context);
HttpEntity e2 = response2.getEntity(); HttpEntity e2 = response2.getEntity();
if (e2 != null) { if (e2 != null) {
e2.consumeContent(); e2.consumeContent();
@ -267,8 +260,7 @@ public class TestCookie2Support extends ServerTestBase {
HttpGet httpget = new HttpGet("/test/"); HttpGet httpget = new HttpGet("/test/");
RoutedRequest request1 = new RoutedRequest.Impl(httpget, getDefaultRoute()); HttpResponse response1 = client.execute(getServerHttp(), httpget, context);
HttpResponse response1 = client.execute(request1, context);
HttpEntity e1 = response1.getEntity(); HttpEntity e1 = response1.getEntity();
if (e1 != null) { if (e1 != null) {
e1.consumeContent(); e1.consumeContent();

View File

@ -1,7 +1,7 @@
/* /*
* $HeadURL:$ * $HeadURL$
* $Revision:$ * $Revision$
* $Date:$ * $Date$
* ==================================================================== * ====================================================================
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -39,7 +39,6 @@ import org.apache.http.HttpException;
import org.apache.http.HttpRequest; import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.apache.http.client.RoutedRequest;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.localserver.ServerTestBase; import org.apache.http.localserver.ServerTestBase;
@ -50,7 +49,7 @@ import org.apache.http.protocol.HttpRequestHandler;
/** /**
* Simple tests for {@link RequestWrapper}. * Simple tests for {@link RequestWrapper}.
* *
* @version $Revision:$ * @version $Revision$
*/ */
public class TestRequestWrapper extends ServerTestBase { public class TestRequestWrapper extends ServerTestBase {
@ -97,8 +96,7 @@ public class TestRequestWrapper extends ServerTestBase {
String s = "http://localhost:" + port + "/path"; String s = "http://localhost:" + port + "/path";
HttpGet httpget = new HttpGet(s); HttpGet httpget = new HttpGet(s);
RoutedRequest request = new RoutedRequest.Impl(httpget, getDefaultRoute()); HttpResponse response = client.execute(getServerHttp(), httpget, context);
HttpResponse response = client.execute(request, context);
HttpEntity e = response.getEntity(); HttpEntity e = response.getEntity();
if (e != null) { if (e != null) {
e.consumeContent(); e.consumeContent();
@ -123,8 +121,7 @@ public class TestRequestWrapper extends ServerTestBase {
String s = "http://localhost:" + port; String s = "http://localhost:" + port;
HttpGet httpget = new HttpGet(s); HttpGet httpget = new HttpGet(s);
RoutedRequest request = new RoutedRequest.Impl(httpget, getDefaultRoute()); HttpResponse response = client.execute(getServerHttp(), httpget, context);
HttpResponse response = client.execute(request, context);
HttpEntity e = response.getEntity(); HttpEntity e = response.getEntity();
if (e != null) { if (e != null) {
e.consumeContent(); e.consumeContent();