Package org.springframework.http.client.support

# Class HttpAccessor

java.lang.Object
org.springframework.http.client.support.HttpAccessor

Direct Known Subclasses:
  `InterceptingHttpAccessor`

public abstract class HttpAccessor extends Object
Base class for `RestTemplate` and other HTTP accessing gateway helpers, defining common properties such as the `ClientHttpRequestFactory` to operate on.

Not intended to be used directly.

See `RestTemplate` for an entry point.

Since:
  3.0
Author:
  Arjen Poutsma, Juergen Hoeller, Phillip Webb
See Also:
  - `ClientHttpRequestFactory`
  - `RestTemplate`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final org.apache.commons.logging.Log`
`logger`
Logger available to subclasses.

## Constructor Summary

Constructors
Constructor
Description
`HttpAccessor()`

## Method Summary

Modifier and Type
Method
Description
`protected ClientHttpRequest`
`createRequest(URI url, HttpMethod method)`
Create a new `ClientHttpRequest` via this template's `ClientHttpRequestFactory`.
`List<ClientHttpRequestInitializer>`
`getClientHttpRequestInitializers()`
Get the request initializers that this accessor uses.
`ClientHttpRequestFactory`
`getRequestFactory()`
Return the request factory that this accessor uses for obtaining client request handles.
`void`
`setClientHttpRequestInitializers(List<ClientHttpRequestInitializer> clientHttpRequestInitializers)`
Set the request initializers that this accessor should use.
`void`
`setRequestFactory(ClientHttpRequestFactory requestFactory)`
Set the request factory that this accessor uses for obtaining client request handles.

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

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

## Field Details

### logger

protected final org.apache.commons.logging.Log logger
Logger available to subclasses.

## Constructor Details

### HttpAccessor

public HttpAccessor()

## Method Details

### setRequestFactory

public void setRequestFactory(ClientHttpRequestFactory requestFactory)
Set the request factory that this accessor uses for obtaining client request handles.

The default is a `SimpleClientHttpRequestFactory` based on the JDK's own HTTP libraries (`HttpURLConnection`).

Note that the standard JDK HTTP library does not support the HTTP PATCH method. Configure the Apache HttpComponents or OkHttp request factory to enable PATCH.

See Also:
  - `createRequest(URI, HttpMethod)`
  - `SimpleClientHttpRequestFactory`
  - `HttpComponentsClientHttpRequestFactory`
  - `JdkClientHttpRequestFactory`

### getRequestFactory

public ClientHttpRequestFactory getRequestFactory()
Return the request factory that this accessor uses for obtaining client request handles.

### setClientHttpRequestInitializers

public void setClientHttpRequestInitializers(List<ClientHttpRequestInitializer> clientHttpRequestInitializers)
Set the request initializers that this accessor should use.

The initializers will get immediately sorted according to their order.

Since:
  5.2

### getClientHttpRequestInitializers

public List<ClientHttpRequestInitializer> getClientHttpRequestInitializers()
Get the request initializers that this accessor uses.

The returned `List` is active and may be modified. Note, however, that the initializers will not be resorted according to their order before the `ClientHttpRequest` is initialized.

Since:
  5.2
See Also:
  - `setClientHttpRequestInitializers(List)`

### createRequest

protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException
Create a new `ClientHttpRequest` via this template's `ClientHttpRequestFactory`.

Parameters:
  `url` - the URL to connect to
  `method` - the HTTP method to execute (GET, POST, etc)
Returns:
  the created request
Throws:
  `IOException` - in case of I/O errors
See Also:
  - `getRequestFactory()`
  - `ClientHttpRequestFactory.createRequest(URI, HttpMethod)`