org.springframework.http.client
Class AbstractClientHttpRequest

java.lang.Object
  extended by org.springframework.http.client.AbstractClientHttpRequest
All Implemented Interfaces:
ClientHttpRequest, HttpMessage, HttpOutputMessage
Direct Known Subclasses:
CommonsClientHttpRequest, SimpleClientHttpRequest

public abstract class AbstractClientHttpRequest
extends java.lang.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

Field Summary
private  java.io.ByteArrayOutputStream bufferedOutput
           
private  boolean executed
           
private  HttpHeaders headers
           
 
Constructor Summary
AbstractClientHttpRequest()
           
 
Method Summary
private  void checkExecuted()
           
 ClientHttpResponse execute()
          Execute this request, resulting in a ClientHttpResponse that can be read.
protected abstract  ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput)
          Abstract template method that writes the given headers and content to the HTTP request.
 java.io.OutputStream getBody()
          Return the body of the message as an output stream.
 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.client.ClientHttpRequest
getMethod, getURI
 

Field Detail

executed

private boolean executed

headers

private final HttpHeaders headers

bufferedOutput

private final java.io.ByteArrayOutputStream bufferedOutput
Constructor Detail

AbstractClientHttpRequest

public AbstractClientHttpRequest()
Method Detail

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

getBody

public final java.io.OutputStream getBody()
                                   throws java.io.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
Throws:
java.io.IOException - in case of I/O Errors

execute

public final ClientHttpResponse execute()
                                 throws java.io.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:
java.io.IOException - in case of I/O errors

checkExecuted

private void checkExecuted()

executeInternal

protected abstract ClientHttpResponse executeInternal(HttpHeaders headers,
                                                      byte[] bufferedOutput)
                                               throws java.io.IOException
Abstract template method that writes the given headers and content to the HTTP request.

Parameters:
headers - the HTTP headers
bufferedOutput - the body content
Returns:
the response object for the executed request
Throws:
java.io.IOException