params refactoring, step 6 - Moved param hierarchy building methods to an optional interface extending HttpParams
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@542225 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
53e4063593
commit
7813fd1197
|
@ -79,6 +79,7 @@ import org.apache.http.entity.BufferedHttpEntity;
|
||||||
import org.apache.http.message.BasicHttpRequest;
|
import org.apache.http.message.BasicHttpRequest;
|
||||||
import org.apache.http.params.HttpConnectionParams;
|
import org.apache.http.params.HttpConnectionParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
|
import org.apache.http.params.HttpParamsLinker;
|
||||||
import org.apache.http.params.HttpProtocolParams;
|
import org.apache.http.params.HttpProtocolParams;
|
||||||
import org.apache.http.protocol.HTTP;
|
import org.apache.http.protocol.HTTP;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
|
@ -177,7 +178,7 @@ public class DefaultClientRequestDirector
|
||||||
this.redirectHandler = redirectHandler;
|
this.redirectHandler = redirectHandler;
|
||||||
this.authHandler = authHandler;
|
this.authHandler = authHandler;
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.requestExec = new HttpRequestExecutor(params);
|
this.requestExec = new HttpRequestExecutor();
|
||||||
|
|
||||||
this.managedConn = null;
|
this.managedConn = null;
|
||||||
|
|
||||||
|
@ -254,10 +255,7 @@ public class DefaultClientRequestDirector
|
||||||
throws HttpException, IOException {
|
throws HttpException, IOException {
|
||||||
|
|
||||||
HttpRequest orig = roureq.getRequest();
|
HttpRequest orig = roureq.getRequest();
|
||||||
|
HttpParamsLinker.link(orig, this.params);
|
||||||
// Link parameter collections to form a hierarchy:
|
|
||||||
// request -> client
|
|
||||||
orig.getParams().setDefaults(this.params);
|
|
||||||
|
|
||||||
// Add default headers
|
// Add default headers
|
||||||
Collection defHeaders = (Collection) orig.getParams().getParameter(
|
Collection defHeaders = (Collection) orig.getParams().getParameter(
|
||||||
|
@ -335,8 +333,6 @@ public class DefaultClientRequestDirector
|
||||||
targetAuthState);
|
targetAuthState);
|
||||||
context.setAttribute(HttpClientContext.PROXY_AUTH_STATE,
|
context.setAttribute(HttpClientContext.PROXY_AUTH_STATE,
|
||||||
proxyAuthState);
|
proxyAuthState);
|
||||||
//@@@ review parameter hierachy building
|
|
||||||
request.getParams().setDefaults(requestExec.getParams());
|
|
||||||
requestExec.preProcess(request, httpProcessor, context);
|
requestExec.preProcess(request, httpProcessor, context);
|
||||||
|
|
||||||
if (orig instanceof AbortableHttpRequest) {
|
if (orig instanceof AbortableHttpRequest) {
|
||||||
|
@ -371,10 +367,7 @@ public class DefaultClientRequestDirector
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Link parameter collections to form a hierarchy:
|
HttpParamsLinker.link(request, this.params);
|
||||||
// response -> client
|
|
||||||
response.getParams().setDefaults(this.params);
|
|
||||||
|
|
||||||
requestExec.postProcess(response, httpProcessor, context);
|
requestExec.postProcess(response, httpProcessor, context);
|
||||||
|
|
||||||
RoutedRequest followup =
|
RoutedRequest followup =
|
||||||
|
@ -484,13 +477,13 @@ public class DefaultClientRequestDirector
|
||||||
|
|
||||||
case RouteDirector.CONNECT_TARGET:
|
case RouteDirector.CONNECT_TARGET:
|
||||||
case RouteDirector.CONNECT_PROXY:
|
case RouteDirector.CONNECT_PROXY:
|
||||||
managedConn.open(route, context, requestExec.getParams());
|
managedConn.open(route, context, this.params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RouteDirector.TUNNEL_TARGET:
|
case RouteDirector.TUNNEL_TARGET:
|
||||||
boolean secure = createTunnel(route, context);
|
boolean secure = createTunnel(route, context);
|
||||||
LOG.debug("Tunnel created");
|
LOG.debug("Tunnel created");
|
||||||
managedConn.tunnelCreated(secure, requestExec.getParams());
|
managedConn.tunnelCreated(secure, this.params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RouteDirector.TUNNEL_PROXY:
|
case RouteDirector.TUNNEL_PROXY:
|
||||||
|
@ -498,7 +491,7 @@ public class DefaultClientRequestDirector
|
||||||
("Proxy chains are not supported.");
|
("Proxy chains are not supported.");
|
||||||
|
|
||||||
case RouteDirector.LAYER_PROTOCOL:
|
case RouteDirector.LAYER_PROTOCOL:
|
||||||
managedConn.layerProtocol(context, requestExec.getParams());
|
managedConn.layerProtocol(context, this.params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RouteDirector.UNREACHABLE:
|
case RouteDirector.UNREACHABLE:
|
||||||
|
|
|
@ -102,7 +102,6 @@ public class ExecReqThread extends GetConnThread {
|
||||||
|
|
||||||
HttpRequest request = (HttpRequest) request_spec.context.
|
HttpRequest request = (HttpRequest) request_spec.context.
|
||||||
getAttribute(HttpExecutionContext.HTTP_REQUEST);
|
getAttribute(HttpExecutionContext.HTTP_REQUEST);
|
||||||
request.getParams().setDefaults(request_spec.executor.getParams());
|
|
||||||
request_spec.executor.preProcess
|
request_spec.executor.preProcess
|
||||||
(request, request_spec.processor, request_spec.context);
|
(request, request_spec.processor, request_spec.context);
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@ import org.apache.http.HttpClientConnection;
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.http.HttpHost;
|
||||||
import org.apache.http.HttpRequest;
|
import org.apache.http.HttpRequest;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.params.HttpParams;
|
||||||
|
import org.apache.http.params.HttpParamsLinker;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
import org.apache.http.protocol.HttpExecutionContext;
|
||||||
import org.apache.http.protocol.HttpProcessor;
|
import org.apache.http.protocol.HttpProcessor;
|
||||||
|
@ -59,6 +61,7 @@ public final class Helper {
|
||||||
HttpHost target,
|
HttpHost target,
|
||||||
HttpRequestExecutor exec,
|
HttpRequestExecutor exec,
|
||||||
HttpProcessor proc,
|
HttpProcessor proc,
|
||||||
|
HttpParams params,
|
||||||
HttpContext ctxt)
|
HttpContext ctxt)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
|
@ -66,9 +69,10 @@ public final class Helper {
|
||||||
ctxt.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, target);
|
ctxt.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, target);
|
||||||
ctxt.setAttribute(HttpExecutionContext.HTTP_REQUEST, req);
|
ctxt.setAttribute(HttpExecutionContext.HTTP_REQUEST, req);
|
||||||
|
|
||||||
req.getParams().setDefaults(exec.getParams());
|
HttpParamsLinker.link(req, params);
|
||||||
exec.preProcess(req, proc, ctxt);
|
exec.preProcess(req, proc, ctxt);
|
||||||
HttpResponse rsp = exec.execute(req, conn, ctxt);
|
HttpResponse rsp = exec.execute(req, conn, ctxt);
|
||||||
|
HttpParamsLinker.link(rsp, params);
|
||||||
exec.postProcess(rsp, proc, ctxt);
|
exec.postProcess(rsp, proc, ctxt);
|
||||||
|
|
||||||
return rsp;
|
return rsp;
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.localserver.LocalTestServer;
|
import org.apache.http.localserver.LocalTestServer;
|
||||||
import org.apache.http.localserver.ServerTestBase;
|
import org.apache.http.localserver.ServerTestBase;
|
||||||
|
import org.apache.http.params.HttpParamsLinker;
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
import org.apache.http.protocol.HttpExecutionContext;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
@ -85,12 +86,13 @@ public class TestLocalServer extends ServerTestBase {
|
||||||
HttpExecutionContext.HTTP_TARGET_HOST, target);
|
HttpExecutionContext.HTTP_TARGET_HOST, target);
|
||||||
httpContext.setAttribute(
|
httpContext.setAttribute(
|
||||||
HttpExecutionContext.HTTP_REQUEST, request);
|
HttpExecutionContext.HTTP_REQUEST, request);
|
||||||
request.getParams().setDefaults(httpExecutor.getParams());
|
|
||||||
|
|
||||||
|
HttpParamsLinker.link(request, defaultParams);
|
||||||
httpExecutor.preProcess
|
httpExecutor.preProcess
|
||||||
(request, httpProcessor, httpContext);
|
(request, httpProcessor, httpContext);
|
||||||
HttpResponse response = httpExecutor.execute
|
HttpResponse response = httpExecutor.execute
|
||||||
(request, conn, httpContext);
|
(request, conn, httpContext);
|
||||||
|
HttpParamsLinker.link(response, defaultParams);
|
||||||
httpExecutor.postProcess
|
httpExecutor.postProcess
|
||||||
(response, httpProcessor, httpContext);
|
(response, httpProcessor, httpContext);
|
||||||
|
|
||||||
|
@ -127,12 +129,13 @@ public class TestLocalServer extends ServerTestBase {
|
||||||
HttpExecutionContext.HTTP_TARGET_HOST, target);
|
HttpExecutionContext.HTTP_TARGET_HOST, target);
|
||||||
httpContext.setAttribute(
|
httpContext.setAttribute(
|
||||||
HttpExecutionContext.HTTP_REQUEST, request);
|
HttpExecutionContext.HTTP_REQUEST, request);
|
||||||
request.getParams().setDefaults(httpExecutor.getParams());
|
|
||||||
|
|
||||||
|
HttpParamsLinker.link(request, defaultParams);
|
||||||
httpExecutor.preProcess
|
httpExecutor.preProcess
|
||||||
(request, httpProcessor, httpContext);
|
(request, httpProcessor, httpContext);
|
||||||
HttpResponse response = httpExecutor.execute
|
HttpResponse response = httpExecutor.execute
|
||||||
(request, conn, httpContext);
|
(request, conn, httpContext);
|
||||||
|
HttpParamsLinker.link(response, defaultParams);
|
||||||
httpExecutor.postProcess
|
httpExecutor.postProcess
|
||||||
(response, httpProcessor, httpContext);
|
(response, httpProcessor, httpContext);
|
||||||
|
|
||||||
|
|
|
@ -194,8 +194,9 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
conn.open(route, httpContext, defaultParams);
|
conn.open(route, httpContext, defaultParams);
|
||||||
|
|
||||||
// a new context is created for each testcase, no need to reset
|
// a new context is created for each testcase, no need to reset
|
||||||
HttpResponse response = Helper.execute
|
HttpResponse response = Helper.execute(
|
||||||
(request, conn, target, httpExecutor, httpProcessor, httpContext);
|
request, conn, target,
|
||||||
|
httpExecutor, httpProcessor, defaultParams, httpContext);
|
||||||
|
|
||||||
assertEquals("wrong status in first response",
|
assertEquals("wrong status in first response",
|
||||||
HttpStatus.SC_OK,
|
HttpStatus.SC_OK,
|
||||||
|
@ -282,8 +283,8 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
conn.open(route, httpContext, defaultParams);
|
conn.open(route, httpContext, defaultParams);
|
||||||
|
|
||||||
// a new context is created for each testcase, no need to reset
|
// a new context is created for each testcase, no need to reset
|
||||||
HttpResponse response = Helper.execute
|
Helper.execute(request, conn, target,
|
||||||
(request, conn, target, httpExecutor, httpProcessor, httpContext);
|
httpExecutor, httpProcessor, defaultParams, httpContext);
|
||||||
|
|
||||||
// we leave the connection in mid-use
|
// we leave the connection in mid-use
|
||||||
// it's not really re-usable, but it must be closed anyway
|
// it's not really re-usable, but it must be closed anyway
|
||||||
|
@ -301,7 +302,6 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
// We now drop the hard references to the connection and trigger GC.
|
// We now drop the hard references to the connection and trigger GC.
|
||||||
WeakReference wref = new WeakReference(conn);
|
WeakReference wref = new WeakReference(conn);
|
||||||
conn = null;
|
conn = null;
|
||||||
response = null;
|
|
||||||
httpContext = null; // holds a reference to the connection
|
httpContext = null; // holds a reference to the connection
|
||||||
|
|
||||||
// Java does not guarantee that this will trigger the GC, but
|
// Java does not guarantee that this will trigger the GC, but
|
||||||
|
@ -338,9 +338,9 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
conn.open(route, httpContext, defaultParams);
|
conn.open(route, httpContext, defaultParams);
|
||||||
|
|
||||||
// a new context is created for each testcase, no need to reset
|
// a new context is created for each testcase, no need to reset
|
||||||
HttpResponse response = Helper.execute
|
HttpResponse response = Helper.execute(request, conn, target,
|
||||||
(request, conn, target, httpExecutor, httpProcessor, httpContext);
|
httpExecutor, httpProcessor, defaultParams, httpContext);
|
||||||
byte[] data = EntityUtils.toByteArray(response.getEntity());
|
EntityUtils.toByteArray(response.getEntity());
|
||||||
|
|
||||||
// release connection after marking it for re-use
|
// release connection after marking it for re-use
|
||||||
conn.markReusable();
|
conn.markReusable();
|
||||||
|
|
|
@ -110,7 +110,6 @@ public abstract class ServerTestBase extends TestCase {
|
||||||
*/
|
*/
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
|
||||||
boolean newparams = false;
|
|
||||||
if (defaultParams == null) {
|
if (defaultParams == null) {
|
||||||
defaultParams = new BasicHttpParams(null);
|
defaultParams = new BasicHttpParams(null);
|
||||||
HttpProtocolParams.setVersion
|
HttpProtocolParams.setVersion
|
||||||
|
@ -121,7 +120,6 @@ public abstract class ServerTestBase extends TestCase {
|
||||||
(defaultParams, "Jakarta-HttpComponents-Test/1.1");
|
(defaultParams, "Jakarta-HttpComponents-Test/1.1");
|
||||||
HttpProtocolParams.setUseExpectContinue
|
HttpProtocolParams.setUseExpectContinue
|
||||||
(defaultParams, false);
|
(defaultParams, false);
|
||||||
newparams = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (supportedSchemes == null) {
|
if (supportedSchemes == null) {
|
||||||
|
@ -139,8 +137,8 @@ public abstract class ServerTestBase extends TestCase {
|
||||||
// the context is created each time, it may get modified by test cases
|
// the context is created each time, it may get modified by test cases
|
||||||
httpContext = new HttpExecutionContext(null);
|
httpContext = new HttpExecutionContext(null);
|
||||||
|
|
||||||
if ((httpExecutor == null) || newparams) {
|
if (httpExecutor == null) {
|
||||||
httpExecutor = new HttpRequestExecutor(defaultParams);
|
httpExecutor = new HttpRequestExecutor();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (localServer == null) {
|
if (localServer == null) {
|
||||||
|
|
Loading…
Reference in New Issue