ziti-sdk-jvm icon indicating copy to clipboard operation
ziti-sdk-jvm copied to clipboard

Java SDK not using ziti socket with Apache HttpClient5 version 5.4

Open ahazeltonNF opened this issue 6 months ago • 1 comments

Using HttpClient5 version 5.3.1 works correctly. After upgrading to 5.4.2, socket connection refused errors are observed. Below is a sample that uses the ZitiHttpClientConfiguration that is part of the org.openziti:ziti-springboot-client package but created manually instead of via Spring:

      // This is using the spring boot ZitiHttpClientConfiguration manually.  Normally these would be created as spring beans
      ZitiHttpClientConfiguration zitiHttpClientConfiguration = new ZitiHttpClientConfiguration();
      ZitiConnectionSocketFactory socketFactory = zitiHttpClientConfiguration.connectionSocketFactory(zitiContext);
      ZitiSSLConnectionSocketFactory sslSocketFactory = zitiHttpClientConfiguration.sslConnectionSocketFactory(zitiContext);
      PoolingHttpClientConnectionManager poolingMgr = zitiHttpClientConfiguration.poolingConnectionManager(socketFactory, sslSocketFactory,
          ZitiHttpClientConfiguration.dnsResolver(), null, null);
      CloseableHttpClient client = zitiHttpClientConfiguration.httpClient(poolingMgr, zitiHttpClientConfiguration.connectionKeepAliveStrategy(null), null,
          null);

      HttpGet httpGet = new HttpGet(new URI(myUriString));
      client.execute(httpGet, response -> {
        log.info("Reading response");
        if (response.getCode() == 200) {
          log.info("--- {}", EntityUtils.toString(response.getEntity()));
        } else {
          log.error("Response code {} received", response.getCode());
        }
        return response;
      });
    }

ahazeltonNF avatar Apr 08 '25 13:04 ahazeltonNF