You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2006/08/26 19:08:23 UTC
svn commit: r437181 - in
/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async: ./
impl/
Author: rolandw
Date: Sat Aug 26 10:08:22 2006
New Revision: 437181
URL: http://svn.apache.org/viewvc?rev=437181&view=rev
Log:
refactored AsyncHttpProcessor, AbstractHttpDispatcher to prepare for configurable preprocessing thread
Modified:
jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AbstractHttpDispatcher.java
jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AbstractHttpHandle.java
jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AsyncHttpProcessor.java
jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcher.java
jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpHandle.java
jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpNotificationHandler.java
jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/NotificationResponseWrapper.java
jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java
jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpHandle.java
Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AbstractHttpDispatcher.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AbstractHttpDispatcher.java?rev=437181&r1=437180&r2=437181&view=diff
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AbstractHttpDispatcher.java (original)
+++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AbstractHttpDispatcher.java Sat Aug 26 10:08:22 2006
@@ -39,12 +39,18 @@
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpExecutionContext;
+
/**
* Abstract base for implementations of {@link HttpDispatcher HttpDispatcher}.
* Provides access to protected methods in
* {@link AsyncHttpProcessor AsyncHttpProcessor}.
*
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ *
+ * <!-- empty lines above to avoid 'svn diff' context problems -->
* @version $Revision$ $Date$
*
* @since 4.0
@@ -53,6 +59,15 @@
/**
+ * Context attribute indicating whether a request is preprocessed.
+ * Set to a {@link Boolean Boolean} <code>true</code> when preprocessed.
+ * <!-- @@@ find a better place for this definition -->
+ */
+ public final static String CTXT_REQUEST_PREPROCESSED =
+ "http.request.preprocessed";
+
+
+ /**
* All handles linked to this dispatcher.
* This is assumed to be used as a set, but declared a collection to
* avoid the overhead of duplicate checking. A set implementation can
@@ -117,12 +132,9 @@
/**
- * Prepare a request for sending.
- * Maps to
- * {@link AsyncHttpProcessor#doPrepareRequest proc.doPrepareRequest}.
+ * Prepares a new request specific context.
*
- * @param proc the processor to use for preparing
- * @param request the request to prepare
+ * @param proc the processor to be used for executing the request
* @param target the target host for the request
* @param context the parent context for sending the request,
* or <code>null</code> to use the default context
@@ -130,15 +142,66 @@
* @return a new context specific to the request
*
* @throws HttpException if the request can not be prepared
- * @throws IOException in case of an IO problem
*/
- protected static HttpContext prepareRequest(AsyncHttpProcessor proc,
- HttpRequest request,
+ protected static HttpContext prepareContext(AsyncHttpProcessor proc,
HttpHost target,
HttpContext context)
+ throws HttpException {
+
+ if (proc == null)
+ throw new IllegalArgumentException
+ ("HTTP processor must not be null.");
+ if (target == null)
+ throw new IllegalArgumentException
+ ("Target host must not be null.");
+
+ if (context == null)
+ context = proc.getContext(); // default context
+
+ HttpExecutionContext hxc = new HttpExecutionContext(context);
+ hxc.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, target);
+
+ return hxc;
+
+ } // prepareContext
+
+
+ /**
+ * Prepares a request for sending.
+ * This performs preprocessing on the request.
+ *
+ * @param proc the processor to use for preparing
+ * @param request the request to prepare
+ * @param context the request specific context
+ *
+ * @throws HttpException if the request can not be prepared
+ * @throws IOException in case of an IO problem
+ */
+ protected static void prepareRequest(AsyncHttpProcessor proc,
+ HttpRequest request,
+ HttpContext context)
throws HttpException, IOException {
- return proc.asyncPrepareRequest(request, target, context);
+ if (proc == null)
+ throw new IllegalArgumentException
+ ("HTTP processor must not be null.");
+ if (request == null)
+ throw new IllegalArgumentException
+ ("Request must not be null.");
+ if (context == null)
+ throw new IllegalArgumentException
+ ("Context must not be null.");
+
+ if (Boolean.TRUE
+ .equals(context.getAttribute(CTXT_REQUEST_PREPROCESSED)))
+ throw new IllegalArgumentException
+ ("Request already preprocessed.");
+
+ context.setAttribute(HttpExecutionContext.HTTP_REQUEST, request);
+ // set the flag before preprocessing, in case we get an exception
+ context.setAttribute(CTXT_REQUEST_PREPROCESSED, Boolean.TRUE);
+
+ proc.doPrepareRequest(request, context);
} // prepareRequest
Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AbstractHttpHandle.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AbstractHttpHandle.java?rev=437181&r1=437180&r2=437181&view=diff
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AbstractHttpHandle.java (original)
+++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AbstractHttpHandle.java Sat Aug 26 10:08:22 2006
@@ -39,7 +39,7 @@
/**
* Base class for implementations of {@link HttpHandle HttpHandle}.
*
- * @author <a href="mailto:http-async at dubioso.net">Roland Weber</a>
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
*
*
* <!-- empty lines above to avoid 'svn diff' context problems -->
Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AsyncHttpProcessor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AsyncHttpProcessor.java?rev=437181&r1=437180&r2=437181&view=diff
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AsyncHttpProcessor.java (original)
+++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/AsyncHttpProcessor.java Sat Aug 26 10:08:22 2006
@@ -42,12 +42,13 @@
import org.apache.http.protocol.HttpExecutionContext;
import org.apache.http.protocol.HttpRequestExecutor;
+
/**
* HTTP processor for asynchronously dispatched requests.
* This is the asynchronous version of
* {@link org.apache.http.protocol.HttpRequestExecutor HttpRequestExecutor}.
*
- * @author <a href="mailto:http-async at dubioso.net">Roland Weber</a>
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
*
*
* <!-- empty lines above to avoid 'svn diff' context problems -->
@@ -75,38 +76,13 @@
}
- /**
- * Prepare a request for sending.
- *
- * @param request the request to prepare
- * @param target the target host for the request
- * @param context the parent context for sending the request,
- * or <code>null</code> to use the default context
- *
- * @return a new context specific to the request
- *
- * @throws HttpException if the request can not be prepared
- * @throws IOException in case of an IO problem
- */
- protected HttpContext asyncPrepareRequest(HttpRequest request,
- HttpHost target,
- HttpContext context)
+ // non-javadoc, see base class HttpRequestExecutor
+ // make protected method accessible in this package, too
+ protected void doPrepareRequest(final HttpRequest request,
+ final HttpContext context)
throws HttpException, IOException {
-
- if (context == null)
- context = getContext(); // default context
-
- HttpExecutionContext hxc = new HttpExecutionContext(context);
- hxc.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, target);
-
- // argument checking is done here...
- super.doPrepareRequest(request, hxc);
-
- hxc.setAttribute(HttpExecutionContext.HTTP_REQUEST, request);
-
- return hxc;
-
- } // asyncPrepareRequest
+ super.doPrepareRequest(request, context);
+ }
/**
Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcher.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcher.java?rev=437181&r1=437180&r2=437181&view=diff
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcher.java (original)
+++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpDispatcher.java Sat Aug 26 10:08:22 2006
@@ -56,6 +56,10 @@
* that callbacks return swiftly. Prolonged processing of responses
* MUST be delegated from the callbacks to application threads.
*
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ *
+ * <!-- empty lines above to avoid 'svn diff' context problems -->
* @version $Revision$ $Date$
*
* @since 4.0
Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpHandle.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpHandle.java?rev=437181&r1=437180&r2=437181&view=diff
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpHandle.java (original)
+++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpHandle.java Sat Aug 26 10:08:22 2006
@@ -42,6 +42,10 @@
/**
* Represents a {@link HttpDispatcher dispatched} HTTP request.
*
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ *
+ * <!-- empty lines above to avoid 'svn diff' context problems -->
* @version $Revision$ $Date$
*
* @since 4.0
Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpNotificationHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpNotificationHandler.java?rev=437181&r1=437180&r2=437181&view=diff
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpNotificationHandler.java (original)
+++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpNotificationHandler.java Sat Aug 26 10:08:22 2006
@@ -74,7 +74,7 @@
* while handles for responses with non-error status codes are routed
* to a third queue.
*
- * @author <a href="mailto:http-async at dubioso.net">Roland Weber</a>
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
*
*
* <!-- empty lines above to avoid 'svn diff' context problems -->
Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/NotificationResponseWrapper.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/NotificationResponseWrapper.java?rev=437181&r1=437180&r2=437181&view=diff
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/NotificationResponseWrapper.java (original)
+++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/NotificationResponseWrapper.java Sat Aug 26 10:08:22 2006
@@ -47,7 +47,7 @@
* and this wrapper will not allow it to.
*
*
- * @author <a href="mailto:http-async at dubioso.net">Roland Weber</a>
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
*
*
* <!-- empty lines above to avoid 'svn diff' context problems -->
Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java?rev=437181&r1=437180&r2=437181&view=diff
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java (original)
+++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java Sat Aug 26 10:08:22 2006
@@ -66,7 +66,7 @@
* <li>{@link #response_handle_monitor response_handle_monitor}</li>
* </ol>
*
- * @author <a href="mailto:http-async at dubioso.net">Roland Weber</a>
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
*
*
* <!-- empty lines above to avoid 'svn diff' context problems -->
@@ -177,9 +177,11 @@
//@@@ check whether target is suitable:
//@@@ - for now: no proxy (how to indicate proxy in the first place?)
- HttpContext ctxt = prepareRequest
- (async_processor, request, target, context);
+ HttpContext ctxt = prepareContext(async_processor, target, context);
SimpleHttpHandle hdl = new SimpleHttpHandle(this, request, ctxt);
+
+ //@@@ check with params whether to preprocess here or later
+ prepareRequest(async_processor, request, ctxt);
// linked handles need to be tracked for abortAll()
synchronized (linked_handle_monitor) {
Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpHandle.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpHandle.java?rev=437181&r1=437180&r2=437181&view=diff
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpHandle.java (original)
+++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpHandle.java Sat Aug 26 10:08:22 2006
@@ -44,7 +44,7 @@
* Handles for the {@link SimpleHttpDispatcher SimpleHttpDispatcher}.
*
*
- * @author <a href="mailto:http-async at dubioso.net">Roland Weber</a>
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
*
*
* <!-- empty lines above to avoid 'svn diff' context problems -->