Package org.springframework.http.client

# Class AbstractClientHttpRequest

java.lang.Object
org.springframework.http.client.AbstractClientHttpRequest

All Implemented Interfaces:
  `ClientHttpRequest`, `HttpMessage`, `HttpOutputMessage`, `HttpRequest`

public abstract class AbstractClientHttpRequest extends Object implements ClientHttpRequest
Abstract base for `ClientHttpRequest` that makes sure that headers and body are not written multiple times.

Since:
  3.0
Author:
  Arjen Poutsma

## Constructor Summary

Constructors
Constructor
Description
`AbstractClientHttpRequest()`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`assertNotExecuted()`
Assert that this request has not been executed yet.
`final ClientHttpResponse`
`execute()`
Execute this request, resulting in a `ClientHttpResponse` that can be read.
`protected abstract ClientHttpResponse`
`executeInternal(HttpHeaders headers)`
Abstract template method that writes the given headers and content to the HTTP request.
`Map<String,Object>`
`getAttributes()`
Return a mutable map of request attributes for this request.
`final OutputStream`
`getBody()`
Return the body of the message as an output stream.
`protected abstract OutputStream`
`getBodyInternal(HttpHeaders headers)`
Abstract template method that returns the body.
`final HttpHeaders`
`getHeaders()`
Return the headers of this message.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.http.HttpRequest

`getMethod, getURI`

## Constructor Details

### AbstractClientHttpRequest

public AbstractClientHttpRequest()

## Method Details

### getHeaders

public final HttpHeaders getHeaders()
Description copied from interface: `HttpMessage`
Return the headers of this message.

Specified by:
  `getHeaders` in interface `HttpMessage`
Returns:
  a corresponding HttpHeaders object (never `null`)

### getBody

public final OutputStream getBody() throws IOException
Description copied from interface: `HttpOutputMessage`
Return the body of the message as an output stream.

Specified by:
  `getBody` in interface `HttpOutputMessage`
Returns:
  the output stream body (never `null`)
Throws:
  `IOException` - in case of I/O errors

### getAttributes

public Map<String,Object> getAttributes()
Description copied from interface: `HttpRequest`
Return a mutable map of request attributes for this request.

Specified by:
  `getAttributes` in interface `HttpRequest`

### execute

public final ClientHttpResponse execute() throws IOException
Description copied from interface: `ClientHttpRequest`
Execute this request, resulting in a `ClientHttpResponse` that can be read.

Specified by:
  `execute` in interface `ClientHttpRequest`
Returns:
  the response result of the execution
Throws:
  `IOException` - in case of I/O errors

### assertNotExecuted

protected void assertNotExecuted()
Assert that this request has not been executed yet.

Throws:
  `IllegalStateException` - if this request has been executed

### getBodyInternal

protected abstract OutputStream getBodyInternal(HttpHeaders headers) throws IOException
Abstract template method that returns the body.

Parameters:
  `headers` - the HTTP headers
Returns:
  the body output stream
Throws:
  `IOException`

### executeInternal

protected abstract ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException
Abstract template method that writes the given headers and content to the HTTP request.

Parameters:
  `headers` - the HTTP headers
Returns:
  the response object for the executed request
Throws:
  `IOException`