mdzh
mdzh

Reputation: 1050

Set custom socket implementation in HttpUrlConnection

Looking for java networking experts here :)

The team that I'm part of is developing a solution which consists of server part and a small client API (and api-impl) bundle that our customers must deploy and use in order to make http requests to the server part.

One of our customers who uses the API is asking us to provide him with a new method for setting a custom Socket implementation, so that the actual http communication with the server part can go through his Socket. Until now, we used HttpsUrlConnection to connect to the server part. The question is - is it possible to somehow supply the HttpsUrlConnection with a custom socket implementation instead of the default one? What are the alternatives? Is Apache HttpClient able to do this?

Upvotes: 6

Views: 4921

Answers (2)

ok2c
ok2c

Reputation: 27518

One can fully customize the way Apache HttpClient instantiates sockets and connects them to a remote endpoint by using ConnectionSocketFactory. This example for instance demonstrates how connect to an external host via a SOCKS proxy

Upvotes: 0

Brett Okken
Brett Okken

Reputation: 6306

It is possible to set an SSLSocketFactory on an HttpsUrlConnection. This is only possible with ssl and not with the "plain" HttpUrlConnection.

Upvotes: 8

Related Questions