* Changed HttpClient interface to take a single HttpUriRequest parameter instead HttpHost / HttpRequest pair
* Fixed bug in the RequestAddCookies protocol interceptor git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@537141 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c2bebe8f7e
commit
3ff9c31171
|
@ -39,7 +39,9 @@ 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;
|
||||||
|
@ -96,10 +98,13 @@ public class ClientExecuteDirect {
|
||||||
|
|
||||||
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(target, req);
|
HttpResponse rsp = client.execute(roureq, null);
|
||||||
entity = rsp.getEntity();
|
entity = rsp.getEntity();
|
||||||
|
|
||||||
System.out.println("----------------------------------------");
|
System.out.println("----------------------------------------");
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
package org.apache.http.examples.client;
|
package org.apache.http.examples.client;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpHost;
|
|
||||||
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;
|
||||||
|
@ -62,12 +61,10 @@ public class MethodAbort {
|
||||||
|
|
||||||
HttpClient httpclient = new DefaultHttpClient(params);
|
HttpClient httpclient = new DefaultHttpClient(params);
|
||||||
|
|
||||||
HttpHost target = new HttpHost("www.apache.org", 80, "http");
|
HttpGet httpget = new HttpGet("http://www.apache.org/");
|
||||||
|
|
||||||
HttpGet httpget = new HttpGet("/");
|
System.out.println("executing request " + httpget.getURI());
|
||||||
|
HttpResponse response = httpclient.execute(httpget);
|
||||||
System.out.println("executing request to " + target);
|
|
||||||
HttpResponse response = httpclient.execute(target, httpget);
|
|
||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
|
|
||||||
System.out.println("----------------------------------------");
|
System.out.println("----------------------------------------");
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpException;
|
import org.apache.http.HttpException;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
|
import org.apache.http.client.methods.HttpUriRequest;
|
||||||
import org.apache.http.conn.ClientConnectionManager;
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,14 +95,11 @@ public interface HttpClient {
|
||||||
;
|
;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a request for the given target using the
|
* Executes a request using the {@link #getContext default context}.
|
||||||
* {@link #getContext default context}.
|
* Same as {@link #execute(HttpUriRequest,HttpContext)
|
||||||
* Same as {@link #execute(HttpHost,HttpRequest,HttpContext)
|
* client.execute(request, client.getContext())},
|
||||||
* client.execute(target, request, client.getContext())},
|
|
||||||
* see there for details.
|
* see there for details.
|
||||||
*
|
*
|
||||||
* @param target the target host for the request.
|
|
||||||
* Some implementations may accept <code>null</code>.
|
|
||||||
* @param request the request to execute
|
* @param request the request to execute
|
||||||
*
|
*
|
||||||
* @return the response to the request
|
* @return the response to the request
|
||||||
|
@ -110,17 +108,15 @@ public interface HttpClient {
|
||||||
* @throws IOException in case of an IO problem
|
* @throws IOException in case of an IO problem
|
||||||
* <br/><i @@@>timeout exceptions?</i>
|
* <br/><i @@@>timeout exceptions?</i>
|
||||||
*/
|
*/
|
||||||
HttpResponse execute(HttpHost target, HttpRequest request)
|
HttpResponse execute(HttpUriRequest request)
|
||||||
throws HttpException, IOException
|
throws HttpException, IOException
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a request for the given target using the given context.
|
* Executes a request using the given context.
|
||||||
* The route to the target will be determined by the HTTP client.
|
* The route to the target will be determined by the HTTP client.
|
||||||
*
|
*
|
||||||
* @param target the target host for the request.
|
|
||||||
* Some implementations may accept <code>null</code>.
|
|
||||||
* @param request the request to execute
|
* @param request the request to execute
|
||||||
* @param context the context to use for the execution, or
|
* @param context the context to use for the execution, or
|
||||||
* <code>null</code> to use the
|
* <code>null</code> to use the
|
||||||
|
@ -136,8 +132,7 @@ public interface HttpClient {
|
||||||
* @throws IOException in case of an IO problem
|
* @throws IOException in case of an IO problem
|
||||||
* <br/><i @@@>timeout exceptions?</i>
|
* <br/><i @@@>timeout exceptions?</i>
|
||||||
*/
|
*/
|
||||||
HttpResponse execute(HttpHost target, HttpRequest request,
|
HttpResponse execute(HttpUriRequest request, HttpContext context)
|
||||||
HttpContext context)
|
|
||||||
throws HttpException, IOException
|
throws HttpException, IOException
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ package org.apache.http.client.methods;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.apache.http.HttpRequest;
|
|
||||||
import org.apache.http.HttpVersion;
|
import org.apache.http.HttpVersion;
|
||||||
import org.apache.http.RequestLine;
|
import org.apache.http.RequestLine;
|
||||||
import org.apache.http.conn.ConnectionReleaseTrigger;
|
import org.apache.http.conn.ConnectionReleaseTrigger;
|
||||||
|
@ -52,7 +51,7 @@ import org.apache.http.params.HttpProtocolParams;
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
abstract class HttpRequestBase extends AbstractHttpMessage
|
abstract class HttpRequestBase extends AbstractHttpMessage
|
||||||
implements HttpRequest, AbortableHttpRequest {
|
implements HttpUriRequest, AbortableHttpRequest {
|
||||||
|
|
||||||
private URI uri;
|
private URI uri;
|
||||||
private ConnectionReleaseTrigger releaseTrigger;
|
private ConnectionReleaseTrigger releaseTrigger;
|
||||||
|
|
|
@ -131,9 +131,15 @@ public class RequestAddCookies implements HttpRequestInterceptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String hostName = targetHost.getHostName();
|
||||||
|
int port = targetHost.getPort();
|
||||||
|
if (port < 0) {
|
||||||
|
port = conn.getRemotePort();
|
||||||
|
}
|
||||||
|
|
||||||
CookieOrigin cookieOrigin = new CookieOrigin(
|
CookieOrigin cookieOrigin = new CookieOrigin(
|
||||||
targetHost.getHostName(),
|
hostName,
|
||||||
targetHost.getPort(),
|
port,
|
||||||
requestURI.getPath(),
|
requestURI.getPath(),
|
||||||
conn.isSecure());
|
conn.isSecure());
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
package org.apache.http.impl.client;
|
package org.apache.http.impl.client;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.http.ConnectionReuseStrategy;
|
import org.apache.http.ConnectionReuseStrategy;
|
||||||
|
@ -47,6 +48,7 @@ import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.HttpRequestRetryHandler;
|
import org.apache.http.client.HttpRequestRetryHandler;
|
||||||
import org.apache.http.client.HttpState;
|
import org.apache.http.client.HttpState;
|
||||||
import org.apache.http.client.RoutedRequest;
|
import org.apache.http.client.RoutedRequest;
|
||||||
|
import org.apache.http.client.methods.HttpUriRequest;
|
||||||
import org.apache.http.conn.ClientConnectionManager;
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
import org.apache.http.cookie.CookieSpecRegistry;
|
import org.apache.http.cookie.CookieSpecRegistry;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
|
@ -304,11 +306,9 @@ public abstract class AbstractHttpClient
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps to {@link #execute(HttpHost,HttpRequest,HttpContext)
|
* Maps to {@link #execute(HttpUriRequest,HttpContext)
|
||||||
* execute(target, request, context)}.
|
* execute(request, context)}.
|
||||||
*
|
*
|
||||||
* @param target the target host for the request.
|
|
||||||
* Some implementations may accept <code>null</code>.
|
|
||||||
* @param request the request to execute
|
* @param request the request to execute
|
||||||
*
|
*
|
||||||
* @return the response to the request
|
* @return the response to the request
|
||||||
|
@ -316,10 +316,10 @@ public abstract class AbstractHttpClient
|
||||||
* @throws HttpException in case of a problem
|
* @throws HttpException in case of a problem
|
||||||
* @throws IOException in case of an IO problem
|
* @throws IOException in case of an IO problem
|
||||||
*/
|
*/
|
||||||
public final HttpResponse execute(HttpHost target, HttpRequest request)
|
public final HttpResponse execute(HttpUriRequest request)
|
||||||
throws HttpException, IOException {
|
throws HttpException, IOException {
|
||||||
|
|
||||||
return execute(target, request, null);
|
return execute(request, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -332,17 +332,26 @@ public abstract class AbstractHttpClient
|
||||||
* Some implementations may accept <code>null</code>.
|
* Some implementations may accept <code>null</code>.
|
||||||
* @param request the request to execute
|
* @param request the request to execute
|
||||||
*/
|
*/
|
||||||
public final HttpResponse execute(HttpHost target, HttpRequest request,
|
public final HttpResponse execute(HttpUriRequest request, HttpContext context)
|
||||||
HttpContext context)
|
|
||||||
throws HttpException, IOException {
|
throws HttpException, IOException {
|
||||||
|
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
("Request must not be null.");
|
("Request must not be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// A null target may be acceptable if there is a default target.
|
// A null target may be acceptable if there is a default target.
|
||||||
// Otherwise, the null target is detected in determineRoute().
|
// Otherwise, the null target is detected in determineRoute().
|
||||||
|
HttpHost target = null;
|
||||||
|
|
||||||
|
URI requestURI = request.getURI();
|
||||||
|
if (requestURI.isAbsolute()) {
|
||||||
|
target = new HttpHost(
|
||||||
|
requestURI.getHost(),
|
||||||
|
requestURI.getPort(),
|
||||||
|
requestURI.getScheme());
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
context = new HttpExecutionContext(getContext());
|
context = new HttpExecutionContext(getContext());
|
||||||
|
|
Loading…
Reference in New Issue