Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.http
Class HttpEntity<T>

    java.lang.Object
      org.springframework.http.HttpEntity<T>

Direct Known Subclasses:
  ResponseEntity

    public class HttpEntity<T>

extends java.lang.Object

Represents an HTTP request or response entity, consisting of headers and body.

Typically used in combination with the `RestTemplate`, like so:

     HttpHeaders headers = new HttpHeaders();
     headers.setContentType(MediaType.TEXT_PLAIN);
     HttpEntity<String> entity = new HttpEntity<String>(helloWorld, headers);
     URI location = template.postForLocation("http://example.com", entity);

or

     HttpEntity<String> entity = template.getForEntity("http://example.com", String.class);
     String body = entity.getBody();
     MediaType contentType = entity.getHeaders().getContentType();

Can also be used in Spring MVC, as a return value from a @Controller method:

     @RequestMapping("/handle")
     public HttpEntity<String> handle() {
       HttpHeaders responseHeaders = new HttpHeaders();
       responseHeaders.set("MyResponseHeader", "MyValue");
       return new HttpEntity<String>("Hello World", responseHeaders);
     }

Since:
  3.0.2
Author:
  Arjen Poutsma
See Also:
  `RestTemplate`, `getBody()`, `getHeaders()`

Field Summary
`static HttpEntity` | `EMPTY` The empty `HttpEntity`, with no body or headers.

Constructor Summary
`protected` | `HttpEntity()` Create a new, empty `HttpEntity`.
`` | `HttpEntity(MultiValueMap<java.lang.String,java.lang.String> headers)` Create a new `HttpEntity` with the given headers and no body.
`` | `HttpEntity(T body)` Create a new `HttpEntity` with the given body and no headers.
`` | `HttpEntity(T body, MultiValueMap<java.lang.String,java.lang.String> headers)` Create a new `HttpEntity` with the given body and headers.

Method Summary
`T` | `getBody()` Returns the body of this entity.
`HttpHeaders` | `getHeaders()` Returns the headers of this entity.
`boolean` | `hasBody()` Indicates whether this entity has a body.
`java.lang.String` | `toString()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### EMPTY

    public static final HttpEntity EMPTY

  The empty `HttpEntity`, with no body or headers.

Constructor Detail

### HttpEntity

    protected HttpEntity()

  Create a new, empty `HttpEntity`.

### HttpEntity

    public HttpEntity(T body)

  Create a new `HttpEntity` with the given body and no headers.

  Parameters:
    `body` - the entity body

### HttpEntity

    public HttpEntity(MultiValueMap<java.lang.String,java.lang.String> headers)

  Create a new `HttpEntity` with the given headers and no body.

  Parameters:
    `headers` - the entity headers

### HttpEntity

    public HttpEntity(T body,
                      MultiValueMap<java.lang.String,java.lang.String> headers)

  Create a new `HttpEntity` with the given body and headers.

  Parameters:
    `body` - the entity body
    `headers` - the entity headers

Method Detail

### getHeaders

    public HttpHeaders getHeaders()

  Returns the headers of this entity.

### getBody

    public T getBody()

  Returns the body of this entity.

### hasBody

    public boolean hasBody()

  Indicates whether this entity has a body.

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD