mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-09 19:45:48 +00:00
HTTPCLIENT-715: changed tests and one example to not use RoutedRequest
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@603969 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
92a3847e4c
commit
389cd303f2
@ -39,9 +39,7 @@
|
|||||||
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;
|
||||||
@ -98,13 +96,10 @@ public final static void main(String[] args)
|
|||||||
|
|
||||||
HttpRequest req = createRequest();
|
HttpRequest req = createRequest();
|
||||||
|
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
|
||||||
final RoutedRequest roureq = new RoutedRequest.Impl(req, route);
|
|
||||||
|
|
||||||
System.out.println("executing request to " + target);
|
System.out.println("executing request to " + target);
|
||||||
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("----------------------------------------");
|
||||||
|
@ -219,5 +219,4 @@ HttpResponse execute(RoutedRequest roureq, HttpContext context)
|
|||||||
throws HttpException, IOException, InterruptedException
|
throws HttpException, IOException, InterruptedException
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
} // interface HttpClient
|
} // interface HttpClient
|
||||||
|
@ -45,7 +45,6 @@
|
|||||||
import org.apache.http.client.CircularRedirectException;
|
import org.apache.http.client.CircularRedirectException;
|
||||||
import org.apache.http.client.CookieStore;
|
import org.apache.http.client.CookieStore;
|
||||||
import org.apache.http.client.RedirectException;
|
import org.apache.http.client.RedirectException;
|
||||||
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.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.client.params.ClientPNames;
|
import org.apache.http.client.params.ClientPNames;
|
||||||
@ -244,8 +243,7 @@ public void testBasicRedirect300() throws Exception {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
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();
|
||||||
@ -269,8 +267,7 @@ public void testBasicRedirect301() throws Exception {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
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();
|
||||||
@ -298,8 +295,7 @@ public void testBasicRedirect302() throws Exception {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
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();
|
||||||
@ -327,8 +323,7 @@ public void testBasicRedirect303() throws Exception {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
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();
|
||||||
@ -356,8 +351,7 @@ public void testBasicRedirect304() throws Exception {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
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();
|
||||||
@ -381,8 +375,7 @@ public void testBasicRedirect305() throws Exception {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
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();
|
||||||
@ -406,8 +399,7 @@ public void testBasicRedirect307() throws Exception {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
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();
|
||||||
@ -433,9 +425,8 @@ public void testMaxRedirectCheck() throws Exception {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet("/circular-oldlocation/");
|
HttpGet httpget = new HttpGet("/circular-oldlocation/");
|
||||||
|
|
||||||
RoutedRequest request = new RoutedRequest.Impl(httpget, getDefaultRoute());
|
|
||||||
try {
|
try {
|
||||||
client.execute(request, null);
|
client.execute(getServerHttp(), httpget);
|
||||||
fail("RedirectException exception should have been thrown");
|
fail("RedirectException exception should have been thrown");
|
||||||
} catch (RedirectException e) {
|
} catch (RedirectException e) {
|
||||||
// expected
|
// expected
|
||||||
@ -450,9 +441,8 @@ public void testCircularRedirect() throws Exception {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet("/circular-oldlocation/");
|
HttpGet httpget = new HttpGet("/circular-oldlocation/");
|
||||||
|
|
||||||
RoutedRequest request = new RoutedRequest.Impl(httpget, getDefaultRoute());
|
|
||||||
try {
|
try {
|
||||||
client.execute(request, null);
|
client.execute(getServerHttp(), httpget);
|
||||||
fail("CircularRedirectException exception should have been thrown");
|
fail("CircularRedirectException exception should have been thrown");
|
||||||
} catch (CircularRedirectException e) {
|
} catch (CircularRedirectException e) {
|
||||||
// expected
|
// expected
|
||||||
@ -470,8 +460,7 @@ public void testPostRedirect() throws Exception {
|
|||||||
HttpPost httppost = new HttpPost("/oldlocation/");
|
HttpPost httppost = new HttpPost("/oldlocation/");
|
||||||
httppost.setEntity(new StringEntity("stuff"));
|
httppost.setEntity(new StringEntity("stuff"));
|
||||||
|
|
||||||
RoutedRequest request = new RoutedRequest.Impl(httppost, getDefaultRoute());
|
HttpResponse response = client.execute(getServerHttp(), httppost, 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();
|
||||||
@ -497,8 +486,7 @@ public void testRelativeRedirect() throws Exception {
|
|||||||
ClientPNames.REJECT_RELATIVE_REDIRECT, false);
|
ClientPNames.REJECT_RELATIVE_REDIRECT, false);
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
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();
|
||||||
@ -527,8 +515,7 @@ public void testRelativeRedirect2() throws Exception {
|
|||||||
ClientPNames.REJECT_RELATIVE_REDIRECT, false);
|
ClientPNames.REJECT_RELATIVE_REDIRECT, false);
|
||||||
HttpGet httpget = new HttpGet("/test/oldlocation");
|
HttpGet httpget = new HttpGet("/test/oldlocation");
|
||||||
|
|
||||||
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();
|
||||||
@ -554,9 +541,8 @@ public void testRejectRelativeRedirect() throws Exception {
|
|||||||
ClientPNames.REJECT_RELATIVE_REDIRECT, true);
|
ClientPNames.REJECT_RELATIVE_REDIRECT, true);
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
RoutedRequest request = new RoutedRequest.Impl(httpget, getDefaultRoute());
|
|
||||||
try {
|
try {
|
||||||
client.execute(request, null);
|
client.execute(getServerHttp(), httpget);
|
||||||
fail("ProtocolException exception should have been thrown");
|
fail("ProtocolException exception should have been thrown");
|
||||||
} catch (ProtocolException e) {
|
} catch (ProtocolException e) {
|
||||||
// expected
|
// expected
|
||||||
@ -570,9 +556,8 @@ public void testRejectBogusRedirectLocation() throws Exception {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
RoutedRequest request = new RoutedRequest.Impl(httpget, getDefaultRoute());
|
|
||||||
try {
|
try {
|
||||||
client.execute(request, null);
|
client.execute(getServerHttp(), httpget);
|
||||||
fail("IllegalStateException should have been thrown");
|
fail("IllegalStateException should have been thrown");
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
// expected
|
// expected
|
||||||
@ -589,9 +574,8 @@ public void testRejectInvalidRedirectLocation() throws Exception {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
RoutedRequest request = new RoutedRequest.Impl(httpget, getDefaultRoute());
|
|
||||||
try {
|
try {
|
||||||
client.execute(request, null);
|
client.execute(getServerHttp(), httpget);
|
||||||
fail("ProtocolException should have been thrown");
|
fail("ProtocolException should have been thrown");
|
||||||
} catch (ProtocolException e) {
|
} catch (ProtocolException e) {
|
||||||
// expected
|
// expected
|
||||||
@ -619,9 +603,8 @@ public void testRedirectWithCookie() throws Exception {
|
|||||||
HttpContext context = client.getDefaultContext();
|
HttpContext context = client.getDefaultContext();
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
RoutedRequest request = new RoutedRequest.Impl(httpget, getDefaultRoute());
|
|
||||||
|
|
||||||
HttpResponse response = client.execute(request, context);
|
HttpResponse response = client.execute(getServerHttp(), httpget, context);
|
||||||
HttpEntity e = response.getEntity();
|
HttpEntity e = response.getEntity();
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
e.consumeContent();
|
e.consumeContent();
|
||||||
@ -654,9 +637,8 @@ public void testDefaultHeadersRedirect() throws Exception {
|
|||||||
|
|
||||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||||
|
|
||||||
RoutedRequest request = new RoutedRequest.Impl(httpget, getDefaultRoute());
|
|
||||||
|
|
||||||
HttpResponse response = client.execute(request, context);
|
HttpResponse response = client.execute(getServerHttp(), httpget, context);
|
||||||
HttpEntity e = response.getEntity();
|
HttpEntity e = response.getEntity();
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
e.consumeContent();
|
e.consumeContent();
|
||||||
|
@ -176,13 +176,14 @@ protected HttpHost getServerHttp() {
|
|||||||
"http");
|
"http");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the default route to the local test server.
|
* Obtains the default route to the local test server.
|
||||||
*
|
*
|
||||||
* @return the default route to the local test server
|
* @return the default route to the local test server
|
||||||
*/
|
*/
|
||||||
protected HttpRoute getDefaultRoute() {
|
protected HttpRoute getDefaultRoute() {
|
||||||
return new HttpRoute(new HttpHost("localhost", localServer.getServicePort()));
|
return new HttpRoute(getServerHttp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user