Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B721E200BAF for ; Mon, 31 Oct 2016 18:43:58 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B5BCF160B09; Mon, 31 Oct 2016 17:43:58 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 67A26160B06 for ; Mon, 31 Oct 2016 18:43:56 +0100 (CET) Received: (qmail 72188 invoked by uid 500); 31 Oct 2016 17:39:20 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 70111 invoked by uid 99); 31 Oct 2016 17:33:52 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Oct 2016 17:33:52 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id ECC9B1809D7 for ; Mon, 31 Oct 2016 17:33:51 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.199 X-Spam-Level: X-Spam-Status: No, score=-1.199 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 1hhGD3buOscJ for ; Mon, 31 Oct 2016 17:33:39 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 5DE5E5F644 for ; Mon, 31 Oct 2016 17:33:39 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 4DCF0E7C04 for ; Mon, 31 Oct 2016 17:33:36 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 4070C3A29C2 for ; Mon, 31 Oct 2016 17:33:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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... Date: Mon, 31 Oct 2016 17:33:33 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20161031173336.4070C3A29C2@svn01-us-west.apache.org> archived-at: Mon, 31 Oct 2016 17:43:58 -0000 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 { +public class DefaultHttpRequestParser extends AbstractMessageParser { - private final HttpRequestFactory requestFactory; + private final HttpRequestFactory 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 requestFactory, final LineParser parser, - final HttpRequestFactory 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 requestFactory, final H1Config constraints) { + this(requestFactory, null, constraints); } /** * @since 4.3 */ - public DefaultHttpRequestParser() { - this(null); + public DefaultHttpRequestParser(final HttpRequestFactory 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 { +public class DefaultHttpRequestParserFactory implements NHttpMessageParserFactory { public static final DefaultHttpRequestParserFactory INSTANCE = new DefaultHttpRequestParserFactory(); private final LineParser lineParser; - private final HttpRequestFactory requestFactory; + private final HttpRequestFactory requestFactory; - public DefaultHttpRequestParserFactory(final LineParser lineParser, - final HttpRequestFactory requestFactory) { + public DefaultHttpRequestParserFactory(final HttpRequestFactory 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 requestFactory) { + this(requestFactory, null); } public DefaultHttpRequestParserFactory() { - this(null, null); + this(null); } @Override - public NHttpMessageParser create(final MessageConstraints constraints) { - return new DefaultHttpRequestParser(lineParser, requestFactory, constraints); + public NHttpMessageParser 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 { +public class DefaultHttpRequestWriter extends AbstractMessageWriter { /** * 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 { +public class DefaultHttpRequestWriterFactory implements NHttpMessageWriterFactory { public static final DefaultHttpRequestWriterFactory INSTANCE = new DefaultHttpRequestWriterFactory(); @@ -57,8 +57,8 @@ public class DefaultHttpRequestWriterFac } @Override - public NHttpMessageWriter create() { - return new DefaultHttpRequestWriter(this.lineFormatter); + public NHttpMessageWriter 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 { +public class DefaultHttpResponseFactory implements HttpResponseFactory { 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 { +public class DefaultHttpResponseParser extends AbstractMessageParser { - private final HttpResponseFactory responseFactory; + private final HttpResponseFactory 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 responseFactory, final LineParser parser, - final HttpResponseFactory 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 responseFactory, final H1Config constraints) { + this(responseFactory, null, constraints); } /** * @since 4.3 */ - public DefaultHttpResponseParser() { - this(null); + public DefaultHttpResponseParser(final HttpResponseFactory 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 { +public class DefaultHttpResponseParserFactory implements NHttpMessageParserFactory { public static final DefaultHttpResponseParserFactory INSTANCE = new DefaultHttpResponseParserFactory(); + private final HttpResponseFactory responseFactory; private final LineParser lineParser; - private final HttpResponseFactory responseFactory; - public DefaultHttpResponseParserFactory(final LineParser lineParser, - final HttpResponseFactory responseFactory) { + public DefaultHttpResponseParserFactory(final HttpResponseFactory 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 responseFactory) { + this(responseFactory, null); } public DefaultHttpResponseParserFactory() { - this(null, null); + this(null); } @Override - public NHttpMessageParser create(final MessageConstraints constraints) { - return new DefaultHttpResponseParser(this.lineParser, this.responseFactory, constraints); + public NHttpMessageParser 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 { +public class DefaultHttpResponseWriter extends AbstractMessageWriter { /** * 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 { +public class DefaultHttpResponseWriterFactory implements NHttpMessageWriterFactory { public static final DefaultHttpResponseWriterFactory INSTANCE = new DefaultHttpResponseWriterFactory(); @@ -57,8 +57,8 @@ public class DefaultHttpResponseWriterFa } @Override - public NHttpMessageWriter create() { - return new DefaultHttpResponseWriter(this.lineFormatter); + public NHttpMessageWriter 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 @@ * . * */ - -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 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 @@ * . * */ -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 @@ * . * */ -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 @@ * . * */ -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. - *

- * 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 + * . + * + */ + +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 exchangeHandlerFactory; + private final ConnectionReuseStrategy connectionReuseStrategy; + private final ConnectionConfig connectionConfig; + private final NHttpMessageParserFactory requestParserFactory; + private final NHttpMessageWriterFactory responseWriterFactory; + private final ContentLengthStrategy incomingContentStrategy; + private final ContentLengthStrategy outgoingContentStrategy; + private final ConnectionListener connectionListener; + private final Http1StreamListener streamListener; + + public ServerHttp1IOEventHandlerFactory( + final HttpProcessor httpProcessor, + final HandlerFactory exchangeHandlerFactory, + final ConnectionConfig connectionConfig, + final ConnectionReuseStrategy connectionReuseStrategy, + final NHttpMessageParserFactory requestParserFactory, + final NHttpMessageWriterFactory 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 exchangeHandlerFactory, + final ConnectionConfig connectionConfig, + final ConnectionReuseStrategy connectionReuseStrategy, + final NHttpMessageParserFactory requestParserFactory, + final NHttpMessageWriterFactory 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 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 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 + * . + * + */ + +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 { + + private final HttpProcessor httpProcessor; + private final HandlerFactory 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 pipeline; + private final Http1StreamChannel outputChannel; + + private volatile boolean inconsistent; + private volatile ServerHttp1StreamHandler outgoing; + private volatile ServerHttp1StreamHandler incoming; + + public ServerHttp1StreamDuplexer( + final IOSession ioSession, + final HttpProcessor httpProcessor, + final HandlerFactory exchangeHandlerFactory, + final H1Config h1Config, + final ConnectionConfig connectionConfig, + final ConnectionReuseStrategy connectionReuseStrategy, + final NHttpMessageParser incomingMessageParser, + final NHttpMessageWriter 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() { + + @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 { + + private final Http1StreamChannel channel; + + private volatile boolean direct; + private volatile HttpResponse delayedResponse; + private volatile boolean completed; + + private DelayedOutputChannel(final Http1StreamChannel 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 + * . + * + */ +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 outputChannel; + private final DataStreamChannel internalDataChannel; + private final HttpProcessor httpProcessor; + private final HandlerFactory 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 outputChannel, + final HttpProcessor httpProcessor, + final ConnectionReuseStrategy connectionReuseStrategy, + final HandlerFactory 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

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);