hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1407784 - in /httpcomponents/httpcore/trunk: httpcore-ab/src/main/java/org/apache/http/benchmark/ httpcore/src/examples/org/apache/http/examples/ httpcore/src/main/java/org/apache/http/protocol/ httpcore/src/test/java/org/apache/http/tests...
Date Sat, 10 Nov 2012 11:57:23 GMT
Author: olegk
Date: Sat Nov 10 11:57:22 2012
New Revision: 1407784

URL: http://svn.apache.org/viewvc?rev=1407784&view=rev
Log:
Tweaked HttpCoreContext and related classes

Modified:
    httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java
    httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java
    httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java
    httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpCoreContext.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestExpectContinue.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestTargetHost.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/HttpClient.java

Modified: httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java?rev=1407784&r1=1407783&r2=1407784&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java
Sat Nov 10 11:57:22 2012
@@ -113,7 +113,7 @@ class BenchmarkWorker implements Runnabl
         }
 
         // Populate the execution context
-        this.context.setTarget(this.targetHost);
+        this.context.setTargetHost(this.targetHost);
 
         stats.start();
         int count = config.getRequests();

Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java?rev=1407784&r1=1407783&r2=1407784&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java
Sat Nov 10 11:57:22 2012
@@ -69,7 +69,7 @@ public class ElementalHttpGet {
 
         HttpCoreContext context = new HttpCoreContext();
         HttpHost host = new HttpHost("localhost", 8080);
-        context.setTarget(host);
+        context.setTargetHost(host);
         context.setExpectContinue();
 
         DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024);

Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java?rev=1407784&r1=1407783&r2=1407784&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java
Sat Nov 10 11:57:22 2012
@@ -74,7 +74,7 @@ public class ElementalHttpPost {
 
         HttpCoreContext context = new HttpCoreContext();
         HttpHost host = new HttpHost("localhost", 8080);
-        context.setTarget(host);
+        context.setTargetHost(host);
         context.setExpectContinue();
 
         DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024);

Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java?rev=1407784&r1=1407783&r2=1407784&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java
Sat Nov 10 11:57:22 2012
@@ -102,7 +102,7 @@ public class ElementalPoolingHttpGet {
                     try {
                         HttpClientConnection conn = entry.getConnection();
                         HttpCoreContext context = new HttpCoreContext();
-                        context.setTarget(this.target);
+                        context.setTargetHost(this.target);
 
                         BasicHttpRequest request = new BasicHttpRequest("GET", "/");
                         System.out.println(">> Request URI: " + request.getRequestLine().getUri());

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpCoreContext.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpCoreContext.java?rev=1407784&r1=1407783&r2=1407784&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpCoreContext.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpCoreContext.java
Sat Nov 10 11:57:22 2012
@@ -41,7 +41,40 @@ import org.apache.http.util.Args;
  * @since 4.3
  */
 @NotThreadSafe
-public class HttpCoreContext extends BasicHttpContext implements ExecutionContext {
+public class HttpCoreContext implements HttpContext, ExecutionContext {
+
+    public static HttpCoreContext adapt(final HttpContext context) {
+        Args.notNull(context, "HTTP context");
+        if (context instanceof HttpCoreContext) {
+            return (HttpCoreContext) context;
+        } else {
+            return new HttpCoreContext(context);
+        }
+    }
+
+    private final HttpContext context;
+
+    public HttpCoreContext(final HttpContext context) {
+        super();
+        this.context = context;
+    }
+
+    public HttpCoreContext() {
+        super();
+        this.context = new BasicHttpContext();
+    }
+
+    public Object getAttribute(final String id) {
+        return context.getAttribute(id);
+    }
+
+    public void setAttribute(final String id, final Object obj) {
+        context.setAttribute(id, obj);
+    }
+
+    public Object removeAttribute(final String id) {
+        return context.removeAttribute(id);
+    }
 
     protected <T> T getAttribute(final String attribname, final Class<T> clazz)
{
         Args.notNull(clazz, "Attribute class");
@@ -56,6 +89,10 @@ public class HttpCoreContext extends Bas
         return getAttribute(HTTP_CONNECTION, clazz);
     }
 
+    public HttpConnection getConnection() {
+        return getAttribute(HTTP_CONNECTION, HttpConnection.class);
+    }
+
     public boolean isExpectContinue() {
         Boolean b = getAttribute(HTTP_EXPECT_CONT, Boolean.class);
         return b != null ? b.booleanValue() : false;
@@ -78,11 +115,11 @@ public class HttpCoreContext extends Bas
         return getAttribute(HTTP_RESPONSE, HttpResponse.class);
     }
 
-    public void setTarget(final HttpHost host) {
+    public void setTargetHost(final HttpHost host) {
         setAttribute(HTTP_TARGET_HOST, host);
     }
 
-    public HttpHost getTarget() {
+    public HttpHost getTargetHost() {
         return getAttribute(HTTP_TARGET_HOST, HttpHost.class);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestExpectContinue.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestExpectContinue.java?rev=1407784&r1=1407783&r2=1407784&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestExpectContinue.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestExpectContinue.java
Sat Nov 10 11:57:22 2012
@@ -37,8 +37,7 @@ import org.apache.http.HttpRequestInterc
 import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.annotation.Immutable;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.util.Args;
 
 /**
@@ -48,8 +47,8 @@ import org.apache.http.util.Args;
  *
  * @since 4.0
  */
-@SuppressWarnings("deprecation")
 @Immutable
+@SuppressWarnings("deprecation")
 public class RequestExpectContinue implements HttpRequestInterceptor {
 
     public RequestExpectContinue() {
@@ -59,21 +58,17 @@ public class RequestExpectContinue imple
     public void process(final HttpRequest request, final HttpContext context)
             throws HttpException, IOException {
         Args.notNull(request, "HTTP request");
+
+        HttpCoreContext corecontext = HttpCoreContext.adapt(context);
+
         if (!request.containsHeader(HTTP.EXPECT_DIRECTIVE)) {
             if (request instanceof HttpEntityEnclosingRequest) {
                 ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
                 HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
                 // Do not send the expect header if request body is known to be empty
                 if (entity != null && entity.getContentLength() != 0 && !ver.lessEquals(HttpVersion.HTTP_1_0))
{
-                    Boolean useExpectCont = null;
-                    HttpParams params = request.getParams();
-                    if (params != null) {
-                        useExpectCont = (Boolean) params.getParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE);
-                    }
-                    if (useExpectCont == null) {
-                        useExpectCont = (Boolean ) context.getAttribute(ExecutionContext.HTTP_EXPECT_CONT);
-                    }
-                    if (useExpectCont != null && useExpectCont.booleanValue()) {
+                    if (corecontext.isExpectContinue()
+                            || HttpProtocolParams.useExpectContinue(request.getParams()))
{
                         request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
                     }
                 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestTargetHost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestTargetHost.java?rev=1407784&r1=1407783&r2=1407784&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestTargetHost.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestTargetHost.java
Sat Nov 10 11:57:22 2012
@@ -58,7 +58,8 @@ public class RequestTargetHost implement
     public void process(final HttpRequest request, final HttpContext context)
             throws HttpException, IOException {
         Args.notNull(request, "HTTP request");
-        Args.notNull(context, "HTTP context");
+
+        HttpCoreContext corecontext = HttpCoreContext.adapt(context);
 
         ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
         String method = request.getRequestLine().getMethod();
@@ -67,11 +68,9 @@ public class RequestTargetHost implement
         }
 
         if (!request.containsHeader(HTTP.TARGET_HOST)) {
-            HttpHost targethost = (HttpHost) context
-                .getAttribute(ExecutionContext.HTTP_TARGET_HOST);
+            HttpHost targethost = corecontext.getTargetHost();
             if (targethost == null) {
-                HttpConnection conn = (HttpConnection) context
-                    .getAttribute(ExecutionContext.HTTP_CONNECTION);
+                HttpConnection conn = corecontext.getConnection();
                 if (conn instanceof HttpInetConnection) {
                     // Populate the context with a default HTTP host based on the
                     // inet address of the target host

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java?rev=1407784&r1=1407783&r2=1407784&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java
Sat Nov 10 11:57:22 2012
@@ -59,7 +59,9 @@ public class ResponseConnControl impleme
     public void process(final HttpResponse response, final HttpContext context)
             throws HttpException, IOException {
         Args.notNull(response, "HTTP response");
-        Args.notNull(context, "HTTP context");
+
+        HttpCoreContext corecontext = HttpCoreContext.adapt(context);
+
         // Always drop connection after certain type of responses
         int status = response.getStatusLine().getStatusCode();
         if (status == HttpStatus.SC_BAD_REQUEST ||
@@ -89,8 +91,7 @@ public class ResponseConnControl impleme
             }
         }
         // Drop connection if requested by the client or request was <= 1.0
-        HttpRequest request = (HttpRequest)
-            context.getAttribute(ExecutionContext.HTTP_REQUEST);
+        HttpRequest request = corecontext.getRequest();
         if (request != null) {
             Header header = request.getFirstHeader(HTTP.CONN_DIRECTIVE);
             if (header != null) {

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/HttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/HttpClient.java?rev=1407784&r1=1407783&r2=1407784&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/HttpClient.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/HttpClient.java
Sat Nov 10 11:57:22 2012
@@ -107,7 +107,7 @@ public class HttpClient {
             final HttpRequest request,
             final HttpHost targetHost,
             final HttpClientConnection conn) throws HttpException, IOException {
-        this.context.setTarget(targetHost);
+        this.context.setTargetHost(targetHost);
         this.httpexecutor.preProcess(request, this.httpproc, this.context);
         HttpResponse response = this.httpexecutor.execute(request, conn, this.context);
         this.httpexecutor.postProcess(response, this.httpproc, this.context);



Mime
View raw message