Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 23F5317FF2 for ; Sun, 8 Feb 2015 13:14:58 +0000 (UTC) Received: (qmail 44714 invoked by uid 500); 8 Feb 2015 13:14:58 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 44674 invoked by uid 500); 8 Feb 2015 13:14:58 -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 44664 invoked by uid 99); 8 Feb 2015 13:14:58 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Feb 2015 13:14:58 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id DA77FAC003E for ; Sun, 8 Feb 2015 13:14:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1658164 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/main/java/org/apache/http/impl/nio/ httpcore-nio/src/main/java/org/apache/http/nio/entity/ httpcore-nio/src/test/java/org/apache/http/impl/nio/ httpcore/src/main/java/org/apache... Date: Sun, 08 Feb 2015 13:14:57 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150208131457.DA77FAC003E@hades.apache.org> Author: olegk Date: Sun Feb 8 13:14:56 2015 New Revision: 1658164 URL: http://svn.apache.org/r1658164 Log: Simplified HttpEntity interface; refactored HttpEntity implementation classes Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/AbstractImmutableHttpEntity.java - copied, changed from r1658163, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/FileEntity.java httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/IncomingHttpEntity.java - copied, changed from r1658163, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/HttpEntityWrapper.java Removed: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestAbstractHttpEntity.java Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentBufferEntity.java httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpEntity.java httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/AbstractHttpEntity.java httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BasicHttpEntity.java httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ByteArrayEntity.java httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/FileEntity.java httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/HttpEntityWrapper.java httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/SerializableEntity.java httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestContent.java httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseContent.java httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestBasicHttpEntity.java httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestBHttpConnectionBase.java httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestEntityUtils.java Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java (original) +++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java Sun Feb 8 13:14:56 2015 @@ -36,7 +36,6 @@ import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; import org.apache.http.ConnectionClosedException; -import org.apache.http.Header; import org.apache.http.HttpConnectionMetrics; import org.apache.http.HttpEntity; import org.apache.http.HttpException; @@ -45,9 +44,9 @@ import org.apache.http.HttpMessage; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; import org.apache.http.config.MessageConstraints; -import org.apache.http.entity.BasicHttpEntity; import org.apache.http.entity.ContentLengthStrategy; import org.apache.http.impl.HttpConnectionMetricsImpl; +import org.apache.http.impl.IncomingHttpEntity; import org.apache.http.impl.io.HttpTransportMetricsImpl; import org.apache.http.impl.nio.codecs.ChunkDecoder; import org.apache.http.impl.nio.codecs.ChunkEncoder; @@ -189,26 +188,11 @@ class NHttpConnectionBase implements NHt HttpEntity createIncomingEntity( final HttpMessage message, final long len) throws HttpException { - final BasicHttpEntity entity = new BasicHttpEntity(); - if (len >= 0) { - entity.setChunked(false); - entity.setContentLength(len); - } else if (len == ContentLengthStrategy.CHUNKED) { - entity.setChunked(true); - entity.setContentLength(-1); - } else { - entity.setChunked(false); - entity.setContentLength(-1); - } - final Header contentTypeHeader = message.getFirstHeader(HttpHeaders.CONTENT_TYPE); - if (contentTypeHeader != null) { - entity.setContentType(contentTypeHeader); - } - final Header contentEncodingHeader = message.getFirstHeader(HttpHeaders.CONTENT_ENCODING); - if (contentEncodingHeader != null) { - entity.setContentEncoding(contentEncodingHeader); - } - return entity; + return new IncomingHttpEntity( + null, + len >= 0 ? len : -1, len == ContentLengthStrategy.CHUNKED, + message.getFirstHeader(HttpHeaders.CONTENT_TYPE), + message.getFirstHeader(HttpHeaders.CONTENT_ENCODING)); } /** Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentBufferEntity.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentBufferEntity.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentBufferEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentBufferEntity.java Sun Feb 8 13:14:56 2015 @@ -27,7 +27,6 @@ package org.apache.http.nio.entity; -import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.annotation.NotThreadSafe; import org.apache.http.entity.BasicHttpEntity; @@ -69,12 +68,12 @@ public class ContentBufferEntity extends } @Override - public Header getContentType() { + public String getContentType() { return this.wrappedEntity.getContentType(); } @Override - public Header getContentEncoding() { + public String getContentEncoding() { return this.wrappedEntity.getContentEncoding(); } Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java Sun Feb 8 13:14:56 2015 @@ -34,8 +34,8 @@ import java.io.OutputStream; import java.nio.ByteBuffer; import org.apache.http.annotation.NotThreadSafe; -import org.apache.http.entity.AbstractHttpEntity; import org.apache.http.entity.ContentType; +import org.apache.http.entity.AbstractHttpEntity; import org.apache.http.nio.ContentEncoder; import org.apache.http.nio.IOControl; import org.apache.http.util.Args; Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java Sun Feb 8 13:14:56 2015 @@ -36,8 +36,8 @@ import java.io.RandomAccessFile; import java.nio.channels.FileChannel; import org.apache.http.annotation.NotThreadSafe; -import org.apache.http.entity.AbstractHttpEntity; import org.apache.http.entity.ContentType; +import org.apache.http.entity.AbstractHttpEntity; import org.apache.http.nio.ContentEncoder; import org.apache.http.nio.ContentEncoderChannel; import org.apache.http.nio.FileContentEncoder; Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java Sun Feb 8 13:14:56 2015 @@ -37,8 +37,8 @@ import java.nio.charset.Charset; import org.apache.http.Consts; import org.apache.http.annotation.NotThreadSafe; -import org.apache.http.entity.AbstractHttpEntity; import org.apache.http.entity.ContentType; +import org.apache.http.entity.AbstractHttpEntity; import org.apache.http.nio.ContentEncoder; import org.apache.http.nio.IOControl; import org.apache.http.util.Args; Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java (original) +++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java Sun Feb 8 13:14:56 2015 @@ -31,7 +31,6 @@ import java.net.InetSocketAddress; import java.nio.channels.ByteChannel; import java.nio.channels.SelectionKey; -import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpHeaders; import org.apache.http.HttpVersion; @@ -197,10 +196,8 @@ public class TestNHttpConnectionBase { Assert.assertNotNull(entity); Assert.assertEquals(-1, entity.getContentLength()); Assert.assertFalse(entity.isChunked()); - final Header h1 = entity.getContentType(); - Assert.assertNull(h1); - final Header h2 = entity.getContentEncoding(); - Assert.assertNull(h2); + Assert.assertNull(entity.getContentType()); + Assert.assertNull(entity.getContentEncoding()); } @Test @@ -214,12 +211,8 @@ public class TestNHttpConnectionBase { Assert.assertNotNull(entity); Assert.assertEquals(10, entity.getContentLength()); Assert.assertFalse(entity.isChunked()); - final Header h1 = entity.getContentType(); - Assert.assertNotNull(h1); - Assert.assertEquals("stuff", h1.getValue()); - final Header h2 = entity.getContentEncoding(); - Assert.assertNotNull(h2); - Assert.assertEquals("identity", h2.getValue()); + Assert.assertEquals("stuff", entity.getContentType()); + Assert.assertEquals("identity", entity.getContentEncoding()); } @Test @@ -233,12 +226,8 @@ public class TestNHttpConnectionBase { Assert.assertNotNull(entity); Assert.assertEquals(-1, entity.getContentLength()); Assert.assertTrue(entity.isChunked()); - final Header h1 = entity.getContentType(); - Assert.assertNotNull(h1); - Assert.assertEquals("stuff", h1.getValue()); - final Header h2 = entity.getContentEncoding(); - Assert.assertNotNull(h2); - Assert.assertEquals("identity", h2.getValue()); + Assert.assertEquals("stuff", entity.getContentType()); + Assert.assertEquals("identity", entity.getContentEncoding()); } } Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpEntity.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpEntity.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpEntity.java Sun Feb 8 13:14:56 2015 @@ -104,7 +104,7 @@ public interface HttpEntity { * @return the Content-Type header for this entity, or * {@code null} if the content type is unknown */ - Header getContentType(); + String getContentType(); /** * Obtains the Content-Encoding header, if known. @@ -116,7 +116,7 @@ public interface HttpEntity { * @return the Content-Encoding header for this entity, or * {@code null} if the content encoding is unknown */ - Header getContentEncoding(); + String getContentEncoding(); /** * Returns a content stream of the entity. Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/AbstractHttpEntity.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/AbstractHttpEntity.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/AbstractHttpEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/AbstractHttpEntity.java Sun Feb 8 13:14:56 2015 @@ -27,21 +27,16 @@ package org.apache.http.entity; -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.HttpHeaders; import org.apache.http.annotation.NotThreadSafe; -import org.apache.http.message.BasicHeader; /** - * Abstract base class for entities. - * Provides the commonly used attributes for streamed and self-contained - * implementations of {@link HttpEntity HttpEntity}. + * Abstract base class for mutable entities. Provides the commonly used attributes for streamed and + * self-contained implementations. * * @since 4.0 */ @NotThreadSafe -public abstract class AbstractHttpEntity implements HttpEntity { +public abstract class AbstractHttpEntity extends AbstractImmutableHttpEntity { /** * Buffer size for output stream processing. @@ -50,147 +45,35 @@ public abstract class AbstractHttpEntity */ static final int OUTPUT_BUFFER_SIZE = 4096; - private Header contentType; - private Header contentEncoding; + private String contentType; + private String contentEncoding; private boolean chunked; - /** - * Obtains the Content-Type header. - * The default implementation returns the value of the - * {@link #contentType contentType} attribute. - * - * @return the Content-Type header, or {@code null} - */ @Override - public Header getContentType() { + public String getContentType() { return this.contentType; } - - /** - * Obtains the Content-Encoding header. - * The default implementation returns the value of the - * {@link #contentEncoding contentEncoding} attribute. - * - * @return the Content-Encoding header, or {@code null} - */ @Override - public Header getContentEncoding() { + public String getContentEncoding() { return this.contentEncoding; } - /** - * Obtains the 'chunked' flag. - * The default implementation returns the value of the - * {@link #chunked chunked} attribute. - * - * @return the 'chunked' flag - */ @Override public boolean isChunked() { return this.chunked; } - - /** - * Specifies the Content-Type header. - * The default implementation sets the value of the - * {@link #contentType contentType} attribute. - * - * @param contentType the new Content-Encoding header, or - * {@code null} to unset - */ - public void setContentType(final Header contentType) { + public void setContentType(final String contentType) { this.contentType = contentType; } - /** - * Specifies the Content-Type header, as a string. - * The default implementation calls - * {@link #setContentType(Header) setContentType(Header)}. - * - * @param ctString the new Content-Type header, or - * {@code null} to unset - */ - public void setContentType(final String ctString) { - Header h = null; - if (ctString != null) { - h = new BasicHeader(HttpHeaders.CONTENT_TYPE, ctString); - } - setContentType(h); - } - - /** - * Specifies the Content-Encoding header. - * The default implementation sets the value of the - * {@link #contentEncoding contentEncoding} attribute. - * - * @param contentEncoding the new Content-Encoding header, or - * {@code null} to unset - */ - public void setContentEncoding(final Header contentEncoding) { + public void setContentEncoding(final String contentEncoding) { this.contentEncoding = contentEncoding; } - /** - * Specifies the Content-Encoding header, as a string. - * The default implementation calls - * {@link #setContentEncoding(Header) setContentEncoding(Header)}. - * - * @param ceString the new Content-Encoding header, or - * {@code null} to unset - */ - public void setContentEncoding(final String ceString) { - Header h = null; - if (ceString != null) { - h = new BasicHeader(HttpHeaders.CONTENT_ENCODING, ceString); - } - setContentEncoding(h); - } - - - /** - * Specifies the 'chunked' flag. - *

- * Note that the chunked setting is a hint only. - * If using HTTP/1.0, chunking is never performed. - * Otherwise, even if chunked is false, HttpClient must - * use chunk coding if the entity content length is - * unknown (-1). - *

- * The default implementation sets the value of the - * {@link #chunked chunked} attribute. - * - * @param b the new 'chunked' flag - */ public void setChunked(final boolean b) { this.chunked = b; } - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append('['); - if (contentType != null) { - sb.append("Content-Type: "); - sb.append(contentType.getValue()); - sb.append(','); - } - if (contentEncoding != null) { - sb.append("Content-Encoding: "); - sb.append(contentEncoding.getValue()); - sb.append(','); - } - final long len = getContentLength(); - if (len >= 0) { - sb.append("Content-Length: "); - sb.append(len); - sb.append(','); - } - sb.append("Chunked: "); - sb.append(chunked); - sb.append(']'); - return sb.toString(); - } - } Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/AbstractImmutableHttpEntity.java (from r1658163, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/FileEntity.java) URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/AbstractImmutableHttpEntity.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/AbstractImmutableHttpEntity.java&p1=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/FileEntity.java&r1=1658163&r2=1658164&rev=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/FileEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/AbstractImmutableHttpEntity.java Sun Feb 8 13:14:56 2015 @@ -27,83 +27,61 @@ package org.apache.http.entity; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import org.apache.http.HttpEntity; import org.apache.http.annotation.NotThreadSafe; import org.apache.http.util.Args; /** - * A self contained, repeatable entity that obtains its content from a file. + * Abstract base class for immutable entities. * - * @since 4.0 + * @since 5.0 */ @NotThreadSafe -public class FileEntity extends AbstractHttpEntity implements HttpContentProducer { +public abstract class AbstractImmutableHttpEntity implements HttpEntity, HttpContentProducer { - private final File file; - - /** - * @since 4.2 - */ - public FileEntity(final File file, final ContentType contentType) { - super(); - this.file = Args.notNull(file, "File"); - if (contentType != null) { - setContentType(contentType.toString()); - } - } - - /** - * @since 4.2 - */ - public FileEntity(final File file) { - super(); - this.file = Args.notNull(file, "File"); - } - - @Override - public boolean isRepeatable() { - return true; - } - - @Override - public long getContentLength() { - return this.file.length(); - } - - @Override - public InputStream getContent() throws IOException { - return new FileInputStream(this.file); - } + static final int OUTPUT_BUFFER_SIZE = 4096; @Override public void writeTo(final OutputStream outstream) throws IOException { Args.notNull(outstream, "Output stream"); - final InputStream instream = new FileInputStream(this.file); - try { - final byte[] tmp = new byte[OUTPUT_BUFFER_SIZE]; - int l; - while ((l = instream.read(tmp)) != -1) { - outstream.write(tmp, 0, l); + final InputStream instream = getContent(); + if (instream != null) { + try { + int l; + final byte[] tmp = new byte[OUTPUT_BUFFER_SIZE]; + while ((l = instream.read(tmp)) != -1) { + outstream.write(tmp, 0, l); + } + } finally { + instream.close(); } - outstream.flush(); - } finally { - instream.close(); } } - /** - * Tells that this entity is not streaming. - * - * @return {@code false} - */ @Override - public boolean isStreaming() { - return false; + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append('['); + sb.append("Content-Type: "); + sb.append(getContentType()); + sb.append(','); + sb.append("Content-Encoding: "); + sb.append(getContentEncoding()); + sb.append(','); + final long len = getContentLength(); + if (len >= 0) { + sb.append("Content-Length: "); + sb.append(len); + sb.append(','); + } + sb.append("Chunked: "); + sb.append(isChunked()); + sb.append(']'); + return sb.toString(); } -} // class FileEntity +} Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BasicHttpEntity.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BasicHttpEntity.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BasicHttpEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BasicHttpEntity.java Sun Feb 8 13:14:56 2015 @@ -27,13 +27,10 @@ package org.apache.http.entity; -import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import org.apache.http.annotation.NotThreadSafe; import org.apache.http.impl.io.EmptyInputStream; -import org.apache.http.util.Args; import org.apache.http.util.Asserts; /** @@ -43,7 +40,7 @@ import org.apache.http.util.Asserts; * @since 4.0 */ @NotThreadSafe -public class BasicHttpEntity extends AbstractHttpEntity implements HttpContentProducer { +public class BasicHttpEntity extends AbstractHttpEntity { private InputStream content; private long length; @@ -109,21 +106,6 @@ public class BasicHttpEntity extends Abs } @Override - public void writeTo(final OutputStream outstream) throws IOException { - Args.notNull(outstream, "Output stream"); - final InputStream instream = getContent(); - try { - int l; - final byte[] tmp = new byte[OUTPUT_BUFFER_SIZE]; - while ((l = instream.read(tmp)) != -1) { - outstream.write(tmp, 0, l); - } - } finally { - instream.close(); - } - } - - @Override public boolean isStreaming() { return this.content != null && this.content != EmptyInputStream.INSTANCE; } Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ByteArrayEntity.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ByteArrayEntity.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ByteArrayEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ByteArrayEntity.java Sun Feb 8 13:14:56 2015 @@ -41,7 +41,7 @@ import org.apache.http.util.Args; * @since 4.0 */ @NotThreadSafe -public class ByteArrayEntity extends AbstractHttpEntity implements HttpContentProducer { +public class ByteArrayEntity extends AbstractHttpEntity { private final byte[] b; private final int off, len; @@ -108,7 +108,6 @@ public class ByteArrayEntity extends Abs outstream.flush(); } - /** * Tells that this entity is not streaming. * Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java Sun Feb 8 13:14:56 2015 @@ -37,7 +37,6 @@ import java.util.Locale; import java.util.Map; import org.apache.http.Consts; -import org.apache.http.Header; import org.apache.http.HeaderElement; import org.apache.http.HttpEntity; import org.apache.http.NameValuePair; @@ -263,13 +262,17 @@ public final class ContentType implement * this instance of the Java virtual machine */ public static ContentType parse(final CharSequence s) throws UnsupportedCharsetException { + return parse(s, true); + } + + private static ContentType parse(final CharSequence s, final boolean strict) throws UnsupportedCharsetException { if (TextUtils.isBlank(s)) { return null; } final ParserCursor cursor = new ParserCursor(0, s.length()); final HeaderElement[] elements = BasicHeaderValueParser.INSTANCE.parseElements(s, cursor); if (elements.length > 0) { - return create(elements[0], true); + return create(elements[0], strict); } else { return null; } @@ -290,12 +293,9 @@ public final class ContentType implement if (entity == null) { return null; } - final Header header = entity.getContentType(); - if (header != null) { - final HeaderElement[] elements = header.getElements(); - if (elements.length > 0) { - return create(elements[0], true); - } + final String contentType = entity.getContentType(); + if (contentType != null) { + return parse(contentType); } return null; } @@ -314,12 +314,9 @@ public final class ContentType implement if (entity == null) { return null; } - final Header header = entity.getContentType(); - if (header != null) { - final HeaderElement[] elements = header.getElements(); - if (elements.length > 0) { - return create(elements[0], false); - } + final String contentType = entity.getContentType(); + if (contentType != null) { + return parse(contentType, false); } return null; } Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/FileEntity.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/FileEntity.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/FileEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/FileEntity.java Sun Feb 8 13:14:56 2015 @@ -31,7 +31,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import org.apache.http.annotation.NotThreadSafe; import org.apache.http.util.Args; @@ -42,7 +41,7 @@ import org.apache.http.util.Args; * @since 4.0 */ @NotThreadSafe -public class FileEntity extends AbstractHttpEntity implements HttpContentProducer { +public class FileEntity extends AbstractHttpEntity { private final File file; @@ -80,22 +79,6 @@ public class FileEntity extends Abstract return new FileInputStream(this.file); } - @Override - public void writeTo(final OutputStream outstream) throws IOException { - Args.notNull(outstream, "Output stream"); - final InputStream instream = new FileInputStream(this.file); - try { - final byte[] tmp = new byte[OUTPUT_BUFFER_SIZE]; - int l; - while ((l = instream.read(tmp)) != -1) { - outstream.write(tmp, 0, l); - } - outstream.flush(); - } finally { - instream.close(); - } - } - /** * Tells that this entity is not streaming. * Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/HttpEntityWrapper.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/HttpEntityWrapper.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/HttpEntityWrapper.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/HttpEntityWrapper.java Sun Feb 8 13:14:56 2015 @@ -31,7 +31,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.annotation.NotThreadSafe; import org.apache.http.util.Args; @@ -75,12 +74,12 @@ public class HttpEntityWrapper implement } @Override - public Header getContentType() { + public String getContentType() { return wrappedEntity.getContentType(); } @Override - public Header getContentEncoding() { + public String getContentEncoding() { return wrappedEntity.getContentEncoding(); } Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/SerializableEntity.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/SerializableEntity.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/SerializableEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/SerializableEntity.java Sun Feb 8 13:14:56 2015 @@ -47,7 +47,7 @@ import org.apache.http.util.Args; * @since 4.0 */ @NotThreadSafe -public class SerializableEntity extends AbstractHttpEntity implements HttpContentProducer { +public class SerializableEntity extends AbstractHttpEntity { private byte[] objSer; Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java Sun Feb 8 13:14:56 2015 @@ -39,14 +39,12 @@ import java.nio.charset.CharsetEncoder; import java.util.concurrent.atomic.AtomicReference; import org.apache.http.BHttpConnection; -import org.apache.http.Header; import org.apache.http.HttpConnectionMetrics; import org.apache.http.HttpEntity; import org.apache.http.HttpException; import org.apache.http.HttpHeaders; import org.apache.http.HttpMessage; import org.apache.http.config.MessageConstraints; -import org.apache.http.entity.BasicHttpEntity; import org.apache.http.entity.ContentLengthStrategy; import org.apache.http.impl.io.ChunkedInputStream; import org.apache.http.impl.io.ChunkedOutputStream; @@ -166,28 +164,11 @@ class BHttpConnectionBase implements BHt final HttpMessage message, final SessionInputBuffer inbuffer, final long len) throws HttpException { - final BasicHttpEntity entity = new BasicHttpEntity(); - if (len >= 0) { - entity.setChunked(false); - entity.setContentLength(len); - } else if (len == ContentLengthStrategy.CHUNKED) { - entity.setChunked(true); - entity.setContentLength(-1); - } else { - entity.setChunked(false); - entity.setContentLength(-1); - } - entity.setContent(createContentInputStream(len, inbuffer)); - - final Header contentTypeHeader = message.getFirstHeader(HttpHeaders.CONTENT_TYPE); - if (contentTypeHeader != null) { - entity.setContentType(contentTypeHeader); - } - final Header contentEncodingHeader = message.getFirstHeader(HttpHeaders.CONTENT_ENCODING); - if (contentEncodingHeader != null) { - entity.setContentEncoding(contentEncodingHeader); - } - return entity; + return new IncomingHttpEntity( + createContentInputStream(len, inbuffer), + len >= 0 ? len : -1, len == ContentLengthStrategy.CHUNKED, + message.getFirstHeader(HttpHeaders.CONTENT_TYPE), + message.getFirstHeader(HttpHeaders.CONTENT_ENCODING)); } @Override Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/IncomingHttpEntity.java (from r1658163, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/HttpEntityWrapper.java) URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/IncomingHttpEntity.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/IncomingHttpEntity.java&p1=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/HttpEntityWrapper.java&r1=1658163&r2=1658164&rev=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/HttpEntityWrapper.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/IncomingHttpEntity.java Sun Feb 8 13:14:56 2015 @@ -25,80 +25,67 @@ * */ -package org.apache.http.entity; +package org.apache.http.impl; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import org.apache.http.Header; -import org.apache.http.HttpEntity; import org.apache.http.annotation.NotThreadSafe; -import org.apache.http.util.Args; +import org.apache.http.entity.AbstractImmutableHttpEntity; +import org.apache.http.entity.HttpContentProducer; +import org.apache.http.impl.io.EmptyInputStream; -/** - * Base class for wrapping entities. - * Keeps a {@link #wrappedEntity wrappedEntity} and delegates all - * calls to it. Implementations of wrapping entities can derive - * from this class and need to override only those methods that - * should not be delegated to the wrapped entity. - * - * @since 4.0 - */ @NotThreadSafe -public class HttpEntityWrapper implements HttpEntity { +public class IncomingHttpEntity extends AbstractImmutableHttpEntity implements HttpContentProducer { - /** The wrapped entity. */ - protected HttpEntity wrappedEntity; - - /** - * Creates a new entity wrapper. - */ - public HttpEntityWrapper(final HttpEntity wrappedEntity) { - super(); - this.wrappedEntity = Args.notNull(wrappedEntity, "Wrapped entity"); - } // constructor + private final InputStream content; + private final long len; + private final boolean chunked; + private final Header contentType; + private final Header contentEncoding; + + public IncomingHttpEntity(final InputStream content, final long len, final boolean chunked, final Header contentType, final Header contentEncoding) { + this.content = content; + this.len = len; + this.chunked = chunked; + this.contentType = contentType; + this.contentEncoding = contentEncoding; + } @Override public boolean isRepeatable() { - return wrappedEntity.isRepeatable(); + return false; } @Override public boolean isChunked() { - return wrappedEntity.isChunked(); + return chunked; } @Override public long getContentLength() { - return wrappedEntity.getContentLength(); - } - - @Override - public Header getContentType() { - return wrappedEntity.getContentType(); + return len; } @Override - public Header getContentEncoding() { - return wrappedEntity.getContentEncoding(); + public String getContentType() { + return contentType != null ? contentType.getValue() : null; } @Override - public InputStream getContent() - throws IOException { - return wrappedEntity.getContent(); + public String getContentEncoding() { + return contentEncoding != null ? contentEncoding.getValue() : null; } @Override - public void writeTo(final OutputStream outstream) - throws IOException { - wrappedEntity.writeTo(outstream); + public InputStream getContent() throws IOException, IllegalStateException { + return content; } @Override public boolean isStreaming() { - return wrappedEntity.isStreaming(); + return content != null && content != EmptyInputStream.INSTANCE; } } Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestContent.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestContent.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestContent.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestContent.java Sun Feb 8 13:14:56 2015 @@ -39,6 +39,7 @@ import org.apache.http.HttpVersion; import org.apache.http.ProtocolException; import org.apache.http.ProtocolVersion; import org.apache.http.annotation.Immutable; +import org.apache.http.message.BasicHeader; import org.apache.http.util.Args; /** @@ -110,14 +111,12 @@ public class RequestContent implements H request.addHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(entity.getContentLength())); } // Specify a content type if known - if (entity.getContentType() != null && !request.containsHeader( - HttpHeaders.CONTENT_TYPE )) { - request.addHeader(entity.getContentType()); + if (entity.getContentType() != null && !request.containsHeader(HttpHeaders.CONTENT_TYPE)) { + request.addHeader(new BasicHeader(HttpHeaders.CONTENT_TYPE, entity.getContentType())); } // Specify a content encoding if known - if (entity.getContentEncoding() != null && !request.containsHeader( - HttpHeaders.CONTENT_ENCODING)) { - request.addHeader(entity.getContentEncoding()); + if (entity.getContentEncoding() != null && !request.containsHeader(HttpHeaders.CONTENT_ENCODING)) { + request.addHeader(new BasicHeader(HttpHeaders.CONTENT_ENCODING, entity.getContentEncoding())); } } } Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseContent.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseContent.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseContent.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseContent.java Sun Feb 8 13:14:56 2015 @@ -40,6 +40,7 @@ import org.apache.http.HttpVersion; import org.apache.http.ProtocolException; import org.apache.http.ProtocolVersion; import org.apache.http.annotation.Immutable; +import org.apache.http.message.BasicHeader; import org.apache.http.util.Args; /** @@ -114,14 +115,12 @@ public class ResponseContent implements response.addHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(entity.getContentLength())); } // Specify a content type if known - if (entity.getContentType() != null && !response.containsHeader( - HttpHeaders.CONTENT_TYPE)) { - response.addHeader(entity.getContentType()); + if (entity.getContentType() != null && !response.containsHeader(HttpHeaders.CONTENT_TYPE)) { + response.addHeader(new BasicHeader(HttpHeaders.CONTENT_TYPE, entity.getContentType())); } // Specify a content encoding if known - if (entity.getContentEncoding() != null && !response.containsHeader( - HttpHeaders.CONTENT_ENCODING)) { - response.addHeader(entity.getContentEncoding()); + if (entity.getContentEncoding() != null && !response.containsHeader(HttpHeaders.CONTENT_ENCODING)) { + response.addHeader(new BasicHeader(HttpHeaders.CONTENT_ENCODING, entity.getContentEncoding())); } } else { final int status = response.getStatusLine().getStatusCode(); Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestBasicHttpEntity.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestBasicHttpEntity.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestBasicHttpEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestBasicHttpEntity.java Sun Feb 8 13:14:56 2015 @@ -56,6 +56,17 @@ public class TestBasicHttpEntity { } @Test + public void testToString() throws Exception { + final BasicHttpEntity httpentity = new BasicHttpEntity(); + httpentity.setContentType("blah"); + httpentity.setContentEncoding("yada"); + httpentity.setContentLength(10); + httpentity.setChunked(true); + Assert.assertEquals("[Content-Type: blah,Content-Encoding: yada,Content-Length: 10,Chunked: true]", + httpentity.toString()); + } + + @Test public void testContent() throws Exception { final byte[] bytes = "Message content".getBytes(Consts.ASCII); final InputStream content = new ByteArrayInputStream(bytes); Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java Sun Feb 8 13:14:56 2015 @@ -31,8 +31,6 @@ import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; import org.apache.http.Consts; -import org.apache.http.Header; -import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicNameValuePair; import org.junit.Assert; import org.junit.Test; @@ -156,14 +154,14 @@ public class TestContentType { @Test public void testExtractNullContentType() throws Exception { final BasicHttpEntity httpentity = new BasicHttpEntity(); - httpentity.setContentType((Header)null); + httpentity.setContentType(null); Assert.assertNull(ContentType.get(httpentity)); } @Test public void testExtract() throws Exception { final BasicHttpEntity httpentity = new BasicHttpEntity(); - httpentity.setContentType(new BasicHeader("Content-Type", "text/plain; charset = UTF-8")); + httpentity.setContentType("text/plain; charset = UTF-8"); final ContentType contentType = ContentType.get(httpentity); Assert.assertNotNull(contentType); Assert.assertEquals("text/plain", contentType.getMimeType()); @@ -173,7 +171,7 @@ public class TestContentType { @Test public void testExtractNoCharset() throws Exception { final BasicHttpEntity httpentity = new BasicHttpEntity(); - httpentity.setContentType(new BasicHeader("Content-Type", "text/plain; param=yadayada")); + httpentity.setContentType("text/plain; param=yadayada"); final ContentType contentType = ContentType.get(httpentity); Assert.assertNotNull(contentType); Assert.assertEquals("text/plain", contentType.getMimeType()); @@ -183,7 +181,7 @@ public class TestContentType { @Test(expected = UnsupportedCharsetException.class) public void testExtractInvalidCharset() throws Exception { final BasicHttpEntity httpentity = new BasicHttpEntity(); - httpentity.setContentType(new BasicHeader("Content-Type", "text/plain; charset = stuff")); + httpentity.setContentType("text/plain; charset = stuff"); ContentType.get(httpentity); } @@ -195,14 +193,14 @@ public class TestContentType { @Test public void testExtractLenientNullContentType() throws Exception { final BasicHttpEntity httpentity = new BasicHttpEntity(); - httpentity.setContentType((Header) null); + httpentity.setContentType(null); Assert.assertNull(ContentType.getLenient(httpentity)); } @Test public void testLenientExtractInvalidCharset() throws Exception { final BasicHttpEntity httpentity = new BasicHttpEntity(); - httpentity.setContentType(new BasicHeader("Content-Type", "text/plain; charset = stuff")); + httpentity.setContentType("text/plain; charset = stuff"); final ContentType contentType = ContentType.getLenient(httpentity); Assert.assertNotNull(contentType); Assert.assertEquals("text/plain", contentType.getMimeType()); Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java Sun Feb 8 13:14:56 2015 @@ -66,14 +66,11 @@ public class TestStringEntity { public void testDefaultContent() throws Exception { final String s = "Message content"; StringEntity httpentity = new StringEntity(s, ContentType.create("text/csv", "ANSI_X3.4-1968")); - Assert.assertEquals("text/csv; charset=US-ASCII", - httpentity.getContentType().getValue()); + Assert.assertEquals("text/csv; charset=US-ASCII", httpentity.getContentType()); httpentity = new StringEntity(s, Consts.ASCII); - Assert.assertEquals("text/plain; charset=US-ASCII", - httpentity.getContentType().getValue()); + Assert.assertEquals("text/plain; charset=US-ASCII", httpentity.getContentType()); httpentity = new StringEntity(s); - Assert.assertEquals("text/plain; charset=ISO-8859-1", - httpentity.getContentType().getValue()); + Assert.assertEquals("text/plain; charset=ISO-8859-1", httpentity.getContentType()); } private static String constructString(final int [] unicodeChars) { @@ -95,11 +92,11 @@ public class TestStringEntity { final String s = constructString(SWISS_GERMAN_HELLO); StringEntity httpentity = new StringEntity(s, ContentType.create("text/plain", (Charset) null)); Assert.assertNotNull(httpentity.getContentType()); - Assert.assertEquals("text/plain", httpentity.getContentType().getValue()); + Assert.assertEquals("text/plain", httpentity.getContentType()); Assert.assertEquals(s, EntityUtils.toString(httpentity)); httpentity = new StringEntity(s, (Charset) null); Assert.assertNotNull(httpentity.getContentType()); - Assert.assertEquals("text/plain", httpentity.getContentType().getValue()); + Assert.assertEquals("text/plain", httpentity.getContentType()); Assert.assertEquals(s, EntityUtils.toString(httpentity)); } Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestBHttpConnectionBase.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestBHttpConnectionBase.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestBHttpConnectionBase.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestBHttpConnectionBase.java Sun Feb 8 13:14:56 2015 @@ -35,7 +35,6 @@ import java.net.Socket; import java.net.SocketException; import java.net.SocketTimeoutException; -import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpVersion; @@ -168,12 +167,8 @@ public class TestBHttpConnectionBase { Assert.assertNotNull(entity); Assert.assertFalse(entity.isChunked()); Assert.assertEquals(10, entity.getContentLength()); - final Header ct = entity.getContentType(); - Assert.assertNotNull(ct); - Assert.assertEquals("stuff", ct.getValue()); - final Header ce = entity.getContentEncoding(); - Assert.assertNotNull(ce); - Assert.assertEquals("identity", ce.getValue()); + Assert.assertEquals("stuff", entity.getContentType()); + Assert.assertEquals("identity", entity.getContentEncoding()); final InputStream instream = entity.getContent(); Assert.assertNotNull(instream); Assert.assertTrue((instream instanceof ContentLengthInputStream)); Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java Sun Feb 8 13:14:56 2015 @@ -49,9 +49,9 @@ import org.apache.http.HttpRequestInterc import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.HttpVersion; -import org.apache.http.entity.AbstractHttpEntity; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.ContentType; +import org.apache.http.entity.AbstractHttpEntity; import org.apache.http.entity.StringEntity; import org.apache.http.impl.DefaultBHttpClientConnection; import org.apache.http.message.BasicHttpRequest; Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestEntityUtils.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestEntityUtils.java?rev=1658164&r1=1658163&r2=1658164&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestEntityUtils.java (original) +++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestEntityUtils.java Sun Feb 8 13:14:56 2015 @@ -33,7 +33,6 @@ import java.nio.charset.Charset; import org.apache.http.Consts; import org.apache.http.entity.BasicHttpEntity; -import org.apache.http.message.BasicHeader; import org.junit.Assert; import org.junit.Test; @@ -178,7 +177,7 @@ public class TestEntityUtils { final byte[] bytes = content.getBytes(Consts.ISO_8859_1); final BasicHttpEntity httpentity = new BasicHttpEntity(); httpentity.setContent(new ByteArrayInputStream(bytes)); - httpentity.setContentType(new BasicHeader("Content-Type", "text/plain")); + httpentity.setContentType("text/plain"); final String s = EntityUtils.toString(httpentity); Assert.assertEquals(content, s); } @@ -189,7 +188,7 @@ public class TestEntityUtils { final byte[] bytes = content.getBytes(Charset.forName("KOI8-R")); final BasicHttpEntity httpentity = new BasicHttpEntity(); httpentity.setContent(new ByteArrayInputStream(bytes)); - httpentity.setContentType(new BasicHeader("Content-Type", "text/plain")); + httpentity.setContentType("text/plain"); final String s = EntityUtils.toString(httpentity, "KOI8-R"); Assert.assertEquals(content, s); } @@ -200,7 +199,7 @@ public class TestEntityUtils { final byte[] bytes = content.getBytes(Consts.UTF_8); final BasicHttpEntity httpentity = new BasicHttpEntity(); httpentity.setContent(new ByteArrayInputStream(bytes)); - httpentity.setContentType(new BasicHeader("Content-Type", "text/plain; charset=UTF-8")); + httpentity.setContentType("text/plain; charset=UTF-8"); final String s = EntityUtils.toString(httpentity, "ISO-8859-1"); Assert.assertEquals(content, s); } @@ -210,7 +209,7 @@ public class TestEntityUtils { final byte[] bytes = content.getBytes("UTF-8"); final BasicHttpEntity httpentity = new BasicHttpEntity(); httpentity.setContent(new ByteArrayInputStream(bytes)); - httpentity.setContentType(new BasicHeader("Content-Type", "text/plain; charset=nosuchcharset")); + httpentity.setContentType("text/plain; charset=nosuchcharset"); final String s = EntityUtils.toString(httpentity, "UTF-8"); Assert.assertEquals(content, s); }