Browse Source

Clarified that getBody() never returns null

As the only place that historically differed, HttpComponents(Async)ClientHttpResponse returns an empty stream instead of null now.

Issue: SPR-13563
(cherry picked from commit a5f81a0)
pull/931/head
Juergen Hoeller 10 years ago
parent
commit
ca60d796a8
  1. 7
      spring-web/src/main/java/org/springframework/http/HttpInputMessage.java
  2. 8
      spring-web/src/main/java/org/springframework/http/HttpMessage.java
  3. 7
      spring-web/src/main/java/org/springframework/http/HttpOutputMessage.java
  4. 5
      spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java
  5. 5
      spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java

7
spring-web/src/main/java/org/springframework/http/HttpInputMessage.java

@ -1,5 +1,5 @@ @@ -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; @@ -23,7 +23,8 @@ import java.io.InputStream;
* Represents an HTTP input message, consisting of {@linkplain #getHeaders() headers}
* and a readable {@linkplain #getBody() body}.
*
* <p>Typically implemented by an HTTP request on the server-side, or a response on the client-side.
* <p>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 { @@ -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;

8
spring-web/src/main/java/org/springframework/http/HttpMessage.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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 { @@ -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();

7
spring-web/src/main/java/org/springframework/http/HttpOutputMessage.java

@ -1,5 +1,5 @@ @@ -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; @@ -23,7 +23,8 @@ import java.io.OutputStream;
* Represents an HTTP output message, consisting of {@linkplain #getHeaders() headers}
* and a writable {@linkplain #getBody() body}.
*
* <p>Typically implemented by an HTTP request on the client-side, or a response on the server-side.
* <p>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 { @@ -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;

5
spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java

@ -1,5 +1,5 @@ @@ -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.
@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.http.client;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@ -72,7 +73,7 @@ final class HttpComponentsAsyncClientHttpResponse extends AbstractClientHttpResp @@ -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() : new ByteArrayInputStream(new byte[0]));
}
@Override

5
spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java

@ -1,5 +1,5 @@ @@ -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.
@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.http.client;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@ -75,7 +76,7 @@ final class HttpComponentsClientHttpResponse extends AbstractClientHttpResponse @@ -75,7 +76,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() : new ByteArrayInputStream(new byte[0]));
}
@Override

Loading…
Cancel
Save