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 2016/10/31 17:33:33 UTC
svn commit: r1767339 [9/14] - in /httpcomponents/httpcore/trunk: ./
httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/
httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/boots...
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestParser.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestParser.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestParser.java Mon Oct 31 17:33:27 2016
@@ -27,64 +27,62 @@
package org.apache.hc.core5.http.impl.nio;
-import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpRequestFactory;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.UnsupportedHttpVersionException;
-import org.apache.hc.core5.http.config.MessageConstraints;
-import org.apache.hc.core5.http.impl.DefaultHttpRequestFactory;
+import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.message.LineParser;
import org.apache.hc.core5.http.message.RequestLine;
+import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.CharArrayBuffer;
/**
- * Default {@link org.apache.hc.core5.http.nio.NHttpMessageParser} implementation
- * for {@link ClassicHttpRequest}s.
+ * Default {@link org.apache.hc.core5.http.nio.NHttpMessageParser} implementation for {@link HttpRequest}s.
*
* @since 4.1
*/
-public class DefaultHttpRequestParser extends AbstractMessageParser<ClassicHttpRequest> {
+public class DefaultHttpRequestParser<T extends HttpRequest> extends AbstractMessageParser<T> {
- private final HttpRequestFactory<ClassicHttpRequest> requestFactory;
+ private final HttpRequestFactory<T> requestFactory;
/**
* Creates an instance of DefaultHttpRequestParser.
*
+ * @param requestFactory the request factory.
* @param parser the line parser. If {@code null}
* {@link org.apache.hc.core5.http.message.LazyLineParser#INSTANCE} will be used.
- * @param requestFactory the request factory. If {@code null}
- * {@link DefaultHttpRequestFactory#INSTANCE} will be used.
* @param constraints Message constraints. If {@code null}
- * {@link MessageConstraints#DEFAULT} will be used.
+ * {@link H1Config#DEFAULT} will be used.
*
* @since 4.3
*/
public DefaultHttpRequestParser(
+ final HttpRequestFactory<T> requestFactory,
final LineParser parser,
- final HttpRequestFactory<ClassicHttpRequest> requestFactory,
- final MessageConstraints constraints) {
+ final H1Config constraints) {
super(parser, constraints);
- this.requestFactory = requestFactory != null ? requestFactory : DefaultHttpRequestFactory.INSTANCE;
+ this.requestFactory = Args.notNull(requestFactory, "Request factory");
}
/**
* @since 4.3
*/
- public DefaultHttpRequestParser(final MessageConstraints constraints) {
- this(null, null, constraints);
+ public DefaultHttpRequestParser(final HttpRequestFactory<T> requestFactory, final H1Config constraints) {
+ this(requestFactory, null, constraints);
}
/**
* @since 4.3
*/
- public DefaultHttpRequestParser() {
- this(null);
+ public DefaultHttpRequestParser(final HttpRequestFactory<T> requestFactory) {
+ this(requestFactory, null);
}
@Override
- protected ClassicHttpRequest createMessage(final CharArrayBuffer buffer) throws HttpException {
+ protected T createMessage(final CharArrayBuffer buffer) throws HttpException {
final RequestLine requestLine = getLineParser().parseRequestLine(buffer);
final ProtocolVersion transportVersion = requestLine.getProtocolVersion();
if (transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestParserFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestParserFactory.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestParserFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestParserFactory.java Mon Oct 31 17:33:27 2016
@@ -29,10 +29,9 @@ package org.apache.hc.core5.http.impl.ni
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpRequestFactory;
-import org.apache.hc.core5.http.config.MessageConstraints;
-import org.apache.hc.core5.http.impl.DefaultHttpRequestFactory;
+import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.message.LazyLineParser;
import org.apache.hc.core5.http.message.LineParser;
import org.apache.hc.core5.http.nio.NHttpMessageParser;
@@ -44,27 +43,30 @@ import org.apache.hc.core5.http.nio.NHtt
* @since 4.3
*/
@Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
-public class DefaultHttpRequestParserFactory implements NHttpMessageParserFactory<ClassicHttpRequest> {
+public class DefaultHttpRequestParserFactory implements NHttpMessageParserFactory<HttpRequest> {
public static final DefaultHttpRequestParserFactory INSTANCE = new DefaultHttpRequestParserFactory();
private final LineParser lineParser;
- private final HttpRequestFactory requestFactory;
+ private final HttpRequestFactory<HttpRequest> requestFactory;
- public DefaultHttpRequestParserFactory(final LineParser lineParser,
- final HttpRequestFactory requestFactory) {
+ public DefaultHttpRequestParserFactory(final HttpRequestFactory<HttpRequest> requestFactory, final LineParser lineParser) {
super();
- this.lineParser = lineParser != null ? lineParser : LazyLineParser.INSTANCE;
this.requestFactory = requestFactory != null ? requestFactory : DefaultHttpRequestFactory.INSTANCE;
+ this.lineParser = lineParser != null ? lineParser : LazyLineParser.INSTANCE;
+ }
+
+ public DefaultHttpRequestParserFactory(final HttpRequestFactory<HttpRequest> requestFactory) {
+ this(requestFactory, null);
}
public DefaultHttpRequestParserFactory() {
- this(null, null);
+ this(null);
}
@Override
- public NHttpMessageParser<ClassicHttpRequest> create(final MessageConstraints constraints) {
- return new DefaultHttpRequestParser(lineParser, requestFactory, constraints);
+ public NHttpMessageParser<HttpRequest> create(final H1Config constraints) {
+ return new DefaultHttpRequestParser<>(requestFactory, lineParser, constraints);
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestWriter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestWriter.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestWriter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestWriter.java Mon Oct 31 17:33:27 2016
@@ -29,7 +29,7 @@ package org.apache.hc.core5.http.impl.ni
import java.io.IOException;
-import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.message.LineFormatter;
@@ -37,12 +37,11 @@ import org.apache.hc.core5.http.message.
import org.apache.hc.core5.util.CharArrayBuffer;
/**
- * Default {@link org.apache.hc.core5.http.nio.NHttpMessageWriter} implementation
- * for {@link ClassicHttpRequest}s.
+ * Default {@link org.apache.hc.core5.http.nio.NHttpMessageWriter} implementation for {@link HttpRequest}s.
*
* @since 4.1
*/
-public class DefaultHttpRequestWriter extends AbstractMessageWriter<ClassicHttpRequest> {
+public class DefaultHttpRequestWriter<T extends HttpRequest> extends AbstractMessageWriter<T> {
/**
* Creates an instance of DefaultHttpRequestWriter.
@@ -64,7 +63,7 @@ public class DefaultHttpRequestWriter ex
}
@Override
- protected void writeHeadLine(final ClassicHttpRequest message, final CharArrayBuffer lineBuf) throws IOException {
+ protected void writeHeadLine(final T message, final CharArrayBuffer lineBuf) throws IOException {
lineBuf.clear();
ProtocolVersion transportVersion = message.getVersion();
if (transportVersion == null || transportVersion.greaterEquals(HttpVersion.HTTP_2_0)) {
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestWriterFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestWriterFactory.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestWriterFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpRequestWriterFactory.java Mon Oct 31 17:33:27 2016
@@ -29,7 +29,7 @@ package org.apache.hc.core5.http.impl.ni
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.message.BasicLineFormatter;
import org.apache.hc.core5.http.message.LineFormatter;
import org.apache.hc.core5.http.nio.NHttpMessageWriter;
@@ -41,7 +41,7 @@ import org.apache.hc.core5.http.nio.NHtt
* @since 4.3
*/
@Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
-public class DefaultHttpRequestWriterFactory implements NHttpMessageWriterFactory<ClassicHttpRequest> {
+public class DefaultHttpRequestWriterFactory implements NHttpMessageWriterFactory<HttpRequest> {
public static final DefaultHttpRequestWriterFactory INSTANCE = new DefaultHttpRequestWriterFactory();
@@ -57,8 +57,8 @@ public class DefaultHttpRequestWriterFac
}
@Override
- public NHttpMessageWriter<ClassicHttpRequest> create() {
- return new DefaultHttpRequestWriter(this.lineFormatter);
+ public NHttpMessageWriter<HttpRequest> create() {
+ return new DefaultHttpRequestWriter<>(this.lineFormatter);
}
}
Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseFactory.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultHttpResponseFactory.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseFactory.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseFactory.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultHttpResponseFactory.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultHttpResponseFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseFactory.java Mon Oct 31 17:33:27 2016
@@ -25,24 +25,25 @@
*
*/
-package org.apache.hc.core5.http.impl;
+package org.apache.hc.core5.http.impl.nio;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpResponseFactory;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.ReasonPhraseCatalog;
-import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
+import org.apache.hc.core5.http.impl.EnglishReasonPhraseCatalog;
+import org.apache.hc.core5.http.message.BasicHttpResponse;
import org.apache.hc.core5.util.Args;
/**
- * Default factory for creating {@link ClassicHttpResponse} objects.
+ * Default factory for creating {@link HttpResponse} objects.
*
* @since 4.0
*/
@Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
-public class DefaultHttpResponseFactory implements HttpResponseFactory<ClassicHttpResponse> {
+public class DefaultHttpResponseFactory implements HttpResponseFactory<HttpResponse> {
public static final DefaultHttpResponseFactory INSTANCE = new DefaultHttpResponseFactory();
@@ -66,8 +67,8 @@ public class DefaultHttpResponseFactory
}
@Override
- public ClassicHttpResponse newHttpResponse(final ProtocolVersion transportVersion, final int status, final String reasonPhrase) {
- final ClassicHttpResponse response = new BasicClassicHttpResponse(status, reasonPhrase);
+ public HttpResponse newHttpResponse(final ProtocolVersion transportVersion, final int status, final String reasonPhrase) {
+ final HttpResponse response = new BasicHttpResponse(status, reasonPhrase);
response.setVersion(transportVersion);
if (reasonPhrase != null) {
response.setReasonPhrase(reasonPhrase);
@@ -76,8 +77,8 @@ public class DefaultHttpResponseFactory
}
@Override
- public ClassicHttpResponse newHttpResponse(final int status) {
- return new BasicClassicHttpResponse(status, this.reasonCatalog, null);
+ public HttpResponse newHttpResponse(final int status) {
+ return new BasicHttpResponse(status, this.reasonCatalog, null);
}
}
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseParser.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseParser.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseParser.java Mon Oct 31 17:33:27 2016
@@ -27,65 +27,62 @@
package org.apache.hc.core5.http.impl.nio;
-import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpResponseFactory;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.UnsupportedHttpVersionException;
-import org.apache.hc.core5.http.config.MessageConstraints;
-import org.apache.hc.core5.http.impl.DefaultHttpResponseFactory;
+import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.message.LineParser;
import org.apache.hc.core5.http.message.StatusLine;
+import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.CharArrayBuffer;
/**
- * Default {@link org.apache.hc.core5.http.nio.NHttpMessageParser} implementation
- * for {@link ClassicHttpResponse}s.
+ * Default {@link org.apache.hc.core5.http.nio.NHttpMessageParser} implementation for {@link HttpResponse}s.
*
* @since 4.1
*/
-public class DefaultHttpResponseParser extends AbstractMessageParser<ClassicHttpResponse> {
+public class DefaultHttpResponseParser<T extends HttpResponse> extends AbstractMessageParser<T> {
- private final HttpResponseFactory<ClassicHttpResponse> responseFactory;
+ private final HttpResponseFactory<T> responseFactory;
/**
* Creates an instance of DefaultHttpResponseParser.
*
+ * @param responseFactory the response factory.
* @param parser the line parser. If {@code null}
* {@link org.apache.hc.core5.http.message.LazyLineParser#INSTANCE} will be used.
- * @param responseFactory the response factory. If {@code null}
- * {@link DefaultHttpResponseFactory#INSTANCE} will be used.
* @param constraints Message constraints. If {@code null}
- * {@link MessageConstraints#DEFAULT} will be used.
+ * {@link H1Config#DEFAULT} will be used.
*
* @since 4.3
*/
public DefaultHttpResponseParser(
+ final HttpResponseFactory<T> responseFactory,
final LineParser parser,
- final HttpResponseFactory<ClassicHttpResponse> responseFactory,
- final MessageConstraints constraints) {
+ final H1Config constraints) {
super(parser, constraints);
- this.responseFactory = responseFactory != null ? responseFactory :
- DefaultHttpResponseFactory.INSTANCE;
+ this.responseFactory = Args.notNull(responseFactory, "Response factory");
}
/**
* @since 4.3
*/
- public DefaultHttpResponseParser(final MessageConstraints constraints) {
- this(null, null, constraints);
+ public DefaultHttpResponseParser(final HttpResponseFactory<T> responseFactory, final H1Config constraints) {
+ this(responseFactory, null, constraints);
}
/**
* @since 4.3
*/
- public DefaultHttpResponseParser() {
- this(null);
+ public DefaultHttpResponseParser(final HttpResponseFactory<T> responseFactory) {
+ this(responseFactory, null);
}
@Override
- protected ClassicHttpResponse createMessage(final CharArrayBuffer buffer) throws HttpException {
+ protected T createMessage(final CharArrayBuffer buffer) throws HttpException {
final StatusLine statusLine = getLineParser().parseStatusLine(buffer);
final ProtocolVersion transportVersion = statusLine.getProtocolVersion();
if (transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseParserFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseParserFactory.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseParserFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseParserFactory.java Mon Oct 31 17:33:27 2016
@@ -29,10 +29,9 @@ package org.apache.hc.core5.http.impl.ni
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpResponseFactory;
-import org.apache.hc.core5.http.config.MessageConstraints;
-import org.apache.hc.core5.http.impl.DefaultHttpResponseFactory;
+import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.message.LazyLaxLineParser;
import org.apache.hc.core5.http.message.LineParser;
import org.apache.hc.core5.http.nio.NHttpMessageParser;
@@ -44,27 +43,30 @@ import org.apache.hc.core5.http.nio.NHtt
* @since 4.3
*/
@Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
-public class DefaultHttpResponseParserFactory implements NHttpMessageParserFactory<ClassicHttpResponse> {
+public class DefaultHttpResponseParserFactory implements NHttpMessageParserFactory<HttpResponse> {
public static final DefaultHttpResponseParserFactory INSTANCE = new DefaultHttpResponseParserFactory();
+ private final HttpResponseFactory<HttpResponse> responseFactory;
private final LineParser lineParser;
- private final HttpResponseFactory responseFactory;
- public DefaultHttpResponseParserFactory(final LineParser lineParser,
- final HttpResponseFactory responseFactory) {
+ public DefaultHttpResponseParserFactory(final HttpResponseFactory<HttpResponse> responseFactory, final LineParser lineParser) {
super();
- this.lineParser = lineParser != null ? lineParser : LazyLaxLineParser.INSTANCE;
this.responseFactory = responseFactory != null ? responseFactory : DefaultHttpResponseFactory.INSTANCE;
+ this.lineParser = lineParser != null ? lineParser : LazyLaxLineParser.INSTANCE;
+ }
+
+ public DefaultHttpResponseParserFactory(final HttpResponseFactory<HttpResponse> responseFactory) {
+ this(responseFactory, null);
}
public DefaultHttpResponseParserFactory() {
- this(null, null);
+ this(null);
}
@Override
- public NHttpMessageParser<ClassicHttpResponse> create(final MessageConstraints constraints) {
- return new DefaultHttpResponseParser(this.lineParser, this.responseFactory, constraints);
+ public NHttpMessageParser<HttpResponse> create(final H1Config constraints) {
+ return new DefaultHttpResponseParser<>(this.responseFactory, this.lineParser, constraints);
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseWriter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseWriter.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseWriter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseWriter.java Mon Oct 31 17:33:27 2016
@@ -29,7 +29,7 @@ package org.apache.hc.core5.http.impl.ni
import java.io.IOException;
-import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.message.LineFormatter;
@@ -37,12 +37,11 @@ import org.apache.hc.core5.http.message.
import org.apache.hc.core5.util.CharArrayBuffer;
/**
- * Default {@link org.apache.hc.core5.http.nio.NHttpMessageWriter} implementation
- * for {@link ClassicHttpResponse}s.
+ * Default {@link org.apache.hc.core5.http.nio.NHttpMessageWriter} implementation for {@link HttpResponse}s.
*
* @since 4.1
*/
-public class DefaultHttpResponseWriter extends AbstractMessageWriter<ClassicHttpResponse> {
+public class DefaultHttpResponseWriter<T extends HttpResponse> extends AbstractMessageWriter<T> {
/**
* Creates an instance of DefaultHttpResponseWriter.
@@ -64,7 +63,7 @@ public class DefaultHttpResponseWriter e
}
@Override
- protected void writeHeadLine(final ClassicHttpResponse message, final CharArrayBuffer lineBuf) throws IOException {
+ protected void writeHeadLine(final T message, final CharArrayBuffer lineBuf) throws IOException {
lineBuf.clear();
ProtocolVersion transportVersion = message.getVersion();
if (transportVersion == null || transportVersion.greaterEquals(HttpVersion.HTTP_2_0)) {
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseWriterFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseWriterFactory.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseWriterFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/DefaultHttpResponseWriterFactory.java Mon Oct 31 17:33:27 2016
@@ -29,7 +29,7 @@ package org.apache.hc.core5.http.impl.ni
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.message.BasicLineFormatter;
import org.apache.hc.core5.http.message.LineFormatter;
import org.apache.hc.core5.http.nio.NHttpMessageWriter;
@@ -41,7 +41,7 @@ import org.apache.hc.core5.http.nio.NHtt
* @since 4.3
*/
@Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
-public class DefaultHttpResponseWriterFactory implements NHttpMessageWriterFactory<ClassicHttpResponse> {
+public class DefaultHttpResponseWriterFactory implements NHttpMessageWriterFactory<HttpResponse> {
public static final DefaultHttpResponseWriterFactory INSTANCE = new DefaultHttpResponseWriterFactory();
@@ -57,8 +57,8 @@ public class DefaultHttpResponseWriterFa
}
@Override
- public NHttpMessageWriter<ClassicHttpResponse> create() {
- return new DefaultHttpResponseWriter(this.lineFormatter);
+ public NHttpMessageWriter<HttpResponse> create() {
+ return new DefaultHttpResponseWriter<>(this.lineFormatter);
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java Mon Oct 31 17:33:27 2016
@@ -159,7 +159,7 @@ public class ExpandableBuffer {
*
* @return buffer length.
*/
- public int available() {
+ public int capacity() {
setInputMode();
return this.buffer.remaining();
}
Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamChannel.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncResponseTrigger.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamChannel.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamChannel.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncResponseTrigger.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncResponseTrigger.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamChannel.java Mon Oct 31 17:33:27 2016
@@ -24,26 +24,29 @@
* <http://www.apache.org/>.
*
*/
-
-package org.apache.hc.core5.http2.nio;
+package org.apache.hc.core5.http.impl.nio;
import java.io.IOException;
-import org.apache.hc.core5.annotation.Contract;
-import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpMessage;
+import org.apache.hc.core5.http.nio.CapacityChannel;
+import org.apache.hc.core5.http.nio.ContentEncoder;
-/**
- * Abstract asynchronous response / response promise trigger.
- *
- * @since 5.0
- */
-@Contract(threading = ThreadingBehavior.SAFE)
-public interface AsyncResponseTrigger {
+interface Http1StreamChannel<OutgoingMessage extends HttpMessage> extends ContentEncoder, CapacityChannel {
+
+ void activate() throws HttpException, IOException;
+
+ void submit(OutgoingMessage messageHead, boolean endStream) throws HttpException, IOException;
+
+ void suspendInput();
+
+ void requestInput();
+
+ void requestOutput();
- void submitResponse(AsyncResponseProducer responseProducer) throws HttpException, IOException;
+ void suspendOutput();
- void pushPromise(HttpRequest promise, AsyncPushProducer responseProducer) throws HttpException, IOException;
+ void abortOutput() throws IOException;
}
Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamListener.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncPushConsumer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamListener.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamListener.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncPushConsumer.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncPushConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamListener.java Mon Oct 31 17:33:27 2016
@@ -24,24 +24,23 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.nio;
+package org.apache.hc.core5.http.impl.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.HttpConnection;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
/**
- * Abstract asynchronous push response consumer.
+ * HTTP/1.1 stream event listener.
*
* @since 5.0
*/
-public interface AsyncPushConsumer extends AsyncDataConsumer {
+public interface Http1StreamListener {
+
+ void onRequestHead(HttpConnection connection, HttpRequest request);
- void consumePromise(HttpRequest promise, HttpResponse response, EntityDetails entityDetails) throws HttpException, IOException;
+ void onResponseHead(HttpConnection connection, HttpResponse response);
- void failed(Exception cause);
+ void onExchangeComplete(HttpConnection connection, boolean keepAlive);
}
Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/HttpConnectionEventHandler.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/HttpErrorListener.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/HttpConnectionEventHandler.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/HttpConnectionEventHandler.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/HttpErrorListener.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/HttpErrorListener.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/HttpConnectionEventHandler.java Mon Oct 31 17:33:27 2016
@@ -24,15 +24,10 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.impl.nio;
+package org.apache.hc.core5.http.impl.nio;
-/**
- * HTTP/2 stream error listener.
- *
- * @since 5.0
- */
-public interface HttpErrorListener {
-
- void onError(Exception exception);
+import org.apache.hc.core5.http.HttpConnection;
+import org.apache.hc.core5.reactor.IOEventHandler;
+public interface HttpConnectionEventHandler extends IOEventHandler, HttpConnection {
}
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/HttpConnectionEventHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/HttpConnectionEventHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/HttpConnectionEventHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/MessageState.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/MessageState.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/MessageState.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/MessageState.java Mon Oct 31 17:33:27 2016
@@ -26,8 +26,4 @@
*/
package org.apache.hc.core5.http.impl.nio;
-enum MessageState {
-
- READY, INIT, ACK_EXPECTED, BODY_STREAM, COMPLETED
-
-}
+public enum MessageState { IDLE, HEADERS, ACK, BODY, COMPLETE }
Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandler.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/CapacityChannel.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandler.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandler.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/CapacityChannel.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/CapacityChannel.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandler.java Mon Oct 31 17:33:27 2016
@@ -24,23 +24,22 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.nio;
-import java.io.IOException;
+package org.apache.hc.core5.http.impl.nio;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
/**
- * Abstract capacity update channel.
- * <p>
- * Implementations are expected to be thread-safe.
+ * {@link org.apache.hc.core5.reactor.IOEventHandler} that implements server side HTTP/1.1 messaging protocol.
*
* @since 5.0
*/
-@Contract(threading = ThreadingBehavior.SAFE)
-public interface CapacityChannel {
+@Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
+public class ServerHttp1IOEventHandler extends AbstractHttp1IOEventHandler {
- void update(int increment) throws IOException;
+ public ServerHttp1IOEventHandler(final ServerHttp1StreamDuplexer streamDuplexer) {
+ super(streamDuplexer);
+ }
}
Added: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java?rev=1767339&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java Mon Oct 31 17:33:27 2016
@@ -0,0 +1,149 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http.impl.nio;
+
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ConnectionReuseStrategy;
+import org.apache.hc.core5.http.ContentLengthStrategy;
+import org.apache.hc.core5.http.ExceptionListener;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.config.ConnectionConfig;
+import org.apache.hc.core5.http.config.H1Config;
+import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
+import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
+import org.apache.hc.core5.http.nio.HandlerFactory;
+import org.apache.hc.core5.http.nio.NHttpMessageParserFactory;
+import org.apache.hc.core5.http.nio.NHttpMessageWriterFactory;
+import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.reactor.IOEventHandler;
+import org.apache.hc.core5.reactor.IOEventHandlerFactory;
+import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public class ServerHttp1IOEventHandlerFactory implements IOEventHandlerFactory {
+
+ private final HttpProcessor httpProcessor;
+ private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
+ private final ConnectionReuseStrategy connectionReuseStrategy;
+ private final ConnectionConfig connectionConfig;
+ private final NHttpMessageParserFactory<HttpRequest> requestParserFactory;
+ private final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory;
+ private final ContentLengthStrategy incomingContentStrategy;
+ private final ContentLengthStrategy outgoingContentStrategy;
+ private final ConnectionListener connectionListener;
+ private final Http1StreamListener streamListener;
+
+ public ServerHttp1IOEventHandlerFactory(
+ final HttpProcessor httpProcessor,
+ final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
+ final ConnectionConfig connectionConfig,
+ final ConnectionReuseStrategy connectionReuseStrategy,
+ final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
+ final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory,
+ final ContentLengthStrategy incomingContentStrategy,
+ final ContentLengthStrategy outgoingContentStrategy,
+ final ExceptionListener errorListener,
+ final ConnectionListener connectionListener,
+ final Http1StreamListener streamListener) {
+ this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
+ this.exchangeHandlerFactory = Args.notNull(exchangeHandlerFactory, "Exchange handler factory");
+ this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
+ this.connectionReuseStrategy = connectionReuseStrategy != null ? connectionReuseStrategy :
+ DefaultConnectionReuseStrategy.INSTANCE;
+ this.requestParserFactory = requestParserFactory != null ? requestParserFactory :
+ DefaultHttpRequestParserFactory.INSTANCE;
+ this.responseWriterFactory = responseWriterFactory != null ? responseWriterFactory :
+ DefaultHttpResponseWriterFactory.INSTANCE;
+ this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
+ DefaultContentLengthStrategy.INSTANCE;
+ this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
+ DefaultContentLengthStrategy.INSTANCE;
+ this.connectionListener = connectionListener;
+ this.streamListener = streamListener;
+ }
+
+ public ServerHttp1IOEventHandlerFactory(
+ final HttpProcessor httpProcessor,
+ final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
+ final ConnectionConfig connectionConfig,
+ final ConnectionReuseStrategy connectionReuseStrategy,
+ final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
+ final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory,
+ final ExceptionListener errorListener,
+ final ConnectionListener connectionListener,
+ final Http1StreamListener streamListener) {
+ this(httpProcessor, exchangeHandlerFactory, connectionConfig,
+ connectionReuseStrategy, requestParserFactory, responseWriterFactory,
+ null, null, errorListener, connectionListener, streamListener);
+ }
+
+ public ServerHttp1IOEventHandlerFactory(
+ final HttpProcessor httpProcessor,
+ final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
+ final ConnectionConfig connectionConfig,
+ final ExceptionListener errorListener,
+ final ConnectionListener connectionListener,
+ final Http1StreamListener streamListener) {
+ this(httpProcessor, exchangeHandlerFactory, connectionConfig, null, null ,null,
+ errorListener, connectionListener, streamListener);
+ }
+
+ public ServerHttp1IOEventHandlerFactory(
+ final HttpProcessor httpProcessor,
+ final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
+ final ConnectionConfig connectionConfig,
+ final ExceptionListener errorListener) {
+ this(httpProcessor, exchangeHandlerFactory, connectionConfig, errorListener, null, null);
+ }
+
+ @Override
+ public IOEventHandler createHandler(final IOSession ioSession) {
+ return new ServerHttp1IOEventHandler(createStreamDuplexer(ioSession));
+ }
+
+ protected ServerHttp1StreamDuplexer createStreamDuplexer(final IOSession ioSession) {
+ return new ServerHttp1StreamDuplexer(ioSession, httpProcessor, exchangeHandlerFactory,
+ H1Config.DEFAULT,
+ connectionConfig,
+ connectionReuseStrategy,
+ requestParserFactory.create(H1Config.DEFAULT),
+ responseWriterFactory.create(),
+ incomingContentStrategy,
+ outgoingContentStrategy,
+ connectionListener,
+ streamListener);
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java?rev=1767339&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java Mon Oct 31 17:33:27 2016
@@ -0,0 +1,475 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http.impl.nio;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import org.apache.hc.core5.http.ConnectionClosedException;
+import org.apache.hc.core5.http.ConnectionReuseStrategy;
+import org.apache.hc.core5.http.ContentLengthStrategy;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.config.ConnectionConfig;
+import org.apache.hc.core5.http.config.H1Config;
+import org.apache.hc.core5.http.impl.BasicHttpConnectionMetrics;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
+import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
+import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
+import org.apache.hc.core5.http.nio.ContentDecoder;
+import org.apache.hc.core5.http.nio.ContentEncoder;
+import org.apache.hc.core5.http.nio.HandlerFactory;
+import org.apache.hc.core5.http.nio.NHttpMessageParser;
+import org.apache.hc.core5.http.nio.NHttpMessageWriter;
+import org.apache.hc.core5.http.nio.SessionInputBuffer;
+import org.apache.hc.core5.http.nio.SessionOutputBuffer;
+import org.apache.hc.core5.http.nio.command.ExecutionCommand;
+import org.apache.hc.core5.http.nio.command.ShutdownType;
+import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.Asserts;
+
+public class ServerHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpRequest, HttpResponse> {
+
+ private final HttpProcessor httpProcessor;
+ private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
+ private final int fragmentSizeHint;
+ private final H1Config h1Config;
+ private final ConnectionReuseStrategy connectionReuseStrategy;
+ private final ContentLengthStrategy incomingContentStrategy;
+ private final ContentLengthStrategy outgoingContentStrategy;
+ private final Http1StreamListener streamListener;
+ private final ByteBuffer contentBuffer;
+ private final Queue<ServerHttp1StreamHandler> pipeline;
+ private final Http1StreamChannel<HttpResponse> outputChannel;
+
+ private volatile boolean inconsistent;
+ private volatile ServerHttp1StreamHandler outgoing;
+ private volatile ServerHttp1StreamHandler incoming;
+
+ public ServerHttp1StreamDuplexer(
+ final IOSession ioSession,
+ final HttpProcessor httpProcessor,
+ final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
+ final H1Config h1Config,
+ final ConnectionConfig connectionConfig,
+ final ConnectionReuseStrategy connectionReuseStrategy,
+ final NHttpMessageParser<HttpRequest> incomingMessageParser,
+ final NHttpMessageWriter<HttpResponse> outgoingMessageWriter,
+ final ContentLengthStrategy incomingContentStrategy,
+ final ContentLengthStrategy outgoingContentStrategy,
+ final ConnectionListener connectionListener,
+ final Http1StreamListener streamListener) {
+ super(ioSession, connectionConfig, incomingMessageParser, outgoingMessageWriter, connectionListener);
+ this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
+ this.exchangeHandlerFactory = Args.notNull(exchangeHandlerFactory, "Exchange handler factory");
+ final int fragmentSizeHint = connectionConfig.getFragmentSizeHint();
+ final int bufferSize = connectionConfig.getBufferSize();
+ this.fragmentSizeHint = fragmentSizeHint >= 0 ? fragmentSizeHint : bufferSize;
+ this.h1Config = h1Config != null ? h1Config : H1Config.DEFAULT;
+ this.connectionReuseStrategy = connectionReuseStrategy != null ? connectionReuseStrategy :
+ DefaultConnectionReuseStrategy.INSTANCE;
+ this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
+ DefaultContentLengthStrategy.INSTANCE;
+ this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
+ DefaultContentLengthStrategy.INSTANCE;
+ this.streamListener = streamListener;
+ this.contentBuffer = ByteBuffer.allocate(connectionConfig.getBufferSize());
+ this.pipeline = new ConcurrentLinkedQueue<>();
+ this.outputChannel = new Http1StreamChannel<HttpResponse>() {
+
+ @Override
+ public void submit(final HttpResponse response, final boolean endStream) throws HttpException, IOException {
+ if (streamListener != null) {
+ streamListener.onResponseHead(ServerHttp1StreamDuplexer.this, response);
+ }
+ commitMessageHead(response, endStream);
+ }
+
+ @Override
+ public void update(final int increment) throws IOException {
+ if (increment > 0) {
+ requestSessionInput();
+ }
+ }
+
+ @Override
+ public void suspendInput() {
+ suspendSessionInput();
+ }
+
+ @Override
+ public void requestInput() {
+ requestSessionInput();
+ }
+
+ @Override
+ public void requestOutput() {
+ requestSessionOutput();
+ }
+
+ @Override
+ public void suspendOutput() {
+ suspendSessionOutput();
+ }
+
+ @Override
+ public int write(final ByteBuffer src) throws IOException {
+ return streamOutput(src);
+ }
+
+ @Override
+ public void complete() throws IOException {
+ endOutputStream();
+ }
+
+ @Override
+ public boolean isCompleted() {
+ return isOutputCompleted();
+ }
+
+ @Override
+ public void abortOutput() throws IOException {
+ final MessageDelineation messageDelineation = endOutputStream();
+ if (messageDelineation == MessageDelineation.MESSAGE_HEAD) {
+ inconsistent = true;
+ }
+ }
+
+ @Override
+ public void activate() throws HttpException, IOException {
+ }
+
+ };
+ }
+
+ @Override
+ public void releaseResources() {
+ if (incoming != null) {
+ incoming.releaseResources();
+ incoming = null;
+ }
+ if (outgoing != null) {
+ outgoing.releaseResources();
+ outgoing = null;
+ }
+ for (;;) {
+ final ServerHttp1StreamHandler handler = pipeline.poll();
+ if (handler != null) {
+ handler.releaseResources();
+ } else {
+ break;
+ }
+ }
+ }
+
+ @Override
+ void terminate(final Exception exception) {
+ if (incoming != null) {
+ incoming.failed(exception);
+ incoming = null;
+ }
+ if (outgoing != null) {
+ outgoing.failed(exception);
+ outgoing = null;
+ }
+ for (;;) {
+ final ServerHttp1StreamHandler handler = pipeline.poll();
+ if (handler != null) {
+ handler.failed(exception);
+ } else {
+ break;
+ }
+ }
+ }
+
+ @Override
+ void updateInputMetrics(final HttpRequest request, final BasicHttpConnectionMetrics connMetrics) {
+ connMetrics.incrementRequestCount();
+ }
+
+ @Override
+ void updateOutputMetrics(final HttpResponse response, final BasicHttpConnectionMetrics connMetrics) {
+ if (response.getCode() >= 200) {
+ connMetrics.incrementRequestCount();
+ }
+ }
+
+ @Override
+ protected ContentDecoder handleIncomingMessage(
+ final HttpRequest request,
+ final ReadableByteChannel channel,
+ final SessionInputBuffer buffer,
+ final BasicHttpTransportMetrics metrics) throws HttpException {
+ final long len = incomingContentStrategy.determineLength(request);
+ if (len >= 0) {
+ return new LengthDelimitedDecoder(channel, buffer, metrics, len);
+ } else if (len == ContentLengthStrategy.CHUNKED) {
+ return new ChunkDecoder(channel, buffer, h1Config, metrics);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ protected ContentEncoder handleOutgoingMessage(
+ final HttpResponse response,
+ final WritableByteChannel channel,
+ final SessionOutputBuffer buffer,
+ final BasicHttpTransportMetrics metrics) throws HttpException {
+ final long len = outgoingContentStrategy.determineLength(response);
+ if (len >= 0) {
+ return new LengthDelimitedEncoder(channel, buffer, metrics, len, fragmentSizeHint);
+ } else if (len == ContentLengthStrategy.CHUNKED) {
+ return new ChunkEncoder(channel, buffer, metrics, fragmentSizeHint, null);
+ } else {
+ return new IdentityEncoder(channel, buffer, metrics, fragmentSizeHint);
+ }
+ }
+
+ @Override
+ boolean inputIdle() {
+ return incoming == null;
+ }
+
+ @Override
+ boolean outputIdle() {
+ return outgoing == null && pipeline.isEmpty();
+ }
+
+ @Override
+ void consumeHeader(final HttpRequest request, final boolean endStream) throws HttpException, IOException {
+ if (streamListener != null) {
+ streamListener.onRequestHead(this, request);
+ }
+ final ServerHttp1StreamHandler streamHandler;
+ if (outgoing == null) {
+ streamHandler = new ServerHttp1StreamHandler(this,
+ outputChannel,
+ httpProcessor,
+ connectionReuseStrategy,
+ exchangeHandlerFactory,
+ contentBuffer);
+ outgoing = streamHandler;
+ } else {
+ streamHandler = new ServerHttp1StreamHandler(this,
+ new DelayedOutputChannel(outputChannel),
+ httpProcessor,
+ connectionReuseStrategy,
+ exchangeHandlerFactory,
+ contentBuffer);
+ pipeline.add(streamHandler);
+ }
+ streamHandler.consumeHeader(request, endStream);
+ incoming = streamHandler;
+ }
+
+ @Override
+ void consumeData(final ContentDecoder contentDecoder) throws HttpException, IOException {
+ Asserts.notNull(incoming, "Request stream handler");
+ incoming.consumeData(contentDecoder);
+ }
+
+ @Override
+ void inputEnd() throws HttpException, IOException {
+ if (incoming != null) {
+ if (incoming.isCompleted()) {
+ incoming.releaseResources();
+ }
+ incoming = null;
+ }
+ }
+
+ @Override
+ void execute(final ExecutionCommand executionCommand) throws HttpException {
+ throw new HttpException("Illegal command: " + executionCommand.getClass());
+ }
+
+ @Override
+ boolean isOutputReady() {
+ return outgoing != null && outgoing.isOutputReady();
+ }
+
+ @Override
+ void produceOutput() throws HttpException, IOException {
+ Asserts.notNull(outgoing, "Response stream handler");
+ outgoing.produceOutput();
+ }
+
+ @Override
+ void outputEnd() throws HttpException, IOException {
+ if (outgoing != null && outgoing.isResponseCompleted()) {
+ final boolean keepAlive = !inconsistent && outgoing.keepAlive();
+ if (outgoing.isCompleted()) {
+ outgoing.releaseResources();
+ }
+ outgoing = null;
+ if (streamListener != null) {
+ streamListener.onExchangeComplete(this, keepAlive);
+ }
+ if (!keepAlive) {
+ if (incoming == null && pipeline.isEmpty()) {
+ requestShutdown(ShutdownType.IMMEDIATE);
+ } else {
+ doTerminate(new ConnectionClosedException("Connection cannot be kept alive"));
+ }
+ }
+ }
+ if (outgoing == null) {
+ final ServerHttp1StreamHandler handler = pipeline.poll();
+ if (handler != null) {
+ outgoing = handler;
+ handler.activateChannel();
+ if (handler.isOutputReady()) {
+ handler.produceOutput();
+ }
+ }
+ }
+ }
+
+ @Override
+ boolean handleTimeout() {
+ return false;
+ }
+
+ private static class DelayedOutputChannel implements Http1StreamChannel<HttpResponse> {
+
+ private final Http1StreamChannel<HttpResponse> channel;
+
+ private volatile boolean direct;
+ private volatile HttpResponse delayedResponse;
+ private volatile boolean completed;
+
+ private DelayedOutputChannel(final Http1StreamChannel<HttpResponse> channel) {
+ this.channel = channel;
+ }
+
+ @Override
+ public void submit(final HttpResponse response, final boolean endStream) throws HttpException, IOException {
+ synchronized (this) {
+ if (direct) {
+ channel.submit(response, endStream);
+ } else {
+ delayedResponse = response;
+ completed = endStream;
+ }
+ }
+ }
+
+ @Override
+ public void update(final int increment) throws IOException {
+ if (increment > 0) {
+ channel.requestInput();
+ }
+ }
+
+ @Override
+ public void suspendInput() {
+ channel.suspendInput();
+ }
+
+ @Override
+ public void requestInput() {
+ channel.requestInput();
+ }
+
+ @Override
+ public void suspendOutput() {
+ channel.suspendOutput();
+ }
+
+ @Override
+ public void requestOutput() {
+ channel.requestOutput();
+ }
+
+ @Override
+ public int write(final ByteBuffer src) throws IOException {
+ synchronized (this) {
+ if (direct) {
+ return channel.write(src);
+ } else {
+ return 0;
+ }
+ }
+ }
+
+ @Override
+ public void complete() throws IOException {
+ synchronized (this) {
+ if (direct) {
+ channel.complete();
+ } else {
+ completed = true;
+ }
+ }
+ }
+
+ @Override
+ public void abortOutput() throws IOException {
+ synchronized (this) {
+ if (direct) {
+ channel.abortOutput();
+ } else {
+ completed = true;
+ }
+ }
+ }
+
+ @Override
+ public boolean isCompleted() {
+ synchronized (this) {
+ if (direct) {
+ return channel.isCompleted();
+ } else {
+ return completed;
+ }
+ }
+ }
+
+ @Override
+ public void activate() throws IOException, HttpException {
+ synchronized (this) {
+ direct = true;
+ if (delayedResponse != null) {
+ channel.submit(delayedResponse, completed);
+ delayedResponse = null;
+ }
+ }
+ }
+
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java?rev=1767339&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java Mon Oct 31 17:33:27 2016
@@ -0,0 +1,381 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http.impl.nio;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.hc.core5.http.ConnectionReuseStrategy;
+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;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.MethodNotSupportedException;
+import org.apache.hc.core5.http.MisdirectedRequestException;
+import org.apache.hc.core5.http.NotImplementedException;
+import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.UnsupportedHttpVersionException;
+import org.apache.hc.core5.http.impl.LazyEntityDetails;
+import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.apache.hc.core5.http.nio.AsyncPushProducer;
+import org.apache.hc.core5.http.nio.AsyncResponseProducer;
+import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
+import org.apache.hc.core5.http.nio.BasicResponseProducer;
+import org.apache.hc.core5.http.nio.ContentDecoder;
+import org.apache.hc.core5.http.nio.DataStreamChannel;
+import org.apache.hc.core5.http.nio.ExpectationChannel;
+import org.apache.hc.core5.http.nio.HandlerFactory;
+import org.apache.hc.core5.http.nio.ResourceHolder;
+import org.apache.hc.core5.http.nio.ResponseChannel;
+import org.apache.hc.core5.http.nio.support.ImmediateResponseExchangeHandler;
+import org.apache.hc.core5.http.protocol.HttpCoreContext;
+import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.util.Asserts;
+
+class ServerHttp1StreamHandler implements ResourceHolder {
+
+ private final HttpConnection connection;
+ private final Http1StreamChannel<HttpResponse> outputChannel;
+ private final DataStreamChannel internalDataChannel;
+ private final HttpProcessor httpProcessor;
+ private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
+ private final ConnectionReuseStrategy connectionReuseStrategy;
+ private final HttpCoreContext context;
+ private final ByteBuffer inputBuffer;
+ private final AtomicBoolean responseCommitted;
+ private final AtomicBoolean done;
+
+ private volatile AsyncServerExchangeHandler exchangeHandler;
+ private volatile HttpRequest receivedRequest;
+ private volatile HttpResponse committedResponse;
+ private volatile MessageState requestState;
+ private volatile MessageState responseState;
+
+ ServerHttp1StreamHandler(
+ final HttpConnection connection,
+ final Http1StreamChannel<HttpResponse> outputChannel,
+ final HttpProcessor httpProcessor,
+ final ConnectionReuseStrategy connectionReuseStrategy,
+ final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
+ final ByteBuffer inputBuffer) {
+ this.connection = connection;
+ this.outputChannel = outputChannel;
+ this.internalDataChannel = new DataStreamChannel() {
+
+ @Override
+ public void requestOutput() {
+ outputChannel.requestOutput();
+ }
+
+ @Override
+ public void endStream(final List<Header> trailers) throws IOException {
+ outputChannel.complete();
+ responseState = MessageState.COMPLETE;
+ }
+
+ @Override
+ public int write(final ByteBuffer src) throws IOException {
+ return outputChannel.write(src);
+ }
+
+ @Override
+ public void endStream() throws IOException {
+ endStream(null);
+ }
+
+ };
+
+ this.httpProcessor = httpProcessor;
+ this.connectionReuseStrategy = connectionReuseStrategy;
+ this.exchangeHandlerFactory = exchangeHandlerFactory;
+ this.context = HttpCoreContext.create();
+ this.inputBuffer = inputBuffer;
+ this.responseCommitted = new AtomicBoolean(false);
+ this.done = new AtomicBoolean(false);
+ this.requestState = MessageState.HEADERS;
+ this.responseState = MessageState.IDLE;
+ }
+
+ private void validateResponse(
+ final HttpResponse response,
+ final EntityDetails responseEntityDetails) throws HttpException {
+ final int status = response.getCode();
+ switch (status) {
+ case HttpStatus.SC_NO_CONTENT:
+ case HttpStatus.SC_NOT_MODIFIED:
+ if (responseEntityDetails != null) {
+ throw new HttpException("Response " + status + " must not enclose an entity");
+ }
+ }
+ }
+
+ private void commitResponse(
+ final HttpResponse response,
+ final EntityDetails responseEntityDetails) throws HttpException, IOException {
+ if (responseCommitted.compareAndSet(false, true)) {
+
+ Asserts.notNull(receivedRequest, "Received request");
+ final String method = receivedRequest.getMethod();
+ context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
+ httpProcessor.process(response, responseEntityDetails, context);
+
+ final boolean endStream = responseEntityDetails == null || method.equalsIgnoreCase("HEAD");
+ outputChannel.submit(response, endStream);
+ committedResponse = response;
+ if (endStream) {
+ responseState = MessageState.COMPLETE;
+ } else {
+ responseState = MessageState.BODY;
+ exchangeHandler.produce(internalDataChannel);
+ }
+ } else {
+ throw new HttpException("Response already committed");
+ }
+ }
+
+ private void commitContinue() throws IOException, HttpException {
+ final HttpResponse ack = new BasicHttpResponse(HttpStatus.SC_CONTINUE);
+ outputChannel.submit(ack, false);
+ responseState = MessageState.ACK;
+ }
+
+ private void commitPromise() throws HttpException {
+ throw new ProtocolException("HTTP/1.1 does not support server push");
+ }
+
+ void activateChannel() throws IOException, HttpException {
+ outputChannel.activate();
+ }
+
+ boolean isResponseCompleted() {
+ return responseState == MessageState.COMPLETE;
+ }
+
+ boolean isCompleted() {
+ return requestState == MessageState.COMPLETE && responseState == MessageState.COMPLETE;
+ }
+
+ boolean keepAlive() {
+ return receivedRequest != null && committedResponse != null &&
+ connectionReuseStrategy.keepAlive(receivedRequest, committedResponse, context);
+ }
+
+ AsyncResponseProducer handleException(final Exception ex) {
+ final int code;
+ if (ex instanceof MethodNotSupportedException) {
+ code = HttpStatus.SC_NOT_IMPLEMENTED;
+ } else if (ex instanceof UnsupportedHttpVersionException) {
+ code = HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED;
+ } else if (ex instanceof NotImplementedException) {
+ code = HttpStatus.SC_NOT_IMPLEMENTED;
+ } else if (ex instanceof ProtocolException) {
+ code = HttpStatus.SC_BAD_REQUEST;
+ } else {
+ code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
+ }
+ String message = ex.getMessage();
+ if (message == null) {
+ message = ex.toString();
+ }
+ return new BasicResponseProducer(code, message);
+ }
+
+ void consumeHeader(final HttpRequest request, final boolean requestEndStream) throws HttpException, IOException {
+ if (done.get() || requestState != MessageState.HEADERS) {
+ throw new ProtocolException("Unexpected message head");
+ }
+ receivedRequest = request;
+ requestState = requestEndStream ? MessageState.COMPLETE : MessageState.BODY;
+
+ final EntityDetails requestEntityDetails = requestEndStream ? null : new LazyEntityDetails(request);
+ boolean expectContinue = false;
+ if (requestEntityDetails != null) {
+ final Header h = request.getFirstHeader(HttpHeaders.EXPECT);
+ if (h != null && "100-continue".equalsIgnoreCase(h.getValue())) {
+ expectContinue = true;
+ }
+ }
+
+ AsyncServerExchangeHandler handler;
+ try {
+ handler = exchangeHandlerFactory.create(request);
+ } catch (MisdirectedRequestException ex) {
+ handler = new ImmediateResponseExchangeHandler(HttpStatus.SC_MISDIRECTED_REQUEST, ex.getMessage());
+ } catch (HttpException ex) {
+ handler = new ImmediateResponseExchangeHandler(HttpStatus.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
+ }
+ if (handler == null) {
+ handler = new ImmediateResponseExchangeHandler(HttpStatus.SC_NOT_FOUND, "Cannot handle request");
+ }
+
+ exchangeHandler = handler;
+
+ final ProtocolVersion transportVersion = request.getVersion();
+ context.setProtocolVersion(transportVersion);
+ context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
+ context.setAttribute(HttpCoreContext.HTTP_CONNECTION, connection);
+
+ exchangeHandler.setContext(context);
+
+ try {
+ httpProcessor.process(request, requestEntityDetails, context);
+ } catch (HttpException ex) {
+ expectContinue = false;
+ final AsyncResponseProducer responseProducer = handleException(ex);
+ exchangeHandler = new ImmediateResponseExchangeHandler(responseProducer);
+ }
+
+ if (expectContinue) {
+ exchangeHandler.verify(request, requestEntityDetails, new ExpectationChannel() {
+
+ @Override
+ public void sendResponse(
+ final HttpResponse response, final EntityDetails responseEntityDetails) throws HttpException, IOException {
+ validateResponse(response, responseEntityDetails);
+ commitResponse(response, responseEntityDetails);
+ }
+
+ @Override
+ public void sendContinue() throws HttpException, IOException {
+ commitContinue();
+ }
+
+ });
+ } else {
+ exchangeHandler.handleRequest(request, requestEntityDetails, new ResponseChannel() {
+
+ @Override
+ public void sendResponse(
+ final HttpResponse response, final EntityDetails responseEntityDetails) throws HttpException, IOException {
+ validateResponse(response, responseEntityDetails);
+ commitResponse(response, responseEntityDetails);
+ }
+
+ @Override
+ public void pushPromise(
+ final HttpRequest promise, final AsyncPushProducer pushProducer) throws HttpException, IOException {
+ commitPromise();
+ }
+
+ });
+ }
+ }
+
+ boolean isOutputReady() {
+ switch (responseState) {
+ case ACK:
+ return true;
+ case BODY:
+ return exchangeHandler.available() > 0;
+ default:
+ return false;
+ }
+ }
+
+ void produceOutput() throws HttpException, IOException {
+ switch (responseState) {
+ case ACK:
+ responseState = MessageState.HEADERS;
+ Asserts.notNull(receivedRequest, "Received request");
+ exchangeHandler.handleRequest(receivedRequest, new LazyEntityDetails(receivedRequest), new ResponseChannel() {
+
+ @Override
+ public void sendResponse(
+ final HttpResponse response, final EntityDetails responseEntityDetails) throws HttpException, IOException {
+ validateResponse(response, responseEntityDetails);
+ commitResponse(response, responseEntityDetails);
+ }
+
+ @Override
+ public void pushPromise(
+ final HttpRequest promise, final AsyncPushProducer pushProducer) throws HttpException, IOException {
+ commitPromise();
+ }
+
+ });
+ break;
+ case BODY:
+ exchangeHandler.produce(internalDataChannel);
+ break;
+ }
+ }
+
+ void consumeData(final ContentDecoder contentDecoder) throws HttpException, IOException {
+ if (done.get() || requestState != MessageState.BODY) {
+ throw new ProtocolException("Unexpected message data");
+ }
+ if (responseState == MessageState.ACK) {
+ outputChannel.requestOutput();
+ }
+ while (contentDecoder.read(inputBuffer) > 0) {
+ inputBuffer.flip();
+ final int capacity = exchangeHandler.consume(inputBuffer);
+ inputBuffer.clear();
+ if (capacity <= 0) {
+ if (!contentDecoder.isCompleted()) {
+ outputChannel.suspendInput();
+ exchangeHandler.updateCapacity(outputChannel);
+ }
+ break;
+ }
+ }
+ if (contentDecoder.isCompleted()) {
+ requestState = MessageState.COMPLETE;
+ exchangeHandler.streamEnd(null);
+ }
+ }
+
+ void failed(final Exception cause) {
+ exchangeHandler.failed(cause);
+ }
+
+ @Override
+ public void releaseResources() {
+ if (done.compareAndSet(false, true)) {
+ requestState = MessageState.COMPLETE;
+ responseState = MessageState.COMPLETE;
+ exchangeHandler.releaseResources();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "[" +
+ "requestState=" + requestState +
+ ", responseState=" + responseState +
+ ']';
+ }
+
+}
+
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java Mon Oct 31 17:33:27 2016
@@ -38,7 +38,7 @@ import java.nio.charset.CoderResult;
import org.apache.hc.core5.http.Chars;
import org.apache.hc.core5.http.MessageConstraintException;
-import org.apache.hc.core5.http.config.MessageConstraints;
+import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.nio.SessionInputBuffer;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.ByteBufferAllocator;
@@ -54,7 +54,7 @@ import org.apache.hc.core5.util.HeapByte
public class SessionInputBufferImpl extends ExpandableBuffer implements SessionInputBuffer {
private final CharsetDecoder chardecoder;
- private final MessageConstraints constraints;
+ private final H1Config constraints;
private final int lineBuffersize;
private CharBuffer charbuffer;
@@ -68,7 +68,7 @@ public class SessionInputBufferImpl exte
* @param chardecoder chardecoder to be used for decoding HTTP protocol elements.
* If {@code null} simple type cast will be used for byte to char conversion.
* @param constraints Message constraints. If {@code null}
- * {@link MessageConstraints#DEFAULT} will be used.
+ * {@link H1Config#DEFAULT} will be used.
* @param allocator memory allocator.
* If {@code null} {@link HeapByteBufferAllocator#INSTANCE} will be used.
*
@@ -77,12 +77,12 @@ public class SessionInputBufferImpl exte
public SessionInputBufferImpl(
final int buffersize,
final int lineBuffersize,
- final MessageConstraints constraints,
+ final H1Config constraints,
final CharsetDecoder chardecoder,
final ByteBufferAllocator allocator) {
super(buffersize, allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE);
this.lineBuffersize = Args.positive(lineBuffersize, "Line buffer size");
- this.constraints = constraints != null ? constraints : MessageConstraints.DEFAULT;
+ this.constraints = constraints != null ? constraints : H1Config.DEFAULT;
this.chardecoder = chardecoder;
}
@@ -124,7 +124,7 @@ public class SessionInputBufferImpl exte
public SessionInputBufferImpl(
final int buffersize,
final int lineBuffersize,
- final MessageConstraints constraints,
+ final H1Config constraints,
final Charset charset) {
this(buffersize, lineBuffersize, constraints,
charset != null ? charset.newDecoder() : null, HeapByteBufferAllocator.INSTANCE);