You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2018/08/21 15:01:24 UTC
[13/32] httpcomponents-core git commit: Added omitted EntityDetails
parameter to AsyncServerRequestHandler#prepare method
Added omitted EntityDetails parameter to AsyncServerRequestHandler#prepare method
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/f6b77ed4
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/f6b77ed4
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/f6b77ed4
Branch: refs/heads/api_javadocs
Commit: f6b77ed43a041749db31764ece5b7f425341bd8b
Parents: 55e55b8
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Sun Aug 12 16:15:42 2018 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Sun Aug 12 16:16:03 2018 +0200
----------------------------------------------------------------------
.../core5/http/examples/Http2FileServerExample.java | 4 +++-
.../hc/core5/testing/nio/Http1IntegrationTest.java | 6 ++++--
.../hc/core5/testing/nio/Http2IntegrationTest.java | 6 ++++--
.../core5/testing/nio/MessageExchangeHandler.java | 2 ++
.../core5/testing/nio/MultiLineResponseHandler.java | 4 +++-
.../testing/nio/SingleLineResponseHandler.java | 4 +++-
.../core5/http/examples/AsyncFileServerExample.java | 4 +++-
.../http/examples/AsyncServerFilterExample.java | 3 ++-
.../core5/http/nio/AsyncServerRequestHandler.java | 3 ++-
.../hc/core5/http/nio/BasicRequestConsumer.java | 16 ++++++++++++----
.../nio/support/AbstractServerExchangeHandler.java | 3 ++-
.../nio/support/BasicServerExchangeHandler.java | 4 +++-
12 files changed, 43 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f6b77ed4/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java
index 3811dad..33ed9e8 100644
--- a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java
@@ -38,6 +38,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.EndpointDetails;
+import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpConnection;
import org.apache.hc.core5.http.HttpException;
@@ -124,8 +125,9 @@ public class Http2FileServerExample {
@Override
public AsyncRequestConsumer<Message<HttpRequest, Void>> prepare(
final HttpRequest request,
+ final EntityDetails entityDetails,
final HttpContext context) throws HttpException {
- return new BasicRequestConsumer<>(new NoopEntityConsumer());
+ return new BasicRequestConsumer<>(entityDetails != null ? new NoopEntityConsumer() : null);
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f6b77ed4/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
index cc1f5ab..565023a 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
@@ -1583,8 +1583,10 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
@Override
protected AsyncRequestConsumer<Message<HttpRequest, String>> supplyConsumer(
- final HttpRequest request, final HttpContext context) throws HttpException {
- return new BasicRequestConsumer<>(new StringAsyncEntityConsumer());
+ final HttpRequest request,
+ final EntityDetails entityDetails,
+ final HttpContext context) throws HttpException {
+ return new BasicRequestConsumer<>(entityDetails != null ? new StringAsyncEntityConsumer() : null);
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f6b77ed4/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
index 3af925e..6f5cf2d 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
@@ -924,8 +924,10 @@ public class Http2IntegrationTest extends InternalHttp2ServerTestBase {
@Override
protected AsyncRequestConsumer<Message<HttpRequest, String>> supplyConsumer(
- final HttpRequest request, final HttpContext context) throws HttpException {
- return new BasicRequestConsumer<>(new StringAsyncEntityConsumer());
+ final HttpRequest request,
+ final EntityDetails entityDetails,
+ final HttpContext context) throws HttpException {
+ return new BasicRequestConsumer<>(entityDetails != null ? new StringAsyncEntityConsumer() : null);
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f6b77ed4/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/MessageExchangeHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/MessageExchangeHandler.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/MessageExchangeHandler.java
index f9d181c..0e7565e 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/MessageExchangeHandler.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/MessageExchangeHandler.java
@@ -26,6 +26,7 @@
*/
package org.apache.hc.core5.testing.nio;
+import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.Message;
@@ -54,6 +55,7 @@ public abstract class MessageExchangeHandler<T> extends AbstractServerExchangeHa
@Override
protected AsyncRequestConsumer<Message<HttpRequest, T>> supplyConsumer(
final HttpRequest request,
+ final EntityDetails entityDetails,
final HttpContext context) throws HttpException {
return requestConsumer;
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f6b77ed4/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/MultiLineResponseHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/MultiLineResponseHandler.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/MultiLineResponseHandler.java
index bdfce02..f3767a7 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/MultiLineResponseHandler.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/MultiLineResponseHandler.java
@@ -28,6 +28,7 @@ package org.apache.hc.core5.testing.nio;
import java.io.IOException;
+import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
@@ -50,8 +51,9 @@ public class MultiLineResponseHandler extends BasicServerExchangeHandler<Message
@Override
public AsyncRequestConsumer<Message<HttpRequest, String>> prepare(
final HttpRequest request,
+ final EntityDetails entityDetails,
final HttpContext context) throws HttpException {
- return new BasicRequestConsumer<>(new StringAsyncEntityConsumer());
+ return new BasicRequestConsumer<>(entityDetails != null ? new StringAsyncEntityConsumer() : null);
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f6b77ed4/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/SingleLineResponseHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/SingleLineResponseHandler.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/SingleLineResponseHandler.java
index 6abebf2..9ecc6af 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/SingleLineResponseHandler.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/SingleLineResponseHandler.java
@@ -28,6 +28,7 @@ package org.apache.hc.core5.testing.nio;
import java.io.IOException;
+import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpStatus;
@@ -49,8 +50,9 @@ public class SingleLineResponseHandler extends BasicServerExchangeHandler<Messag
@Override
public AsyncRequestConsumer<Message<HttpRequest, String>> prepare(
final HttpRequest request,
+ final EntityDetails entityDetails,
final HttpContext context) throws HttpException {
- return new BasicRequestConsumer<>(new StringAsyncEntityConsumer());
+ return new BasicRequestConsumer<>(entityDetails != null? new StringAsyncEntityConsumer() : null);
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f6b77ed4/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
index 0c19747..2e475af 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
@@ -37,6 +37,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.EndpointDetails;
+import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpStatus;
@@ -86,8 +87,9 @@ public class AsyncFileServerExample {
@Override
public AsyncRequestConsumer<Message<HttpRequest, Void>> prepare(
final HttpRequest request,
+ final EntityDetails entityDetails,
final HttpContext context) throws HttpException {
- return new BasicRequestConsumer<>(new NoopEntityConsumer());
+ return new BasicRequestConsumer<>(entityDetails != null ? new NoopEntityConsumer() : null);
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f6b77ed4/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncServerFilterExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncServerFilterExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncServerFilterExample.java
index a23159f..7c49081 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncServerFilterExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncServerFilterExample.java
@@ -160,8 +160,9 @@ public class AsyncServerFilterExample {
@Override
public AsyncRequestConsumer<Message<HttpRequest, String>> prepare(
final HttpRequest request,
+ final EntityDetails entityDetails,
final HttpContext context) throws HttpException {
- return new BasicRequestConsumer<>(new StringAsyncEntityConsumer());
+ return new BasicRequestConsumer<>(entityDetails != null ? new StringAsyncEntityConsumer() : null);
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f6b77ed4/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncServerRequestHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncServerRequestHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncServerRequestHandler.java
index 1214596..6e84474 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncServerRequestHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/AsyncServerRequestHandler.java
@@ -30,6 +30,7 @@ import java.io.IOException;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
@@ -51,7 +52,7 @@ public interface AsyncServerRequestHandler<T> {
}
- AsyncRequestConsumer<T> prepare(HttpRequest request, HttpContext context) throws HttpException;
+ AsyncRequestConsumer<T> prepare(HttpRequest request, EntityDetails entityDetails, HttpContext context) throws HttpException;
void handle(T requestMessage, ResponseTrigger responseTrigger, HttpContext context) throws HttpException, IOException;
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f6b77ed4/httpcore5/src/main/java/org/apache/hc/core5/http/nio/BasicRequestConsumer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/BasicRequestConsumer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/BasicRequestConsumer.java
index 9679390..e0290c7 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/BasicRequestConsumer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/BasicRequestConsumer.java
@@ -38,6 +38,7 @@ import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.Message;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.Asserts;
/**
* @since 5.0
@@ -49,16 +50,18 @@ public class BasicRequestConsumer<T> implements AsyncRequestConsumer<Message<Htt
private volatile Message<HttpRequest, T> result;
public BasicRequestConsumer(final AsyncEntityConsumer<T> dataConsumer) {
- this.dataConsumer = Args.notNull(dataConsumer, "Data consumer");
+ this.dataConsumer = dataConsumer;
}
@Override
public void consumeRequest(
final HttpRequest request,
final EntityDetails entityDetails,
- final HttpContext httpContext, final FutureCallback<Message<HttpRequest, T>> resultCallback) throws HttpException, IOException {
+ final HttpContext httpContext,
+ final FutureCallback<Message<HttpRequest, T>> resultCallback) throws HttpException, IOException {
Args.notNull(request, "Request");
if (entityDetails != null) {
+ Asserts.notNull(dataConsumer, "Data consumer");
dataConsumer.streamStart(entityDetails, new FutureCallback<T>() {
@Override
@@ -92,22 +95,25 @@ public class BasicRequestConsumer<T> implements AsyncRequestConsumer<Message<Htt
if (resultCallback != null) {
resultCallback.completed(result);
}
- dataConsumer.releaseResources();
+ releaseResources();
}
}
@Override
public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
+ Asserts.notNull(dataConsumer, "Data consumer");
dataConsumer.updateCapacity(capacityChannel);
}
@Override
public int consume(final ByteBuffer src) throws IOException {
+ Asserts.notNull(dataConsumer, "Data consumer");
return dataConsumer.consume(src);
}
@Override
public void streamEnd(final List<? extends Header> trailers) throws HttpException, IOException {
+ Asserts.notNull(dataConsumer, "Data consumer");
dataConsumer.streamEnd(trailers);
}
@@ -123,7 +129,9 @@ public class BasicRequestConsumer<T> implements AsyncRequestConsumer<Message<Htt
@Override
public void releaseResources() {
- dataConsumer.releaseResources();
+ if (dataConsumer != null) {
+ dataConsumer.releaseResources();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f6b77ed4/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractServerExchangeHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractServerExchangeHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractServerExchangeHandler.java
index 613d248..1ebdbba 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractServerExchangeHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractServerExchangeHandler.java
@@ -65,6 +65,7 @@ public abstract class AbstractServerExchangeHandler<T> implements AsyncServerExc
protected abstract AsyncRequestConsumer<T> supplyConsumer(
HttpRequest request,
+ EntityDetails entityDetails,
HttpContext context) throws HttpException;
protected abstract void handle(
@@ -79,7 +80,7 @@ public abstract class AbstractServerExchangeHandler<T> implements AsyncServerExc
final ResponseChannel responseChannel,
final HttpContext context) throws HttpException, IOException {
- final AsyncRequestConsumer<T> requestConsumer = supplyConsumer(request, context);
+ final AsyncRequestConsumer<T> requestConsumer = supplyConsumer(request, entityDetails, context);
if (requestConsumer == null) {
throw new HttpException("Unable to handle request");
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f6b77ed4/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicServerExchangeHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicServerExchangeHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicServerExchangeHandler.java
index 555cc65..85f2a3b 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicServerExchangeHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicServerExchangeHandler.java
@@ -28,6 +28,7 @@ package org.apache.hc.core5.http.nio.support;
import java.io.IOException;
+import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.nio.AsyncRequestConsumer;
@@ -50,8 +51,9 @@ public class BasicServerExchangeHandler<T> extends AbstractServerExchangeHandler
@Override
protected AsyncRequestConsumer<T> supplyConsumer(
final HttpRequest request,
+ final EntityDetails entityDetails,
final HttpContext context) throws HttpException {
- return requestHandler.prepare(request, context);
+ return requestHandler.prepare(request, entityDetails, context);
}
@Override