hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r180105 - in /jakarta/httpclient/trunk/http-common/src: examples/org/apache/http/examples/ java/org/apache/http/ java/org/apache/http/executor/ java/org/apache/http/impl/ java/org/apache/http/interceptor/
Date Sun, 05 Jun 2005 16:04:01 GMT
Author: olegk
Date: Sun Jun  5 09:03:59 2005
New Revision: 180105

URL: http://svn.apache.org/viewcvs?rev=180105&view=rev
Log:
Several minor tweaks to HttpRequestExecutor, DefaultHttpClientConnection to make them more
method DI freindly

Modified:
    jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpClientConnection.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRequestFactory.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpRequestExecutor.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpParams.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpRequestFactory.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/interceptor/RequestTargetHost.java

Modified: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java?rev=180105&r1=180104&r2=180105&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java
Sun Jun  5 09:03:59 2005
@@ -77,14 +77,15 @@
             .setContentCharset("UTF-8")
             .setUserAgent("Jakarta HTTP Demo");
         
-        HttpRequestExecutor httpexecutor = new HttpRequestExecutor(params);
+        HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
+        httpexecutor.setParams(params);
         // Required request interceptors
-        httpexecutor.setRequestInterceptor(new RequestContent());
-        httpexecutor.setRequestInterceptor(new RequestTargetHost());
+        httpexecutor.addRequestInterceptor(new RequestContent());
+        httpexecutor.addRequestInterceptor(new RequestTargetHost());
         // Recommended request interceptors
-        httpexecutor.setRequestInterceptor(new RequestConnControl());
-        httpexecutor.setRequestInterceptor(new RequestUserAgent());
-        httpexecutor.setRequestInterceptor(new RequestExpectContinue());
+        httpexecutor.addRequestInterceptor(new RequestConnControl());
+        httpexecutor.addRequestInterceptor(new RequestUserAgent());
+        httpexecutor.addRequestInterceptor(new RequestExpectContinue());
         
         HttpHost host = new HttpHost("www.yahoo.com");
         HttpClientConnection conn = new DefaultHttpClientConnection(host);

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpClientConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpClientConnection.java?rev=180105&r1=180104&r2=180105&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpClientConnection.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpClientConnection.java
Sun Jun  5 09:03:59 2005
@@ -30,6 +30,7 @@
 package org.apache.http;
 
 import java.io.IOException;
+import java.net.InetAddress;
 
 import org.apache.http.params.HttpParams;
 
@@ -44,7 +45,13 @@
  */
 public interface HttpClientConnection extends HttpConnection {
 
-    HttpHost getHost();
+    HttpHost getTargetHost();
+    
+    void setTargetHost(HttpHost targethost);
+    
+    InetAddress getLocalAddress();
+    
+    void setLocalAddress(InetAddress localAddress);
     
     void open(HttpParams params) throws IOException;
     

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRequestFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRequestFactory.java?rev=180105&r1=180104&r2=180105&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRequestFactory.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRequestFactory.java
Sun Jun  5 09:03:59 2005
@@ -43,4 +43,7 @@
     HttpMutableRequest newHttpRequest(RequestLine requestline) 
         throws MethodNotSupportedException;
     
+    HttpMutableRequest newHttpRequest(String method, String uri) 
+    	throws MethodNotSupportedException;
+    
 }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpRequestExecutor.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpRequestExecutor.java?rev=180105&r1=180104&r2=180105&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpRequestExecutor.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpRequestExecutor.java
Sun Jun  5 09:03:59 2005
@@ -57,26 +57,30 @@
  */
 public class HttpRequestExecutor {
 
-    private final HttpParams params;
     private final HttpContext localContext;
     
+    private HttpParams params = null;
     private HttpRequestRetryHandler retryhandler = null;
     private Set interceptors = null; 
     
-    public HttpRequestExecutor(final HttpParams params, final HttpContext parentContext)
{
+    public HttpRequestExecutor(final HttpContext parentContext) {
         super();
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
-        }
-        this.params = params;
         this.localContext = new HttpExecutionContext(parentContext);
     }
     
-    public HttpRequestExecutor(final HttpParams params) {
-        this(params, null);
+    public HttpRequestExecutor() {
+        this(null);
+    }
+    
+    public HttpParams getParams() {
+        return this.params;
+    }
+
+    public void setParams(final HttpParams params) {
+        this.params = params;
     }
     
-    private void setInterceptor(final Object obj) {
+    private void addInterceptor(final Object obj) {
         if (obj == null) {
             return;
         }
@@ -99,12 +103,12 @@
         }
     }
     
-    public void setRequestInterceptor(final HttpRequestInterceptor interceptor) {
-        setInterceptor(interceptor);
+    public void addRequestInterceptor(final HttpRequestInterceptor interceptor) {
+        addInterceptor(interceptor);
     }
     
-    public void setResponseInterceptor(final HttpResponseInterceptor interceptor) {
-        setInterceptor(interceptor);
+    public void addResponseInterceptor(final HttpResponseInterceptor interceptor) {
+        addInterceptor(interceptor);
     }
 
     public void removeRequestInterceptor(final HttpRequestInterceptor interceptor) {
@@ -129,6 +133,18 @@
         }
     }
     
+    public void setInterceptors(final Set interceptors) {
+        if (interceptors == null) {
+            return;
+        }
+        if (this.interceptors != null) {
+            this.interceptors.clear();
+            this.interceptors.addAll(interceptors);
+        } else {
+            this.interceptors = new HashSet(interceptors);
+        }
+    }
+    
     public HttpRequestRetryHandler getRetryHandler() {
         return this.retryhandler;
     }
@@ -177,7 +193,8 @@
         
         this.localContext.setAttribute(HttpExecutionContext.HTTP_REQUEST, request);
         this.localContext.setAttribute(HttpExecutionContext.HTTP_CONNECTION, conn);
-        this.localContext.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, conn.getHost());
+        this.localContext.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, 
+        		conn.getTargetHost());
 
         // Link own parameters as defaults 
         request.getParams().setDefaults(this.params);

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java?rev=180105&r1=180104&r2=180105&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
Sun Jun  5 09:03:59 2005
@@ -74,8 +74,8 @@
     private static final String EXPECT_CONTINUE = "100-Continue";
     private static final int WAIT_FOR_CONTINUE_MS = 10000;
     
-    private final HttpHost targethost;
-    private final InetAddress localAddress;
+    private HttpHost targethost = null;
+    private InetAddress localAddress = null;
 
     /*
      * Dependent interfaces
@@ -84,9 +84,6 @@
     
     public DefaultHttpClientConnection(final HttpHost targethost, final InetAddress localAddress)
{
         super();
-        if (targethost == null) {
-            throw new IllegalArgumentException("Target host may not be null");
-        }
         this.targethost = targethost;
         this.localAddress = localAddress;
         this.responsefactory = new DefaultHttpResponseFactory();
@@ -96,6 +93,10 @@
         this(targethost, null);
     }
     
+    public DefaultHttpClientConnection() {
+        this(null, null);
+    }
+    
     public void setResponseFactory(final HttpResponseFactory responsefactory) {
         if (responsefactory == null) {
             throw new IllegalArgumentException("Factory may not be null");
@@ -108,8 +109,10 @@
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
         assertNotOpen();
-        
-        SocketFactory socketfactory = targethost.getProtocol().getSocketFactory();
+        if (this.targethost == null) {
+        	throw new IllegalStateException("Target host not specified");
+        }
+        SocketFactory socketfactory = this.targethost.getProtocol().getSocketFactory();
         Socket socket = socketfactory.createSocket(
                 this.targethost.getHostName(), this.targethost.getPort(), 
                 this.localAddress, 0, 
@@ -117,8 +120,25 @@
         bind(socket, params);
     }
     
-    public HttpHost getHost() {
+    public HttpHost getTargetHost() {
         return this.targethost;
+    }
+    
+    public InetAddress getLocalAddress() {
+        return this.localAddress;
+    }
+    
+    public void setTargetHost(final HttpHost targethost) {
+    	if (targethost == null) {
+    		throw new IllegalArgumentException("Target host may not be null");
+    	}
+    	assertNotOpen();
+    	this.targethost = targethost;
+    }
+    
+    public void setLocalAddress(final InetAddress localAddress) {
+    	assertNotOpen();
+    	this.localAddress = localAddress;
     }
     
     public void close() throws IOException {

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpParams.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpParams.java?rev=180105&r1=180104&r2=180105&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpParams.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpParams.java
Sun Jun  5 09:03:59 2005
@@ -68,6 +68,10 @@
         this.defaults = defaults; 
     }
     
+    public DefaultHttpParams() {
+        this(null);
+    }
+
     public synchronized HttpParams getDefaults() {
         return this.defaults;
     }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpRequestFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpRequestFactory.java?rev=180105&r1=180104&r2=180105&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpRequestFactory.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpRequestFactory.java
Sun Jun  5 09:03:59 2005
@@ -63,5 +63,17 @@
             throw new MethodNotSupportedException(method +  " method not supported");
         }
     }
+
+    public HttpMutableRequest newHttpRequest(final String method, final String uri)
+			throws MethodNotSupportedException {
+		if ("GET".equalsIgnoreCase(method)) {
+			return new BasicHttpRequest(method, uri);
+		} else if ("POST".equalsIgnoreCase(method)) {
+			return new BasicHttpEntityEnclosingRequest(method, uri);
+		} else {
+			throw new MethodNotSupportedException(method
+					+ " method not supported");
+		}
+    }
     
 }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/interceptor/RequestTargetHost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/interceptor/RequestTargetHost.java?rev=180105&r1=180104&r2=180105&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/interceptor/RequestTargetHost.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/interceptor/RequestTargetHost.java
Sun Jun  5 09:03:59 2005
@@ -68,6 +68,9 @@
         if (!request.containsHeader(TARGET_HOST)) {
             HttpHost targethost = (HttpHost) context
                 .getAttribute(HttpExecutionContext.HTTP_TARGET_HOST);
+            if (targethost == null) {
+            	return;
+            }
             HttpProtocolParams params = new HttpProtocolParams(request.getParams());
             String virtualhost = params.getVirtualHost();
             if (virtualhost != null) {



Mime
View raw message