1

Im trying to run Webflux on Tomcat and try to create Sping WebClient with Apache Http Client.

Reference Documentation stated that theres built-in support: https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-client-builder-http-components

private ClientHttpConnector getApacheHttpClient(){
    HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom();
    clientBuilder.setDefaultRequestConfig(RequestConfig.DEFAULT);
    CloseableHttpAsyncClient client = clientBuilder.build();
    ClientHttpConnector connector = new HttpComponentsClientHttpConnector(client);
    return connector;
}

But Springs HttpComponentsClientHttpConnector is not accepting org.apache.http.impl.nio.client.CloseableHttpAsyncClient. It requires org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient. So there seems to be a package rename and I can´t find a Maven Dependency that has the required class. Does anybody know the right Maven Dependency for that class. Or how could I make it work?

safarione
  • 65
  • 7

1 Answers1

1

Apache HTTP Client 5 is a separate artifact. You'll need to add the following dependencies to your pom.xml:

<dependency>
    <groupId>org.apache.httpcomponents.client5</groupId>
    <artifactId>httpclient5</artifactId>
    <version>5.1</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents.core5</groupId>
    <artifactId>httpcore5-reactive</artifactId>
    <version>5.1</version>
</dependency>
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
import org.springframework.http.client.reactive.HttpComponentsClientHttpConnector;

public class ApacheHttp {
    public static void main(String[] args) {
        new HttpComponentsClientHttpConnector(HttpAsyncClients.custom().build())
    }
}
Martin Tarjányi
  • 8,863
  • 2
  • 31
  • 49
  • unfortunatly this does not work and the required class is not present in these dependencies. The HttpComponentsClientHttpConnector requires a class from package org.apache.hc.client5.http.impl.async. This class is not present in the above packages. Can you provide a code sample? – safarione May 20 '21 at 06:30