Skip to content

Tosan HttpClient Spring Boot Starter 3.0.0 Migration Guide

Ali Alimohammadi edited this page Apr 25, 2023 · 10 revisions

This document is meant to help you migrate your application to Tosan HttpClient Spring Boot Starter 3.0.x.

Before You Start

Upgrade to the Latest 2.0.2 Version

  Before you start the upgrade, make sure to upgrade to the latest available 2.0.2 version. This will make sure that you are building against the most recent dependencies of that line.

Review System Requirements

  Tosan HttpClient Spring Boot Starter 3.0 requires Spring Boot 3.0 and Spring Cloud 2022.0.1 and Java 17 or later. It also requires Spring Framework 6.0.

Upgrade to Tosan HttpClient Spring Boot Starter 3.0

  Once you have reviewed the state of your project and its dependencies, upgrade to the latest maintenance release of Tosan HttpClient Spring Boot Starter 3.0.

Auto-configuration Files

  Spring Boot 2.7 introduced a new META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports file for registering auto-configurations.
  So you must replace spring.factories with org.springframework.boot.autoconfigure.AutoConfiguration.imports in where generate your server api sdk.

Therefore, when you use this library to build a client api, in order to enable auto-configuration related to your client, you should use the org.springframework.boot.autoconfigure.AutoConfiguration.imports file instead of the spring.factories file and fill it according to the provided release notes.

    For example, you can refer to the following file which is placed as an example in the sample project: org.springframework.boot.autoconfigure.AutoConfiguration.imports

AbstractFeignConfiguration class

  In order to build the client api in previous versions, there was an abstract class called AbstractFeignConfiguration, which had to be defined for the configuration of the required beans.
  In the new version, there are changes in some of some methods of this class as follows:

The return type of the apacheHttpClientFactory(..) method has been replaced with the ConfigurableApacheHttpClientFactory, previously this method returned the ApacheHttpClientFactory type.

public ApacheHttpClientFactory apacheHttpClientFactory(HttpClientBuilder builder,
                                                           ApacheHttpClientConnectionManagerFactory clientConnectionManagerFactory,
                                                           HttpClientProperties customServerClientConfig) {
        return new ConfigurableApacheHttpClientFactory(builder, clientConnectionManagerFactory, customServerClientConfig);
    }

    Has been replaced with:

public ConfigurableApacheHttpClientFactory apacheHttpClientFactory(HttpClientBuilder builder,
                                                           PoolingHttpClientConnectionManagerBuilder connectionManagerBuilder,
                                                           HttpClientProperties customServerClientConfig) {
        return new ConfigurableApacheHttpClientFactory(builder, connectionManagerBuilder, customServerClientConfig);
    }

The connectionManagerFactory() method has been replaced with connectionManagerBuilder() and The return type of this method is PoolingHttpClientConnectionManagerBuilder, previous method returned the ApacheHttpClientConnectionManagerFactory type.

public ApacheHttpClientConnectionManagerFactory connectionManagerFactory() {
        return new DefaultApacheHttpClientConnectionManagerFactory();
    }

    Has been replaced with:

public PoolingHttpClientConnectionManagerBuilder connectionManagerBuilder() {
        return PoolingHttpClientConnectionManagerBuilder.create();
    }

Therefore, the corresponding inputs in methods apacheHttpClientFactory(..) and httpClient(..) and clientHttpRequestFactory(..) are also changed.

AbstractHttpClientConfiguration class

  In order to produce a rest client on the restTemplate platform in previous versions, there was an abstract class called AbstractHttpClientConfiguration, which had to be defined for the configuration of the required beans.
  The changes made in AbstractFeignConfiguration class have also been made in this class.

NOTE:
  Also, for more help, you can see CustomServerFeignConfig and ExternalServiceConfiguration files that were inherited from the mentioned classes and the desired changes.