Skip to content
A fork of the spring ClientHttpRequestFactory api and implementations without dependency on the remainder of the spring framework
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Fahrschein HTTP API and Implementation

Build Status Release Maven Central

A fork of the spring ClientHttpRequestFactory api and implementations without dependency on the remainder of the spring framework. The main usecase is for the fahrschein nakadi client.

Changes compared to the spring implementation

  • The ClientHttpResponse#close methods do not try to consume remaining data from the stream, instead the connection is aborted (see SPR-14040 and SPR-14882).


Sending a request body serialized with Jackson and deserializing the response

    final URI uri = URI.create(...);
    final ObjectMapper objectMapper = new ObjectMapper();

    // RequestData and ResponseData can be arbitrary java objects which can be serialized and deserialized by jackson
    final RequestData requestData = ...

    final SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
    requestFactoryDelegate.setReadTimeout(60 * 1000);

    final ClientHttpRequest request = clientHttpRequestFactory.createRequest(uri, HttpMethod.POST);


    try (final OutputStream os = request.getBody()) {
        objectMapper.writeValue(os, requestData);

    try (final ClientHttpResponse response = request.execute()) {
        try (final InputStream is = response.getBody()) {
            final ResponseData responseData = objectMapper.readValue(is, ResponseData.class);

Using the Apache HttpComponents implementation

final RequestConfig config = RequestConfig.custom().setSocketTimeout(readTimeout)

final CloseableHttpClient httpClient = HttpClients.custom()
                                                  .setConnectionTimeToLive(readTimeout, TimeUnit.MILLISECONDS)

final ClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);

Getting help

If you have questions, concerns, bug reports, etc, please file an issue in this repository's issue tracker.

Getting involved

To contribute, simply make a pull request and add a brief description (1-2 sentences) of your addition or change.

You can’t perform that action at this time.