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
pull/888/head
Juergen Hoeller 10 years ago
parent
commit
a5f81a0433
  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. 3
      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 @@
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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} * Represents an HTTP input message, consisting of {@linkplain #getHeaders() headers}
* and a readable {@linkplain #getBody() body}. * 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 * @author Arjen Poutsma
* @since 3.0 * @since 3.0
@ -32,7 +33,7 @@ public interface HttpInputMessage extends HttpMessage {
/** /**
* Return the body of the message as an input stream. * 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 * @throws IOException in case of I/O Errors
*/ */
InputStream getBody() throws IOException; InputStream getBody() throws IOException;

8
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,8 +17,8 @@
package org.springframework.http; package org.springframework.http;
/** /**
* Represents the base interface for HTTP request and response messages. Consists of {@link HttpHeaders}, retrievable * Represents the base interface for HTTP request and response messages.
* via {@link #getHeaders()}. * Consists of {@link HttpHeaders}, retrievable via {@link #getHeaders()}.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @since 3.0 * @since 3.0
@ -27,7 +27,7 @@ public interface HttpMessage {
/** /**
* Return the headers of this message. * Return the headers of this message.
* @return a corresponding HttpHeaders object * @return a corresponding HttpHeaders object (never {@code null})
*/ */
HttpHeaders getHeaders(); HttpHeaders getHeaders();

7
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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} * Represents an HTTP output message, consisting of {@linkplain #getHeaders() headers}
* and a writable {@linkplain #getBody() body}. * 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 * @author Arjen Poutsma
* @since 3.0 * @since 3.0
@ -32,7 +33,7 @@ public interface HttpOutputMessage extends HttpMessage {
/** /**
* Return the body of the message as an output stream. * 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 * @throws IOException in case of I/O Errors
*/ */
OutputStream getBody() throws IOException; OutputStream getBody() throws IOException;

5
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.apache.http.HttpResponse;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.util.StreamUtils;
/** /**
* {@link ClientHttpResponse} implementation that uses * {@link ClientHttpResponse} implementation that uses
@ -72,7 +73,7 @@ final class HttpComponentsAsyncClientHttpResponse extends AbstractClientHttpResp
@Override @Override
public InputStream getBody() throws IOException { public InputStream getBody() throws IOException {
HttpEntity entity = this.httpResponse.getEntity(); HttpEntity entity = this.httpResponse.getEntity();
return entity != null ? entity.getContent() : null; return (entity != null ? entity.getContent() : StreamUtils.emptyInput());
} }
@Override @Override

3
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.apache.http.util.EntityUtils;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.util.StreamUtils;
/** /**
* {@link org.springframework.http.client.ClientHttpResponse} implementation that uses * {@link org.springframework.http.client.ClientHttpResponse} implementation that uses
@ -76,7 +77,7 @@ final class HttpComponentsClientHttpResponse extends AbstractClientHttpResponse
@Override @Override
public InputStream getBody() throws IOException { public InputStream getBody() throws IOException {
HttpEntity entity = this.httpResponse.getEntity(); HttpEntity entity = this.httpResponse.getEntity();
return (entity != null ? entity.getContent() : null); return (entity != null ? entity.getContent() : StreamUtils.emptyInput());
} }
@Override @Override

Loading…
Cancel
Save