In an Apache HttpClient 4 application, an HTTPS destination does not mean every connection starts with TLS. An ordinary HTTP proxy is reached over a plain connection before CONNECT opens the tunnel and TLS is layered toward the destination.

If a custom connection manager registers only https, the first proxy hop can fail with UnsupportedSchemeException: http protocol is not supported.

For the 4.5 API, include both factories when constructing that manager:

var registry = RegistryBuilder.<ConnectionSocketFactory>create()
    .register("http", PlainConnectionSocketFactory.getSocketFactory())
    .register("https", tlsFactory)
    .build();

var manager = new PoolingHttpClientConnectionManager(registry);
var client = HttpClients.custom()
    .setConnectionManager(manager)
    .setProxy(new HttpHost("proxy.example.net", 8080, "http"))
    .build();

tlsFactory is the application’s existing SSLConnectionSocketFactory, with its intended trust and hostname verification. The types shown belong to Apache 4’s org.apache.http packages. The fragment assumes Java local-variable inference support; older Java source can use explicit types.

Attach the corrected manager to the client actually used for the request. For an allowed public HTTPS request without proxy authentication, an HTTP entry from the HTTP proxy list can fill HttpHost’s proxy address. Configuring a different builder does not update an already constructed client.

Also inspect builder ownership: HttpClientBuilder documents that an explicitly supplied connection manager can override its separate SSL configuration inputs. Put the required factories in the manager’s registry instead of assuming a later setSSLContext call will replace its internals.

This diagnosis concerns the local scheme registry. A proxy authentication challenge or a denied destination is a later, different result. Preserve both factory registrations while investigating those responses.

Artiglyn mynjee