Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Upgraded HttpCore to 4.2-beta1

  • Loading branch information...
commit cd7f9317b04a2535c182398de8d43558b993652f 1 parent 19ab830
@ok2c ok2c authored
Showing with 272 additions and 227 deletions.
  1. +2 −0  .gitignore
  2. +8 −8 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractHttpAsyncClient.java
  3. +32 −24 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
  4. +6 −6 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java
  5. +1 −1  httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIOReactorExceptionHandler.java
  6. +21 −20 ...org/apache/http/impl/nio/client/{LoggingClientProtocolHandler.java → LoggingAsyncRequestExecutor.java}
  7. +4 −4 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java
  8. +1 −1  httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/LoggingIOSession.java
  9. +11 −3 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java
  10. +19 −24 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
  11. +15 −12 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/BaseZeroCopyRequestProducer.java
  12. +6 −3 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java
  13. +15 −5 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/ZeroCopyConsumer.java
  14. +1 −3 httpasyncclient/src/main/java/org/apache/http/nio/conn/OperatedAsyncClientConnection.java
  15. +2 −2 httpasyncclient/src/test/java/org/apache/http/HttpAsyncTestBase.java
  16. +23 −24 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestClientAuthentication.java
  17. +12 −10 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java
  18. +2 −2 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java
  19. +2 −2 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsRedirects.java
  20. +28 −26 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestRedirects.java
  21. +19 −9 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestStatefulConnManagement.java
  22. +11 −10 httpasyncclient/src/test/java/org/apache/http/localserver/HttpServerNio.java
  23. +15 −17 httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestAsyncConsumers.java
  24. +15 −10 httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestZeroCopy.java
  25. +1 −1  pom.xml
View
2  .gitignore
@@ -4,3 +4,5 @@
.clover
.externalToolBuilders
target
+maven-eclipse.xml
+
View
16 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractHttpAsyncClient.java
@@ -75,7 +75,7 @@
import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
import org.apache.http.impl.cookie.RFC2109SpecFactory;
import org.apache.http.impl.cookie.RFC2965SpecFactory;
-import org.apache.http.impl.nio.DefaultClientIODispatch;
+import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.conn.DefaultHttpAsyncRoutePlanner;
import org.apache.http.impl.nio.conn.PoolingAsyncClientConnectionManager;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
@@ -83,7 +83,7 @@
import org.apache.http.nio.client.HttpAsyncClient;
import org.apache.http.nio.client.methods.HttpAsyncMethods;
import org.apache.http.nio.conn.ClientAsyncConnectionManager;
-import org.apache.http.nio.protocol.HttpAsyncClientExchangeHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.apache.http.nio.reactor.IOEventDispatch;
@@ -101,7 +101,7 @@
private final Log log = LogFactory.getLog(getClass());;
private final ClientAsyncConnectionManager connmgr;
- private final Queue<HttpAsyncClientExchangeHandler<?>> queue;
+ private final Queue<HttpAsyncRequestExecutionHandler<?>> queue;
private Thread reactorThread;
private BasicHttpProcessor mutableProcessor;
@@ -124,7 +124,7 @@
protected AbstractHttpAsyncClient(final ClientAsyncConnectionManager connmgr) {
super();
this.connmgr = connmgr;
- this.queue = new ConcurrentLinkedQueue<HttpAsyncClientExchangeHandler<?>>();
+ this.queue = new ConcurrentLinkedQueue<HttpAsyncRequestExecutionHandler<?>>();
}
protected AbstractHttpAsyncClient(final IOReactorConfig config) throws IOReactorException {
@@ -132,7 +132,7 @@ protected AbstractHttpAsyncClient(final IOReactorConfig config) throws IOReactor
DefaultConnectingIOReactor defaultioreactor = new DefaultConnectingIOReactor(config);
defaultioreactor.setExceptionHandler(new InternalIOReactorExceptionHandler(this.log));
this.connmgr = new PoolingAsyncClientConnectionManager(defaultioreactor);
- this.queue = new ConcurrentLinkedQueue<HttpAsyncClientExchangeHandler<?>>();
+ this.queue = new ConcurrentLinkedQueue<HttpAsyncRequestExecutionHandler<?>>();
}
protected abstract HttpParams createHttpParams();
@@ -454,16 +454,16 @@ public synchronized void removeRequestInterceptorByClass(Class<? extends HttpReq
}
private void doExecute() {
- LoggingClientProtocolHandler handler = new LoggingClientProtocolHandler();
+ LoggingAsyncRequestExecutor handler = new LoggingAsyncRequestExecutor();
try {
- IOEventDispatch ioEventDispatch = new DefaultClientIODispatch(handler, getParams());
+ IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(handler, getParams());
this.connmgr.execute(ioEventDispatch);
} catch (Exception ex) {
this.log.error("I/O reactor terminated abnormally", ex);
} finally {
this.terminated = true;
while (!this.queue.isEmpty()) {
- HttpAsyncClientExchangeHandler<?> exchangeHandler = this.queue.remove();
+ HttpAsyncRequestExecutionHandler<?> exchangeHandler = this.queue.remove();
exchangeHandler.cancel();
}
}
View
56 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
@@ -80,8 +80,8 @@
import org.apache.http.nio.conn.ClientAsyncConnectionManager;
import org.apache.http.nio.conn.ManagedAsyncClientConnection;
import org.apache.http.nio.conn.scheme.AsyncScheme;
-import org.apache.http.nio.protocol.HttpAsyncClientExchangeHandler;
-import org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.apache.http.params.HttpConnectionParams;
@@ -91,7 +91,7 @@
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessor;
-class DefaultAsyncRequestDirector<T> implements HttpAsyncClientExchangeHandler<T> {
+class DefaultAsyncRequestDirector<T> implements HttpAsyncRequestExecutionHandler<T> {
private final Log log;
@@ -171,6 +171,10 @@ public synchronized void close() throws IOException {
public synchronized void start() {
try {
+
+ this.localContext.setAttribute(ClientContext.TARGET_AUTH_STATE, this.targetAuthState);
+ this.localContext.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyAuthState);
+
HttpHost target = this.requestProducer.getTarget();
HttpRequest request = this.requestProducer.generateRequest();
this.params = new ClientParamsStack(null, this.clientParams, request.getParams(), null);
@@ -229,7 +233,10 @@ public synchronized HttpRequest generateRequest() throws IOException, HttpExcept
target = route.getTargetHost();
}
HttpHost proxy = route.getProxyHost();
-
+ this.localContext.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
+ this.localContext.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy);
+ this.localContext.setAttribute(ExecutionContext.HTTP_CONNECTION, this.managedConn);
+
if (this.currentRequest == null) {
this.currentRequest = this.mainRequest.getRequest();
// Re-write request URI if needed
@@ -238,14 +245,6 @@ public synchronized HttpRequest generateRequest() throws IOException, HttpExcept
// Reset headers on the request wrapper
this.currentRequest.resetHeaders();
- this.localContext.setAttribute(ExecutionContext.HTTP_REQUEST, this.currentRequest);
- this.localContext.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
- this.localContext.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy);
- this.localContext.setAttribute(ExecutionContext.HTTP_CONNECTION, this.managedConn);
- this.localContext.setAttribute(ClientContext.TARGET_AUTH_STATE, this.targetAuthState);
- this.localContext.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyAuthState);
-
- this.httppocessor.process(this.currentRequest, this.localContext);
this.currentRequest.incrementExecCount();
if (this.currentRequest.getExecCount() > 1
&& !this.requestProducer.isRepeatable()
@@ -277,7 +276,7 @@ public boolean isRepeatable() {
return this.requestProducer.isRepeatable();
}
- public void resetRequest() {
+ public void resetRequest() throws IOException {
this.requestProducer.resetRequest();
}
@@ -288,8 +287,6 @@ public synchronized void responseReceived(
}
this.currentResponse = response;
this.currentResponse.setParams(this.params);
- this.localContext.setAttribute(ExecutionContext.HTTP_RESPONSE, this.currentResponse);
- this.httppocessor.process(this.currentResponse, this.localContext);
int status = this.currentResponse.getStatusLine().getStatusCode();
@@ -339,7 +336,7 @@ public synchronized void consumeContent(
private void releaseConnection() {
if (this.managedConn != null) {
try {
- this.managedConn.getContext().removeAttribute(HttpAsyncClientProtocolHandler.HTTP_HANDLER);
+ this.managedConn.getContext().removeAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER);
this.managedConn.releaseConnection();
} catch (IOException ioex) {
this.log.debug("I/O error releasing connection", ioex);
@@ -361,7 +358,16 @@ private void releaseResources() {
this.connFuture.cancel(true);
this.connFuture = null;
}
- this.requestProducer.resetRequest();
+ try {
+ this.requestProducer.close();
+ } catch (IOException ex) {
+ this.log.debug("I/O error closing request producer", ex);
+ }
+ try {
+ this.responseConsumer.close();
+ } catch (IOException ex) {
+ this.log.debug("I/O error closing response consumer", ex);
+ }
}
public synchronized void failed(final Exception ex) {
@@ -485,7 +491,7 @@ private synchronized void connectionRequestCompleted(final ManagedAsyncClientCon
conn.open(route, this.localContext, this.params);
}
this.managedConn = conn;
- this.managedConn.getContext().setAttribute(HttpAsyncClientProtocolHandler.HTTP_HANDLER, this);
+ this.managedConn.getContext().setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this);
this.managedConn.requestOutput();
this.routeEstablished = route.equals(conn.getRoute());
} catch (IOException ex) {
@@ -499,20 +505,18 @@ private synchronized void connectionRequestCompleted(final ManagedAsyncClientCon
private synchronized void connectionRequestFailed(final Exception ex) {
this.log.debug("Connection request failed", ex);
try {
- this.requestProducer.resetRequest();
- this.responseConsumer.failed(ex);
- } finally {
this.resultCallback.failed(ex, this);
+ } finally {
+ releaseResources();
}
}
private synchronized void connectionRequestCancelled() {
this.log.debug("Connection request cancelled");
try {
- this.requestProducer.resetRequest();
- this.responseConsumer.cancel();
- } finally {
this.resultCallback.cancelled(this);
+ } finally {
+ releaseResources();
}
}
@@ -856,6 +860,10 @@ public HttpContext getContext() {
return this.localContext;
}
+ public HttpProcessor getHttpProcessor() {
+ return this.httppocessor;
+ }
+
public ConnectionReuseStrategy getConnectionReuseStrategy() {
return this.reuseStrategy;
}
View
12 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java
@@ -29,31 +29,31 @@
import java.util.Queue;
import org.apache.http.concurrent.BasicFuture;
-import org.apache.http.nio.protocol.HttpAsyncClientExchangeHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
class DefaultResultCallback<T> implements ResultCallback<T> {
private final BasicFuture<T> future;
- private final Queue<HttpAsyncClientExchangeHandler<?>> queue;
+ private final Queue<HttpAsyncRequestExecutionHandler<?>> queue;
DefaultResultCallback(
- final BasicFuture<T> future, final Queue<HttpAsyncClientExchangeHandler<?>> queue) {
+ final BasicFuture<T> future, final Queue<HttpAsyncRequestExecutionHandler<?>> queue) {
super();
this.future = future;
this.queue = queue;
}
- public void completed(final T result, final HttpAsyncClientExchangeHandler<T> handler) {
+ public void completed(final T result, final HttpAsyncRequestExecutionHandler<T> handler) {
this.future.completed(result);
this.queue.remove(handler);
}
- public void failed(final Exception ex, final HttpAsyncClientExchangeHandler<T> handler) {
+ public void failed(final Exception ex, final HttpAsyncRequestExecutionHandler<T> handler) {
this.future.failed(ex);
this.queue.remove(handler);
}
- public void cancelled(final HttpAsyncClientExchangeHandler<T> handler) {
+ public void cancelled(final HttpAsyncRequestExecutionHandler<T> handler) {
this.future.cancel(true);
this.queue.remove(handler);
}
View
2  httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIOReactorExceptionHandler.java
@@ -50,4 +50,4 @@ public boolean handle(final RuntimeException ex) {
return false;
}
-}
+}
View
41 ...impl/nio/client/LoggingClientProtocolHandler.java → .../impl/nio/client/LoggingAsyncRequestExecutor.java
@@ -35,23 +35,25 @@
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.ContentEncoder;
import org.apache.http.nio.NHttpClientConnection;
-import org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
-class LoggingClientProtocolHandler extends HttpAsyncClientProtocolHandler {
+class LoggingAsyncRequestExecutor extends HttpAsyncRequestExecutor {
- private final Log log = LogFactory.getLog(HttpAsyncClientProtocolHandler.class);
+ private final Log log = LogFactory.getLog(HttpAsyncRequestExecutor.class);
- public LoggingClientProtocolHandler() {
+ public LoggingAsyncRequestExecutor() {
super();
}
@Override
- protected void onException(final Exception ex) {
+ protected void log(final Exception ex) {
this.log.debug(ex.getMessage(), ex);
}
@Override
- public void connected(final NHttpClientConnection conn, final Object attachment) {
+ public void connected(
+ final NHttpClientConnection conn,
+ final Object attachment) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Connected");
}
@@ -63,10 +65,11 @@ public void closed(final NHttpClientConnection conn) {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Disconnected");
}
+ super.closed(conn);
}
@Override
- public void exception(final NHttpClientConnection conn, final HttpException ex) {
+ public void exception(final NHttpClientConnection conn, final Exception ex) {
if (this.log.isErrorEnabled()) {
this.log.error(conn + " HTTP protocol exception: " + ex.getMessage(), ex);
}
@@ -74,15 +77,8 @@ public void exception(final NHttpClientConnection conn, final HttpException ex)
}
@Override
- public void exception(final NHttpClientConnection conn, final IOException ex) {
- if (this.log.isErrorEnabled()) {
- this.log.error(conn + " I/O error: " + ex.getMessage(), ex);
- }
- super.exception(conn, ex);
- }
-
- @Override
- public void requestReady(final NHttpClientConnection conn) {
+ public void requestReady(
+ final NHttpClientConnection conn) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Request ready");
}
@@ -90,7 +86,9 @@ public void requestReady(final NHttpClientConnection conn) {
}
@Override
- public void inputReady(final NHttpClientConnection conn, final ContentDecoder decoder) {
+ public void inputReady(
+ final NHttpClientConnection conn,
+ final ContentDecoder decoder) throws IOException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Input ready " + decoder);
}
@@ -98,7 +96,9 @@ public void inputReady(final NHttpClientConnection conn, final ContentDecoder de
}
@Override
- public void outputReady(final NHttpClientConnection conn, final ContentEncoder encoder) {
+ public void outputReady(
+ final NHttpClientConnection conn,
+ final ContentEncoder encoder) throws IOException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Output ready " + encoder);
}
@@ -106,7 +106,8 @@ public void outputReady(final NHttpClientConnection conn, final ContentEncoder e
}
@Override
- public void responseReceived(final NHttpClientConnection conn) {
+ public void responseReceived(
+ final NHttpClientConnection conn) throws HttpException, IOException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Response received");
}
@@ -114,7 +115,7 @@ public void responseReceived(final NHttpClientConnection conn) {
}
@Override
- public void timeout(final NHttpClientConnection conn) {
+ public void timeout(final NHttpClientConnection conn) throws IOException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Timeout");
}
View
8 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java
@@ -26,15 +26,15 @@
*/
package org.apache.http.impl.nio.client;
-import org.apache.http.nio.protocol.HttpAsyncClientExchangeHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
interface ResultCallback<T> {
- void completed(T result, HttpAsyncClientExchangeHandler<T> handler);
+ void completed(T result, HttpAsyncRequestExecutionHandler<T> handler);
- void failed(Exception ex, HttpAsyncClientExchangeHandler<T> handler);
+ void failed(Exception ex, HttpAsyncRequestExecutionHandler<T> handler);
- void cancelled(HttpAsyncClientExchangeHandler<T> handler);
+ void cancelled(HttpAsyncRequestExecutionHandler<T> handler);
boolean isDone();
View
2  httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/LoggingIOSession.java
@@ -226,4 +226,4 @@ public boolean isOpen() {
}
-}
+}
View
14 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java
@@ -29,6 +29,8 @@
import java.io.IOException;
import java.nio.ByteBuffer;
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.ContentType;
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.IOControl;
import org.apache.http.nio.protocol.AbstractAsyncResponseConsumer;
@@ -48,13 +50,19 @@ public AsyncByteConsumer() {
}
protected abstract void onByteReceived(
- final ByteBuffer buf, final IOControl ioctrl) throws IOException;
+ ByteBuffer buf, IOControl ioctrl) throws IOException;
@Override
- protected void onContentReceived(
+ protected final void onEntityEnclosed(
+ final HttpEntity entity, final ContentType contentType) {
+ this.bbuf = ByteBuffer.allocate(this.bufSize);
+ }
+
+ @Override
+ protected final void onContentReceived(
final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
if (this.bbuf == null) {
- this.bbuf = ByteBuffer.allocate(this.bufSize);
+ throw new IllegalStateException("Byte buffer is null");
}
for (;;) {
int bytesRead = decoder.read(this.bbuf);
View
43 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
@@ -36,8 +36,6 @@
import java.nio.charset.UnsupportedCharsetException;
import org.apache.http.HttpEntity;
-import org.apache.http.HttpException;
-import org.apache.http.HttpResponse;
import org.apache.http.entity.ContentType;
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.IOControl;
@@ -48,7 +46,6 @@
private final int bufSize;
private ContentType contentType;
- private Charset charset;
private CharsetDecoder chardecoder;
private ByteBuffer bbuf;
private CharBuffer cbuf;
@@ -63,32 +60,31 @@ public AsyncCharConsumer() {
}
protected abstract void onCharReceived(
- final CharBuffer buf, final IOControl ioctrl) throws IOException;
+ CharBuffer buf, IOControl ioctrl) throws IOException;
@Override
- public synchronized void responseReceived(
- final HttpResponse response) throws IOException, HttpException {
- HttpEntity entity = response.getEntity();
- this.contentType = ContentType.getOrDefault(entity);
- super.responseReceived(response);
+ protected final void onEntityEnclosed(
+ final HttpEntity entity, final ContentType contentType) throws IOException {
+ this.contentType = contentType != null ? contentType : ContentType.DEFAULT_TEXT;
+ try {
+ String cs = this.contentType.getCharset();
+ if (cs == null) {
+ cs = HTTP.DEFAULT_CONTENT_CHARSET;
+ }
+ Charset charset = Charset.forName(cs);
+ this.chardecoder = charset.newDecoder();
+ } catch (UnsupportedCharsetException ex) {
+ throw new UnsupportedEncodingException(this.contentType.getCharset());
+ }
+ this.bbuf = ByteBuffer.allocate(this.bufSize);
+ this.cbuf = CharBuffer.allocate(this.bufSize);
}
@Override
- protected void onContentReceived(
+ protected final void onContentReceived(
final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
- if (this.charset == null) {
- try {
- String cs = this.contentType.getCharset();
- if (cs == null) {
- cs = HTTP.DEFAULT_CONTENT_CHARSET;
- }
- this.charset = Charset.forName(cs);
- } catch (UnsupportedCharsetException ex) {
- throw new UnsupportedEncodingException(this.contentType.getCharset());
- }
- this.chardecoder = this.charset.newDecoder();
- this.bbuf = ByteBuffer.allocate(this.bufSize);
- this.cbuf = CharBuffer.allocate(this.bufSize);
+ if (this.bbuf == null) {
+ throw new IllegalStateException("Byte buffer is null");
}
for (;;) {
int bytesRead = decoder.read(this.bbuf);
@@ -121,7 +117,6 @@ private void handleDecodingResult(
@Override
protected void releaseResources() {
- this.charset = null;
this.chardecoder = null;
this.bbuf = null;
this.cbuf = null;
View
27 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/BaseZeroCopyRequestProducer.java
@@ -70,6 +70,13 @@ protected BaseZeroCopyRequestProducer(
this.contentType = contentType;
}
+ private void closeChannel() throws IOException {
+ if (this.fileChannel != null) {
+ this.fileChannel.close();
+ this.fileChannel = null;
+ }
+ }
+
protected abstract HttpEntityEnclosingRequest createRequest(final URI requestURI, final HttpEntity entity);
public HttpRequest generateRequest() throws IOException, HttpException {
@@ -107,30 +114,26 @@ public synchronized void produceContent(
if (this.idx >= this.fileChannel.size()) {
encoder.complete();
- this.fileChannel.close();
- this.fileChannel = null;
+ closeChannel();
}
}
public void requestCompleted(final HttpContext context) {
}
- public synchronized boolean isRepeatable() {
+ public void failed(final Exception ex) {
+ }
+
+ public boolean isRepeatable() {
return true;
}
- public synchronized void resetRequest() {
- try {
- close();
- } catch (IOException ignore) {
- }
+ public synchronized void resetRequest() throws IOException {
+ closeChannel();
}
public synchronized void close() throws IOException {
- if (this.fileChannel != null) {
- this.fileChannel.close();
- this.fileChannel = null;
- }
+ closeChannel();
}
}
View
9 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java
@@ -43,9 +43,9 @@
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.entity.ContentType;
+import org.apache.http.nio.entity.HttpAsyncContentProducer;
import org.apache.http.nio.entity.NByteArrayEntity;
import org.apache.http.nio.entity.NStringEntity;
-import org.apache.http.nio.entity.ProducingNHttpEntity;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
@@ -217,7 +217,10 @@ public static HttpAsyncRequestProducer createZeroCopyPut(
return new ZeroCopyConsumer<HttpResponse>(file) {
@Override
- protected HttpResponse process(final HttpResponse response, final File file) throws Exception {
+ protected HttpResponse process(
+ final HttpResponse response,
+ final File file,
+ final ContentType contentType) {
return response;
}
@@ -229,7 +232,7 @@ protected HttpResponse process(final HttpResponse response, final File file) thr
protected RequestProducerImpl(
final HttpHost target,
final HttpEntityEnclosingRequest request,
- final ProducingNHttpEntity producer) {
+ final HttpAsyncContentProducer producer) {
super(target, request, producer);
}
View
20 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/ZeroCopyConsumer.java
@@ -31,7 +31,9 @@
import java.io.IOException;
import java.nio.channels.FileChannel;
+import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
+import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.ContentDecoderChannel;
@@ -46,6 +48,7 @@
private final File file;
private HttpResponse response;
+ private ContentType contentType;
private FileChannel fileChannel;
private long idx = -1;
@@ -63,12 +66,18 @@ protected void onResponseReceived(final HttpResponse response) {
}
@Override
+ protected void onEntityEnclosed(
+ final HttpEntity entity, final ContentType contentType) throws IOException {
+ this.contentType = contentType;
+ this.fileChannel = new FileOutputStream(this.file).getChannel();
+ this.idx = 0;
+ }
+
+ @Override
protected void onContentReceived(
final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
if (this.fileChannel == null) {
- FileOutputStream out = new FileOutputStream(this.file);
- this.fileChannel = out.getChannel();
- this.idx = 0;
+ throw new IllegalStateException("File channel is null");
}
long transferred;
if (decoder instanceof FileContentDecoder) {
@@ -87,14 +96,15 @@ protected void onContentReceived(
}
}
- protected abstract T process(final HttpResponse response, final File file) throws Exception;
+ protected abstract T process(
+ HttpResponse response, File file, ContentType contentType) throws Exception;
@Override
protected T buildResult(final HttpContext context) throws Exception {
FileEntity entity = new FileEntity(this.file);
entity.setContentType(this.response.getFirstHeader(HTTP.CONTENT_TYPE));
this.response.setEntity(entity);
- return process(this.response, this.file);
+ return process(this.response, this.file, this.contentType);
}
@Override
View
4 httpasyncclient/src/main/java/org/apache/http/nio/conn/OperatedAsyncClientConnection.java
@@ -28,11 +28,9 @@
import org.apache.http.HttpInetConnection;
import org.apache.http.nio.NHttpClientConnection;
-import org.apache.http.nio.NHttpClientIOTarget;
import org.apache.http.nio.reactor.IOSession;
-public interface OperatedAsyncClientConnection
- extends NHttpClientConnection, HttpInetConnection, NHttpClientIOTarget {
+public interface OperatedAsyncClientConnection extends NHttpClientConnection, HttpInetConnection {
void upgrade(IOSession iosession);
View
4 httpasyncclient/src/test/java/org/apache/http/HttpAsyncTestBase.java
@@ -30,12 +30,12 @@
import java.io.IOException;
import org.apache.http.HttpResponseInterceptor;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.client.DefaultHttpAsyncClient;
import org.apache.http.impl.nio.conn.PoolingAsyncClientConnectionManager;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.localserver.HttpServerNio;
import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.NHttpServerIOTarget;
import org.apache.http.nio.conn.scheme.AsyncScheme;
import org.apache.http.nio.conn.scheme.AsyncSchemeRegistry;
import org.apache.http.nio.reactor.IOReactorExceptionHandler;
@@ -60,7 +60,7 @@
protected PoolingAsyncClientConnectionManager connMgr;
protected DefaultHttpAsyncClient httpclient;
- protected abstract NHttpConnectionFactory<NHttpServerIOTarget> createServerConnectionFactory(
+ protected abstract NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
HttpParams params) throws Exception;
protected abstract String getSchemeName();
View
47 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestClientAuthentication.java
@@ -47,26 +47,26 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
-import org.apache.http.concurrent.Cancellable;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.DefaultTargetAuthenticationHandler;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory;
import org.apache.http.localserver.BasicAuthTokenExtractor;
import org.apache.http.localserver.RequestBasicAuth;
import org.apache.http.localserver.ResponseBasicUnauthorized;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.NHttpServerIOTarget;
import org.apache.http.nio.entity.NByteArrayEntity;
import org.apache.http.nio.entity.NStringEntity;
+import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
import org.apache.http.nio.protocol.BasicAsyncResponseProducer;
-import org.apache.http.nio.protocol.BufferingAsyncRequestHandler;
-import org.apache.http.nio.protocol.HttpAsyncContinueTrigger;
+import org.apache.http.nio.protocol.HttpAsyncExchange;
import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerRegistry;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerResolver;
-import org.apache.http.nio.protocol.HttpAsyncServiceHandler;
+import org.apache.http.nio.protocol.HttpAsyncService;
import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.params.CoreProtocolPNames;
@@ -117,7 +117,7 @@ public void initServer() throws Exception {
}
@Override
- protected NHttpConnectionFactory<NHttpServerIOTarget> createServerConnectionFactory(
+ protected NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
final HttpParams params) throws Exception {
return new DefaultNHttpServerConnectionFactory(params);
}
@@ -130,11 +130,12 @@ protected String getSchemeName() {
private HttpHost start(
final HttpAsyncRequestHandlerResolver requestHandlerResolver,
final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
- HttpAsyncServiceHandler serviceHandler = new HttpAsyncServiceHandler(
- requestHandlerResolver,
- expectationVerifier,
+ HttpAsyncService serviceHandler = new HttpAsyncService(
this.serverHttpProc,
new DefaultConnectionReuseStrategy(),
+ new DefaultHttpResponseFactory(),
+ requestHandlerResolver,
+ expectationVerifier,
this.serverParams);
this.server.start(serviceHandler);
this.httpclient.start();
@@ -218,10 +219,10 @@ public AuthExpectationVerifier() {
this.authTokenExtractor = new BasicAuthTokenExtractor();
}
- public Cancellable verify(
- final HttpRequest request,
- final HttpAsyncContinueTrigger trigger,
+ public void verify(
+ final HttpAsyncExchange httpexchange,
final HttpContext context) throws HttpException, IOException {
+ HttpRequest request = httpexchange.getRequest();
ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
ver = HttpVersion.HTTP_1_1;
@@ -229,11 +230,10 @@ public Cancellable verify(
String creds = this.authTokenExtractor.extract(request);
if (creds == null || !creds.equals("test:test")) {
HttpResponse response = new BasicHttpResponse(ver, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
- trigger.submitResponse(new BasicAsyncResponseProducer(response));
+ httpexchange.submitResponse(new BasicAsyncResponseProducer(response));
} else {
- trigger.continueRequest();
+ httpexchange.submitResponse();
}
- return null;
}
}
@@ -268,7 +268,7 @@ public AuthScope getAuthScope() {
@Test
public void testBasicAuthenticationNoCreds() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new AuthHandler()));
+ registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
HttpHost target = start(registry, null);
TestCredentialsProvider credsProvider = new TestCredentialsProvider(null);
@@ -287,7 +287,7 @@ public void testBasicAuthenticationNoCreds() throws Exception {
@Test
public void testBasicAuthenticationFailure() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new AuthHandler()));
+ registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
HttpHost target = start(registry, null);
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
@@ -307,7 +307,7 @@ public void testBasicAuthenticationFailure() throws Exception {
@Test
public void testBasicAuthenticationSuccess() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new AuthHandler()));
+ registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
HttpHost target = start(registry, null);
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
@@ -327,7 +327,7 @@ public void testBasicAuthenticationSuccess() throws Exception {
@Test
public void testBasicAuthenticationSuccessNonPersistentConnection() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new AuthHandler(false)));
+ registry.register("*", new BasicAsyncRequestHandler(new AuthHandler(false)));
HttpHost target = start(registry, null);
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
@@ -335,7 +335,6 @@ public void testBasicAuthenticationSuccessNonPersistentConnection() throws Excep
this.httpclient.setCredentialsProvider(credsProvider);
HttpGet httpget = new HttpGet("/");
- httpget.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
Future<HttpResponse> future = this.httpclient.execute(target, httpget, null);
HttpResponse response = future.get();
Assert.assertNotNull(response);
@@ -348,7 +347,7 @@ public void testBasicAuthenticationSuccessNonPersistentConnection() throws Excep
@Test
public void testBasicAuthenticationSuccessWithNonRepeatableExpectContinue() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new AuthHandler()));
+ registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
AuthExpectationVerifier expectationVerifier = new AuthExpectationVerifier();
HttpHost target = start(registry, expectationVerifier);
@@ -380,7 +379,7 @@ public boolean isRepeatable() {
@Test(expected=ExecutionException.class)
public void testBasicAuthenticationFailureWithNonRepeatableEntityExpectContinueOff() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new AuthHandler()));
+ registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
HttpHost target = start(registry, null);
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
@@ -416,7 +415,7 @@ public boolean isRepeatable() {
@Test
public void testBasicAuthenticationSuccessOnRepeatablePost() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new AuthHandler()));
+ registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
HttpHost target = start(registry, null);
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
@@ -439,7 +438,7 @@ public void testBasicAuthenticationSuccessOnRepeatablePost() throws Exception {
@Test
public void testBasicAuthenticationCredentialsCaching() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new AuthHandler()));
+ registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
HttpHost target = start(registry, null);
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
View
22 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java
@@ -41,22 +41,23 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory;
import org.apache.http.localserver.EchoHandler;
import org.apache.http.localserver.RandomHandler;
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.IOControl;
import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.NHttpServerIOTarget;
import org.apache.http.nio.client.methods.HttpAsyncMethods;
import org.apache.http.nio.entity.NByteArrayEntity;
+import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
-import org.apache.http.nio.protocol.BufferingAsyncRequestHandler;
import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerRegistry;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerResolver;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
-import org.apache.http.nio.protocol.HttpAsyncServiceHandler;
+import org.apache.http.nio.protocol.HttpAsyncService;
import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.params.HttpParams;
@@ -81,7 +82,7 @@ public void tearDown() throws Exception {
}
@Override
- protected NHttpConnectionFactory<NHttpServerIOTarget> createServerConnectionFactory(
+ protected NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
final HttpParams params) throws Exception {
return new DefaultNHttpServerConnectionFactory(params);
}
@@ -94,11 +95,12 @@ protected String getSchemeName() {
private HttpHost start(
final HttpAsyncRequestHandlerResolver requestHandlerResolver,
final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
- HttpAsyncServiceHandler serviceHandler = new HttpAsyncServiceHandler(
- requestHandlerResolver,
- expectationVerifier,
+ HttpAsyncService serviceHandler = new HttpAsyncService(
this.serverHttpProc,
new DefaultConnectionReuseStrategy(),
+ new DefaultHttpResponseFactory(),
+ requestHandlerResolver,
+ expectationVerifier,
this.serverParams);
this.server.start(serviceHandler);
this.httpclient.start();
@@ -114,8 +116,8 @@ private HttpHost start(
private HttpHost start() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("/echo/*", new BufferingAsyncRequestHandler(new EchoHandler()));
- registry.register("/random/*", new BufferingAsyncRequestHandler(new RandomHandler()));
+ registry.register("/echo/*", new BasicAsyncRequestHandler(new EchoHandler()));
+ registry.register("/random/*", new BasicAsyncRequestHandler(new RandomHandler()));
return start(registry, null);
}
@@ -221,7 +223,7 @@ public void testRequestFailure() throws Exception {
BasicAsyncResponseConsumer responseConsumer = new BasicAsyncResponseConsumer() {
@Override
- public void consumeContent(final ContentDecoder decoder, final IOControl ioctrl)
+ public void onContentReceived(final ContentDecoder decoder, final IOControl ioctrl)
throws IOException {
throw new IOException("Kaboom");
}
View
4 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java
@@ -27,9 +27,9 @@
package org.apache.http.impl.nio.client;
import org.apache.http.SSLTestContexts;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.SSLNHttpServerConnectionFactory;
import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.NHttpServerIOTarget;
import org.apache.http.nio.conn.scheme.AsyncScheme;
import org.apache.http.nio.conn.ssl.SSLLayeringStrategy;
import org.apache.http.params.HttpParams;
@@ -37,7 +37,7 @@
public class TestHttpsAsync extends TestHttpAsync {
@Override
- protected NHttpConnectionFactory<NHttpServerIOTarget> createServerConnectionFactory(
+ protected NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
final HttpParams params) throws Exception {
return new SSLNHttpServerConnectionFactory(SSLTestContexts.createServerSSLContext(), null, params);
}
View
4 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsRedirects.java
@@ -27,9 +27,9 @@
package org.apache.http.impl.nio.client;
import org.apache.http.SSLTestContexts;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.SSLNHttpServerConnectionFactory;
import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.NHttpServerIOTarget;
import org.apache.http.nio.conn.scheme.AsyncScheme;
import org.apache.http.nio.conn.ssl.SSLLayeringStrategy;
import org.apache.http.params.HttpParams;
@@ -37,7 +37,7 @@
public class TestHttpsRedirects extends TestRedirects {
@Override
- protected NHttpConnectionFactory<NHttpServerIOTarget> createServerConnectionFactory(
+ protected NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
final HttpParams params) throws Exception {
return new SSLNHttpServerConnectionFactory(SSLTestContexts.createServerSSLContext(), null, params);
}
View
54 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestRedirects.java
@@ -52,18 +52,19 @@
import org.apache.http.cookie.SM;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.BasicClientCookie;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory;
import org.apache.http.message.BasicHeader;
import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.NHttpServerIOTarget;
import org.apache.http.nio.entity.NStringEntity;
-import org.apache.http.nio.protocol.BufferingAsyncRequestHandler;
+import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerRegistry;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerResolver;
-import org.apache.http.nio.protocol.HttpAsyncServiceHandler;
+import org.apache.http.nio.protocol.HttpAsyncService;
import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.params.HttpParams;
@@ -95,7 +96,7 @@ public void tearDown() throws Exception {
}
@Override
- protected NHttpConnectionFactory<NHttpServerIOTarget> createServerConnectionFactory(
+ protected NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
final HttpParams params) throws Exception {
return new DefaultNHttpServerConnectionFactory(params);
}
@@ -108,11 +109,12 @@ protected String getSchemeName() {
private HttpHost start(
final HttpAsyncRequestHandlerResolver requestHandlerResolver,
final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
- HttpAsyncServiceHandler serviceHandler = new HttpAsyncServiceHandler(
- requestHandlerResolver,
- expectationVerifier,
+ HttpAsyncService serviceHandler = new HttpAsyncService(
this.serverHttpProc,
new DefaultConnectionReuseStrategy(),
+ new DefaultHttpResponseFactory(),
+ requestHandlerResolver,
+ expectationVerifier,
this.serverParams);
this.server.start(serviceHandler);
this.httpclient.start();
@@ -276,7 +278,7 @@ public void handle(
@Test
public void testBasicRedirect300() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BasicRedirectService(getSchemeName(), HttpStatus.SC_MULTIPLE_CHOICES)));
HttpHost target = start(registry, null);
@@ -298,7 +300,7 @@ public void testBasicRedirect300() throws Exception {
@Test
public void testBasicRedirect301() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BasicRedirectService(getSchemeName(), HttpStatus.SC_MOVED_PERMANENTLY)));
HttpHost target = start(registry, null);
@@ -323,7 +325,7 @@ public void testBasicRedirect301() throws Exception {
@Test
public void testBasicRedirect302() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BasicRedirectService(getSchemeName(), HttpStatus.SC_MOVED_TEMPORARILY)));
HttpHost target = start(registry, null);
@@ -348,7 +350,7 @@ public void testBasicRedirect302() throws Exception {
@Test
public void testBasicRedirect302NoLocation() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new HttpRequestHandler() {
+ registry.register("*", new BasicAsyncRequestHandler(new HttpRequestHandler() {
public void handle(
final HttpRequest request,
@@ -381,7 +383,7 @@ public void handle(
@Test
public void testBasicRedirect303() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BasicRedirectService(getSchemeName(), HttpStatus.SC_SEE_OTHER)));
HttpHost target = start(registry, null);
@@ -406,7 +408,7 @@ public void testBasicRedirect303() throws Exception {
@Test
public void testBasicRedirect304() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BasicRedirectService(getSchemeName(), HttpStatus.SC_NOT_MODIFIED)));
HttpHost target = start(registry, null);
@@ -428,7 +430,7 @@ public void testBasicRedirect304() throws Exception {
@Test
public void testBasicRedirect305() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BasicRedirectService(getSchemeName(), HttpStatus.SC_USE_PROXY)));
HttpHost target = start(registry, null);
@@ -450,7 +452,7 @@ public void testBasicRedirect305() throws Exception {
@Test
public void testBasicRedirect307() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BasicRedirectService(getSchemeName(), HttpStatus.SC_TEMPORARY_REDIRECT)));
HttpHost target = start(registry, null);
@@ -475,7 +477,7 @@ public void testBasicRedirect307() throws Exception {
@Test(expected=ExecutionException.class)
public void testMaxRedirectCheck() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new CircularRedirectService()));
+ registry.register("*", new BasicAsyncRequestHandler(new CircularRedirectService()));
HttpHost target = start(registry, null);
this.httpclient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
@@ -494,7 +496,7 @@ public void testMaxRedirectCheck() throws Exception {
@Test(expected=ExecutionException.class)
public void testCircularRedirect() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new CircularRedirectService()));
+ registry.register("*", new BasicAsyncRequestHandler(new CircularRedirectService()));
HttpHost target = start(registry, null);
this.httpclient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false);
@@ -513,7 +515,7 @@ public void testCircularRedirect() throws Exception {
@Test
public void testPostNoRedirect() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BasicRedirectService(getSchemeName(), HttpStatus.SC_MOVED_TEMPORARILY)));
HttpHost target = start(registry, null);
@@ -537,7 +539,7 @@ public void testPostNoRedirect() throws Exception {
@Test
public void testPostRedirectSeeOther() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BasicRedirectService(getSchemeName(), HttpStatus.SC_SEE_OTHER)));
HttpHost target = start(registry, null);
@@ -561,7 +563,7 @@ public void testPostRedirectSeeOther() throws Exception {
@Test
public void testRelativeRedirect() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new RelativeRedirectService()));
+ registry.register("*", new BasicAsyncRequestHandler(new RelativeRedirectService()));
HttpHost target = start(registry, null);
HttpContext context = new BasicHttpContext();
@@ -587,7 +589,7 @@ public void testRelativeRedirect() throws Exception {
@Test
public void testRelativeRedirect2() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new RelativeRedirectService2()));
+ registry.register("*", new BasicAsyncRequestHandler(new RelativeRedirectService2()));
HttpHost target = start(registry, null);
HttpContext context = new BasicHttpContext();
@@ -613,7 +615,7 @@ public void testRelativeRedirect2() throws Exception {
@Test(expected=ExecutionException.class)
public void testRejectRelativeRedirect() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new RelativeRedirectService()));
+ registry.register("*", new BasicAsyncRequestHandler(new RelativeRedirectService()));
HttpHost target = start(registry, null);
this.httpclient.getParams().setBooleanParameter(
@@ -632,7 +634,7 @@ public void testRejectRelativeRedirect() throws Exception {
@Test(expected=ExecutionException.class)
public void testRejectBogusRedirectLocation() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BogusRedirectService(getSchemeName(), "xxx://bogus", true)));
HttpHost target = start(registry, null);
@@ -650,7 +652,7 @@ public void testRejectBogusRedirectLocation() throws Exception {
@Test(expected=ExecutionException.class)
public void testRejectInvalidRedirectLocation() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BogusRedirectService(getSchemeName(), "/newlocation/?p=I have spaces", false)));
HttpHost target = start(registry, null);
@@ -667,7 +669,7 @@ public void testRejectInvalidRedirectLocation() throws Exception {
@Test
public void testRedirectWithCookie() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BasicRedirectService(getSchemeName(), HttpStatus.SC_MOVED_TEMPORARILY)));
HttpHost target = start(registry, null);
@@ -700,7 +702,7 @@ public void testRedirectWithCookie() throws Exception {
@Test
public void testDefaultHeadersRedirect() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(
+ registry.register("*", new BasicAsyncRequestHandler(
new BasicRedirectService(getSchemeName(), HttpStatus.SC_MOVED_TEMPORARILY)));
HttpHost target = start(registry, null);
View
28 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestStatefulConnManagement.java
@@ -31,6 +31,7 @@
import java.util.concurrent.Future;
import org.apache.http.HttpAsyncTestBase;
+import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
@@ -38,22 +39,24 @@
import org.apache.http.HttpStatus;
import org.apache.http.client.UserTokenHandler;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory;
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.IOControl;
import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.NHttpServerIOTarget;
import org.apache.http.nio.client.HttpAsyncClient;
import org.apache.http.nio.conn.ManagedAsyncClientConnection;
import org.apache.http.nio.entity.NStringEntity;
import org.apache.http.nio.protocol.AbstractAsyncResponseConsumer;
+import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
-import org.apache.http.nio.protocol.BufferingAsyncRequestHandler;
import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerRegistry;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerResolver;
-import org.apache.http.nio.protocol.HttpAsyncServiceHandler;
+import org.apache.http.nio.protocol.HttpAsyncService;
import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.params.BasicHttpParams;
@@ -83,7 +86,7 @@ public void tearDown() throws Exception {
}
@Override
- protected NHttpConnectionFactory<NHttpServerIOTarget> createServerConnectionFactory(
+ protected NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
final HttpParams params) throws Exception {
return new DefaultNHttpServerConnectionFactory(params);
}
@@ -96,11 +99,12 @@ protected String getSchemeName() {
private HttpHost start(
final HttpAsyncRequestHandlerResolver requestHandlerResolver,
final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
- HttpAsyncServiceHandler serviceHandler = new HttpAsyncServiceHandler(
- requestHandlerResolver,
- expectationVerifier,
+ HttpAsyncService serviceHandler = new HttpAsyncService(
this.serverHttpProc,
new DefaultConnectionReuseStrategy(),
+ new DefaultHttpResponseFactory(),
+ requestHandlerResolver,
+ expectationVerifier,
this.serverParams);
this.server.start(serviceHandler);
this.httpclient.start();
@@ -142,7 +146,7 @@ public Object getUserToken(final HttpContext context) {
});
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new SimpleService()));
+ registry.register("*", new BasicAsyncRequestHandler(new SimpleService()));
HttpHost target = start(registry, null);
@@ -233,6 +237,12 @@ protected void onResponseReceived(final HttpResponse response) {
}
@Override
+ protected void onEntityEnclosed(
+ final HttpEntity entity,
+ final ContentType contentType) throws IOException {
+ }
+
+ @Override
protected void onContentReceived(
final ContentDecoder decoder,
final IOControl ioctrl) throws IOException {
@@ -285,7 +295,7 @@ public Object getUserToken(final HttpContext context) {
this.connMgr.setDefaultMaxPerRoute(maxConn);
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new SimpleService()));
+ registry.register("*", new BasicAsyncRequestHandler(new SimpleService()));
HttpHost target = start(registry, null);
View
21 httpasyncclient/src/test/java/org/apache/http/localserver/HttpServerNio.java
@@ -31,12 +31,12 @@
import java.net.InetSocketAddress;
import java.util.List;
-import org.apache.http.impl.nio.DefaultServerIODispatch;
+import org.apache.http.impl.nio.DefaultHttpServerIODispatch;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.reactor.DefaultListeningIOReactor;
import org.apache.http.impl.nio.reactor.ExceptionEvent;
import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.NHttpServerIOTarget;
-import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.nio.NHttpServerEventHandler;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorExceptionHandler;
import org.apache.http.nio.reactor.IOReactorStatus;
@@ -46,13 +46,13 @@
public class HttpServerNio {
private final DefaultListeningIOReactor ioReactor;
- private final NHttpConnectionFactory<NHttpServerIOTarget> connFactory;
+ private final NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory;
private volatile IOReactorThread thread;
private ListenerEndpoint endpoint;
public HttpServerNio(
- final NHttpConnectionFactory<NHttpServerIOTarget> connFactory) throws IOException {
+ final NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory) throws IOException {
super();
this.ioReactor = new DefaultListeningIOReactor();
this.connFactory = connFactory;
@@ -62,8 +62,9 @@ public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler
this.ioReactor.setExceptionHandler(exceptionHandler);
}
- private void execute(final NHttpServiceHandler serviceHandler) throws IOException {
- IOEventDispatch ioEventDispatch = new DefaultServerIODispatch(serviceHandler, this.connFactory);
+ private void execute(final NHttpServerEventHandler serviceHandler) throws IOException {
+ IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(serviceHandler,
+ this.connFactory);
this.ioReactor.execute(ioEventDispatch);
}
@@ -75,7 +76,7 @@ public void setEndpoint(ListenerEndpoint endpoint) {
this.endpoint = endpoint;
}
- public void start(final NHttpServiceHandler serviceHandler) {
+ public void start(final NHttpServerEventHandler serviceHandler) {
this.endpoint = this.ioReactor.listen(new InetSocketAddress(0));
this.thread = new IOReactorThread(serviceHandler);
this.thread.start();
@@ -117,11 +118,11 @@ public void shutdown() throws IOException {
private class IOReactorThread extends Thread {
- private final NHttpServiceHandler serviceHandler;
+ private final NHttpServerEventHandler serviceHandler;
private volatile Exception ex;
- public IOReactorThread(final NHttpServiceHandler serviceHandler) {
+ public IOReactorThread(final NHttpServerEventHandler serviceHandler) {
super();
this.serviceHandler = serviceHandler;
}
View
32 httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestAsyncConsumers.java
@@ -40,19 +40,19 @@
import org.apache.http.HttpResponse;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory;
import org.apache.http.localserver.EchoHandler;
import org.apache.http.localserver.RandomHandler;
-import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.IOControl;
import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.NHttpServerIOTarget;
-import org.apache.http.nio.protocol.BufferingAsyncRequestHandler;
+import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerRegistry;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerResolver;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
-import org.apache.http.nio.protocol.HttpAsyncServiceHandler;
+import org.apache.http.nio.protocol.HttpAsyncService;
import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.params.HttpParams;
@@ -79,7 +79,7 @@ public void tearDown() throws Exception {
}
@Override
- protected NHttpConnectionFactory<NHttpServerIOTarget> createServerConnectionFactory(
+ protected NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
final HttpParams params) throws Exception {
return new DefaultNHttpServerConnectionFactory(params);
}
@@ -92,11 +92,12 @@ protected String getSchemeName() {
private HttpHost start(
final HttpAsyncRequestHandlerResolver requestHandlerResolver,
final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
- HttpAsyncServiceHandler serviceHandler = new HttpAsyncServiceHandler(
- requestHandlerResolver,
- expectationVerifier,
+ HttpAsyncService serviceHandler = new HttpAsyncService(
this.serverHttpProc,
new DefaultConnectionReuseStrategy(),
+ new DefaultHttpResponseFactory(),
+ requestHandlerResolver,
+ expectationVerifier,
this.serverParams);
this.server.start(serviceHandler);
this.httpclient.start();
@@ -112,8 +113,8 @@ private HttpHost start(
private HttpHost start() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("/echo/*", new BufferingAsyncRequestHandler(new EchoHandler()));
- registry.register("/random/*", new BufferingAsyncRequestHandler(new RandomHandler()));
+ registry.register("/echo/*", new BasicAsyncRequestHandler(new EchoHandler()));
+ registry.register("/random/*", new BasicAsyncRequestHandler(new RandomHandler()));
return start(registry, null);
}
@@ -134,7 +135,7 @@ protected void onResponseReceived(final HttpResponse response) {
}
@Override
- protected void onByteReceived(final ByteBuffer buf, final IOControl ioctrl) throws IOException {
+ protected void onByteReceived(final ByteBuffer buf, final IOControl ioctrl) {
this.count.addAndGet(buf.remaining());
}
@@ -182,7 +183,7 @@ public BufferingCharConsumer(int bufSize) {
private StringBuilder sb = new StringBuilder();
@Override
- protected void onResponseReceived(final HttpResponse response) {
+ public void onResponseReceived(final HttpResponse response) {
}
@Override
@@ -264,7 +265,6 @@ public void testResourceReleaseOnSuccess() throws Exception {
Future<String> future = this.httpclient.execute(httppost, consumer, null);
String result = future.get();
Assert.assertEquals(s, result);
- Mockito.verify(consumer).responseCompleted(Mockito.any(HttpContext.class));
Mockito.verify(consumer).buildResult(Mockito.any(HttpContext.class));
Mockito.verify(consumer).releaseResources();
}
@@ -276,8 +276,8 @@ public void testResourceReleaseOnException() throws Exception {
target.toURI() + "/echo/stuff", "stuff",
ContentType.create("text/plain", HTTP.ASCII));
AsyncCharConsumer<String> consumer = Mockito.spy(new BufferingCharConsumer());
- Mockito.doThrow(new IOException("Kaboom")).when(consumer).consumeContent(
- Mockito.any(ContentDecoder.class), Mockito.any(IOControl.class));
+ Mockito.doThrow(new IOException("Kaboom")).when(consumer).onCharReceived(
+ Mockito.any(CharBuffer.class), Mockito.any(IOControl.class));
Future<String> future = this.httpclient.execute(httppost, consumer, null);
try {
@@ -289,7 +289,6 @@ public void testResourceReleaseOnException() throws Exception {
Assert.assertTrue(t instanceof IOException);
Assert.assertEquals("Kaboom", t.getMessage());
}
- Mockito.verify(consumer).failed(Mockito.any(IOException.class));
Mockito.verify(consumer).releaseResources();
}
@@ -312,7 +311,6 @@ public void testResourceReleaseOnBuildFailure() throws Exception {
Assert.assertTrue(t instanceof HttpException);
Assert.assertEquals("Kaboom", t.getMessage());
}
- Mockito.verify(consumer).responseCompleted(Mockito.any(HttpContext.class));
Mockito.verify(consumer).releaseResources();
}
View
25 httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestZeroCopy.java
@@ -51,16 +51,17 @@
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory;
import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.NHttpServerIOTarget;
import org.apache.http.nio.entity.NFileEntity;
import org.apache.http.nio.entity.NStringEntity;
-import org.apache.http.nio.protocol.BufferingAsyncRequestHandler;
+import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerRegistry;
import org.apache.http.nio.protocol.HttpAsyncRequestHandlerResolver;
-import org.apache.http.nio.protocol.HttpAsyncServiceHandler;
+import org.apache.http.nio.protocol.HttpAsyncService;
import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.params.HttpParams;
@@ -88,7 +89,7 @@ public void tearDown() throws Exception {
}
@Override
- protected NHttpConnectionFactory<NHttpServerIOTarget> createServerConnectionFactory(
+ protected NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
final HttpParams params) throws Exception {
return new DefaultNHttpServerConnectionFactory(params);
}
@@ -101,11 +102,12 @@ protected String getSchemeName() {
private HttpHost start(
final HttpAsyncRequestHandlerResolver requestHandlerResolver,
final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
- HttpAsyncServiceHandler serviceHandler = new HttpAsyncServiceHandler(
- requestHandlerResolver,
- expectationVerifier,
+ HttpAsyncService serviceHandler = new HttpAsyncService(
this.serverHttpProc,
new DefaultConnectionReuseStrategy(),
+ new DefaultHttpResponseFactory(),
+ requestHandlerResolver,
+ expectationVerifier,
this.serverParams);
this.server.start(serviceHandler);
this.httpclient.start();
@@ -193,7 +195,10 @@ public TestZeroCopyConsumer(final File file) {
}
@Override
- protected Integer process(final HttpResponse response, final File file) throws Exception {
+ protected Integer process(
+ final HttpResponse response,
+ final File file,
+ final ContentType contentType) {
return response.getStatusLine().getStatusCode();
}
@@ -257,7 +262,7 @@ public void handle(
@Test
public void testTwoWayZeroCopy() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new TestHandler(false)));
+ registry.register("*", new BasicAsyncRequestHandler(new TestHandler(false)));
HttpHost target = start(registry, null);
File tmpdir = FileUtils.getTempDirectory();
@@ -287,7 +292,7 @@ public void testTwoWayZeroCopy() throws Exception {
@Test
public void testZeroCopyFallback() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new BufferingAsyncRequestHandler(new TestHandler(true)));
+ registry.register("*", new BasicAsyncRequestHandler(new TestHandler(true)));
HttpHost target = start(registry, null);
File tmpdir = FileUtils.getTempDirectory();
this.tmpfile = new File(tmpdir, "dst.test");
View
2  pom.xml
@@ -71,7 +71,7 @@
<maven.compile.target>1.5</maven.compile.target>
<maven.compile.optimize>true</maven.compile.optimize>
<maven.compile.deprecation>true</maven.compile.deprecation>
- <httpcore.version>4.2-alpha2</httpcore.version>
+ <httpcore.version>4.2-beta1</httpcore.version>
<httpclient.version>4.1.2</httpclient.version>
<commons-logging.version>1.1.1</commons-logging.version>
<commons-io.version>2.0.1</commons-io.version>
Please sign in to comment.
Something went wrong with that request. Please try again.