Top Description Fields Constructors Methods
org.springframework.web.client

pack-priv Class IntrospectingClientHttpResponse

extends ClientHttpResponseDecorator
Class Inheritance
Imports
java.io.IOException, .InputStream, .PushbackInputStream, org.springframework.http.HttpStatus, .HttpStatusCode, org.springframework.http.client.ClientHttpResponse, org.springframework.lang.Nullable

Implementation of ClientHttpResponse that can not only check if the response has a message body, but also if its length is 0 (i.e. empty) by actually reading the input stream.
Authors
Brian Clozel, Rossen Stoyanchev
Since
4.1.5
See Also
RFC 7230 Section 3.3.3

Field Summary

Modifier and TypeField and Description
private PushbackInputStream

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public InputStream
public boolean

Returns:

true if the response has a zero-length message body, false otherwise
hasEmptyMessageBody
()

Indicates whether the response has an empty message body.

public boolean

Returns:

true if the response has a message body, false otherwise
hasMessageBody
()

Indicates whether the response has a message body.

Inherited from org.springframework.web.client.ClientHttpResponseDecorator:
closegetDelegategetHeadersgetStatusCodegetStatusText

Field Detail

pushbackInputStreamback to summary
private PushbackInputStream pushbackInputStream
Annotations
@Nullable

Constructor Detail

IntrospectingClientHttpResponseback to summary
public IntrospectingClientHttpResponse(ClientHttpResponse response)

Method Detail

getBodyback to summary
public InputStream getBody() throws IOException

Overrides org.springframework.web.client.ClientHttpResponseDecorator.getBody.

Implements org.springframework.http.HttpInputMessage.getBody.

Doc from org.springframework.http.HttpInputMessage.getBody.

Return the body of the message as an input stream.

Returns:InputStream

the input stream body (never null)

Annotations
@Override
Exceptions
IOException:
in case of I/O errors
hasEmptyMessageBodyback to summary
public boolean hasEmptyMessageBody() throws IOException

Indicates whether the response has an empty message body.

Implementation tries to read the first bytes of the response stream:

  • if no bytes are available, the message body is empty
  • otherwise it is not empty and the stream is reset to its start for further reading
Returns:boolean

true if the response has a zero-length message body, false otherwise

Annotations
@SuppressWarnings:ConstantConditions
Exceptions
IOException:
in case of I/O errors
hasMessageBodyback to summary
public boolean hasMessageBody() throws IOException

Indicates whether the response has a message body.

Implementation returns false for:

  • a response status of 1XX, 204 or 304
  • a Content-Length header of 0
Returns:boolean

true if the response has a message body, false otherwise

Exceptions
IOException:
in case of I/O errors