diff --git a/spring-web/src/main/java/org/springframework/http/HttpInputMessage.java b/spring-web/src/main/java/org/springframework/http/HttpInputMessage.java index ddc1ebd55d..9aeab46b9a 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpInputMessage.java +++ b/spring-web/src/main/java/org/springframework/http/HttpInputMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,8 @@ import java.io.InputStream; * Represents an HTTP input message, consisting of {@linkplain #getHeaders() headers} * and a readable {@linkplain #getBody() body}. * - *

Typically implemented by an HTTP request on the server-side, or a response on the client-side. + *

Typically implemented by an HTTP request handle on the server side, + * or an HTTP response handle on the client side. * * @author Arjen Poutsma * @since 3.0 @@ -32,7 +33,7 @@ public interface HttpInputMessage extends HttpMessage { /** * Return the body of the message as an input stream. - * @return the input stream body + * @return the input stream body (never {@code null}) * @throws IOException in case of I/O Errors */ InputStream getBody() throws IOException; diff --git a/spring-web/src/main/java/org/springframework/http/HttpMessage.java b/spring-web/src/main/java/org/springframework/http/HttpMessage.java index 80f7ca292d..1855c44f52 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpMessage.java +++ b/spring-web/src/main/java/org/springframework/http/HttpMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,8 @@ package org.springframework.http; /** - * Represents the base interface for HTTP request and response messages. Consists of {@link HttpHeaders}, retrievable - * via {@link #getHeaders()}. + * Represents the base interface for HTTP request and response messages. + * Consists of {@link HttpHeaders}, retrievable via {@link #getHeaders()}. * * @author Arjen Poutsma * @since 3.0 @@ -27,7 +27,7 @@ public interface HttpMessage { /** * Return the headers of this message. - * @return a corresponding HttpHeaders object + * @return a corresponding HttpHeaders object (never {@code null}) */ HttpHeaders getHeaders(); diff --git a/spring-web/src/main/java/org/springframework/http/HttpOutputMessage.java b/spring-web/src/main/java/org/springframework/http/HttpOutputMessage.java index 3dae007465..fdee15b0c9 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpOutputMessage.java +++ b/spring-web/src/main/java/org/springframework/http/HttpOutputMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,8 @@ import java.io.OutputStream; * Represents an HTTP output message, consisting of {@linkplain #getHeaders() headers} * and a writable {@linkplain #getBody() body}. * - *

Typically implemented by an HTTP request on the client-side, or a response on the server-side. + *

Typically implemented by an HTTP request handle on the client side, + * or an HTTP response handle on the server side. * * @author Arjen Poutsma * @since 3.0 @@ -32,7 +33,7 @@ public interface HttpOutputMessage extends HttpMessage { /** * Return the body of the message as an output stream. - * @return the output stream body + * @return the output stream body (never {@code null}) * @throws IOException in case of I/O Errors */ OutputStream getBody() throws IOException; diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java index ecab469bc6..f25579a4e8 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.springframework.http.HttpHeaders; +import org.springframework.util.StreamUtils; /** * {@link ClientHttpResponse} implementation that uses @@ -72,7 +73,7 @@ final class HttpComponentsAsyncClientHttpResponse extends AbstractClientHttpResp @Override public InputStream getBody() throws IOException { HttpEntity entity = this.httpResponse.getEntity(); - return entity != null ? entity.getContent() : null; + return (entity != null ? entity.getContent() : StreamUtils.emptyInput()); } @Override diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java index f7bde9f791..3ef65b0e2d 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java @@ -26,6 +26,7 @@ import org.apache.http.HttpResponse; import org.apache.http.util.EntityUtils; import org.springframework.http.HttpHeaders; +import org.springframework.util.StreamUtils; /** * {@link org.springframework.http.client.ClientHttpResponse} implementation that uses @@ -76,7 +77,7 @@ final class HttpComponentsClientHttpResponse extends AbstractClientHttpResponse @Override public InputStream getBody() throws IOException { HttpEntity entity = this.httpResponse.getEntity(); - return (entity != null ? entity.getContent() : null); + return (entity != null ? entity.getContent() : StreamUtils.emptyInput()); } @Override