The following code compiles nicely against Spring-5.x:
import org.apache.http.client.HttpClient;
...
private static ClientHttpRequestFactory clientHttpRequestFactory(
int timeOut) throws Exception
{
HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory =
new HttpComponentsClientHttpRequestFactory(
httpClient());
httpComponentsClientHttpRequestFactory.setConnectTimeout(timeOut * 10000);
return httpComponentsClientHttpRequestFactory;
}
private static HttpClient httpClient() throws Exception
{
SSLConnectionSocketFactory sslConnectionSocketFactory = new
SSLConnectionSocketFactory(createSSLContext());
return HttpClients.custom().setSSLSocketFactory(
sslConnectionSocketFactory).build();
}
Trying to build against Spring-6.x, however, I get an error: incompatible types: org.apache.http.client.HttpClient cannot be converted to org.apache.hc.client5.http.classic.HttpClient.
With C-code, I'd just use something like #if SPRING_VERSION > 500000 -- but this is Java... Can I import a different HttpClient -- at compile-time -- depending on the version of Spring being used?
Any other suggestions -- to keep using the same code?
pom.xmlorbuild.gradleHttpClientwith different versions of Spring framework (5 and 6). That's a given. My question is, can this same Java-code be compiled in both cases?