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:
Oleg Kalnichevski 2007-05-28 13:34:30 +00:00
parent 53e4063593
commit 7813fd1197
6 changed files with 27 additions and 30 deletions

View File

@ -79,6 +79,7 @@ import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.message.BasicHttpRequest;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpParamsLinker;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
@ -177,7 +178,7 @@ public class DefaultClientRequestDirector
this.redirectHandler = redirectHandler;
this.authHandler = authHandler;
this.params = params;
this.requestExec = new HttpRequestExecutor(params);
this.requestExec = new HttpRequestExecutor();
this.managedConn = null;
@ -254,10 +255,7 @@ public class DefaultClientRequestDirector
throws HttpException, IOException {
HttpRequest orig = roureq.getRequest();
// Link parameter collections to form a hierarchy:
// request -> client
orig.getParams().setDefaults(this.params);
HttpParamsLinker.link(orig, this.params);
// Add default headers
Collection defHeaders = (Collection) orig.getParams().getParameter(
@ -335,8 +333,6 @@ public class DefaultClientRequestDirector
targetAuthState);
context.setAttribute(HttpClientContext.PROXY_AUTH_STATE,
proxyAuthState);
//@@@ review parameter hierachy building
request.getParams().setDefaults(requestExec.getParams());
requestExec.preProcess(request, httpProcessor, context);
if (orig instanceof AbortableHttpRequest) {
@ -371,10 +367,7 @@ public class DefaultClientRequestDirector
throw ex;
}
// Link parameter collections to form a hierarchy:
// response -> client
response.getParams().setDefaults(this.params);
HttpParamsLinker.link(request, this.params);
requestExec.postProcess(response, httpProcessor, context);
RoutedRequest followup =
@ -484,13 +477,13 @@ public class DefaultClientRequestDirector
case RouteDirector.CONNECT_TARGET:
case RouteDirector.CONNECT_PROXY:
managedConn.open(route, context, requestExec.getParams());
managedConn.open(route, context, this.params);
break;
case RouteDirector.TUNNEL_TARGET:
boolean secure = createTunnel(route, context);
LOG.debug("Tunnel created");
managedConn.tunnelCreated(secure, requestExec.getParams());
managedConn.tunnelCreated(secure, this.params);
break;
case RouteDirector.TUNNEL_PROXY:
@ -498,7 +491,7 @@ public class DefaultClientRequestDirector
("Proxy chains are not supported.");
case RouteDirector.LAYER_PROTOCOL:
managedConn.layerProtocol(context, requestExec.getParams());
managedConn.layerProtocol(context, this.params);
break;
case RouteDirector.UNREACHABLE:

View File

@ -102,7 +102,6 @@ public class ExecReqThread extends GetConnThread {
HttpRequest request = (HttpRequest) request_spec.context.
getAttribute(HttpExecutionContext.HTTP_REQUEST);
request.getParams().setDefaults(request_spec.executor.getParams());
request_spec.executor.preProcess
(request, request_spec.processor, request_spec.context);

View File

@ -34,6 +34,8 @@ import org.apache.http.HttpClientConnection;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
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.HttpExecutionContext;
import org.apache.http.protocol.HttpProcessor;
@ -59,6 +61,7 @@ public final class Helper {
HttpHost target,
HttpRequestExecutor exec,
HttpProcessor proc,
HttpParams params,
HttpContext ctxt)
throws Exception {
@ -66,9 +69,10 @@ public final class Helper {
ctxt.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, target);
ctxt.setAttribute(HttpExecutionContext.HTTP_REQUEST, req);
req.getParams().setDefaults(exec.getParams());
HttpParamsLinker.link(req, params);
exec.preProcess(req, proc, ctxt);
HttpResponse rsp = exec.execute(req, conn, ctxt);
HttpParamsLinker.link(rsp, params);
exec.postProcess(rsp, proc, ctxt);
return rsp;

View File

@ -42,6 +42,7 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.localserver.LocalTestServer;
import org.apache.http.localserver.ServerTestBase;
import org.apache.http.params.HttpParamsLinker;
import org.apache.http.protocol.HttpExecutionContext;
import org.apache.http.util.EntityUtils;
@ -85,12 +86,13 @@ public class TestLocalServer extends ServerTestBase {
HttpExecutionContext.HTTP_TARGET_HOST, target);
httpContext.setAttribute(
HttpExecutionContext.HTTP_REQUEST, request);
request.getParams().setDefaults(httpExecutor.getParams());
HttpParamsLinker.link(request, defaultParams);
httpExecutor.preProcess
(request, httpProcessor, httpContext);
HttpResponse response = httpExecutor.execute
(request, conn, httpContext);
HttpParamsLinker.link(response, defaultParams);
httpExecutor.postProcess
(response, httpProcessor, httpContext);
@ -127,12 +129,13 @@ public class TestLocalServer extends ServerTestBase {
HttpExecutionContext.HTTP_TARGET_HOST, target);
httpContext.setAttribute(
HttpExecutionContext.HTTP_REQUEST, request);
request.getParams().setDefaults(httpExecutor.getParams());
HttpParamsLinker.link(request, defaultParams);
httpExecutor.preProcess
(request, httpProcessor, httpContext);
HttpResponse response = httpExecutor.execute
(request, conn, httpContext);
HttpParamsLinker.link(response, defaultParams);
httpExecutor.postProcess
(response, httpProcessor, httpContext);

View File

@ -194,8 +194,9 @@ public class TestTSCCMWithServer extends ServerTestBase {
conn.open(route, httpContext, defaultParams);
// a new context is created for each testcase, no need to reset
HttpResponse response = Helper.execute
(request, conn, target, httpExecutor, httpProcessor, httpContext);
HttpResponse response = Helper.execute(
request, conn, target,
httpExecutor, httpProcessor, defaultParams, httpContext);
assertEquals("wrong status in first response",
HttpStatus.SC_OK,
@ -282,8 +283,8 @@ public class TestTSCCMWithServer extends ServerTestBase {
conn.open(route, httpContext, defaultParams);
// a new context is created for each testcase, no need to reset
HttpResponse response = Helper.execute
(request, conn, target, httpExecutor, httpProcessor, httpContext);
Helper.execute(request, conn, target,
httpExecutor, httpProcessor, defaultParams, httpContext);
// we leave the connection in mid-use
// 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.
WeakReference wref = new WeakReference(conn);
conn = null;
response = null;
httpContext = null; // holds a reference to the connection
// 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);
// a new context is created for each testcase, no need to reset
HttpResponse response = Helper.execute
(request, conn, target, httpExecutor, httpProcessor, httpContext);
byte[] data = EntityUtils.toByteArray(response.getEntity());
HttpResponse response = Helper.execute(request, conn, target,
httpExecutor, httpProcessor, defaultParams, httpContext);
EntityUtils.toByteArray(response.getEntity());
// release connection after marking it for re-use
conn.markReusable();

View File

@ -110,7 +110,6 @@ public abstract class ServerTestBase extends TestCase {
*/
protected void setUp() throws Exception {
boolean newparams = false;
if (defaultParams == null) {
defaultParams = new BasicHttpParams(null);
HttpProtocolParams.setVersion
@ -121,7 +120,6 @@ public abstract class ServerTestBase extends TestCase {
(defaultParams, "Jakarta-HttpComponents-Test/1.1");
HttpProtocolParams.setUseExpectContinue
(defaultParams, false);
newparams = true;
}
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
httpContext = new HttpExecutionContext(null);
if ((httpExecutor == null) || newparams) {
httpExecutor = new HttpRequestExecutor(defaultParams);
if (httpExecutor == null) {
httpExecutor = new HttpRequestExecutor();
}
if (localServer == null) {