-
Notifications
You must be signed in to change notification settings - Fork 983
HTTPCLIENT-2385: make DefaultManagedHttpClientConnection and DefaultM… #692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTPCLIENT-2385: make DefaultManagedHttpClientConnection and DefaultM… #692
Conversation
…anagedAsyncClientConnection extensible
@winfriedgerlach, IMO Rather than opening up those impl classes, you can get the same extensibility via the public HttpConnectionFactory. With a tiny factory+wrapper you can intercept all requests for logging, metrics, callbacks, etc., while keeping |
|
Hi @arturobernalg, I am already using a custom connection factory to create my "instrumented connections". But that was not the question that I wanted to answer with this PR: I wanted to make the creation of such "custom connections" easier. Take this example: if I principally appreciate the behavior of // in ManagedHttpClientConnectionFactory#createConnection:
final var connection = new DefaultManagedHttpClientConnection(id) {
@Override
public void close() throws IOException {
var certificate = (X509Certificate) getSSLSession().getPeerCertificates()[0];
var dn = certificate.getSubjectX500Principal().getName();
LOG.info("Closing connection {} with DN: {}", id, dn);
super.close();
}
};(just as an example, don't worry about missing checks etc.) What would be your alternative solution to this approach? |
@winfriedgerlach I do not have a problem with making I am substantially less thrilled about the possibility of opening up anything logging related. |
@winfriedgerlach What is the reason those classes should be made public? |
@winfriedgerlach Use the |
@winfriedgerlach, to build on that IMO, exposing logging internals like |
OK @ok2c , I have reverted this change. I guess just having |
@winfriedgerlach Can you also live with those classes being internal (annotated |
@ok2c I don't have an opinion on that one. |
@winfriedgerlach Let me re-phrase. If you add the annotation I will approve the PR. |
|
@ok2c your wish is my command :-) |
Cf. https://issues.apache.org/jira/browse/HTTPCLIENT-2385:
I'd like to improve extensibility of
DefaultManagedHttpClientConnectionandDefaultManagedAsyncClientConnection. My request somehow resembles the very old issue HTTPCLIENT-1374, in whichDefaultManagedHttpClientConnectionwas initially made public.IMHO, implementations named
Default...should both demonstrate best practices of API usage and act as easily modifiable blueprints for HttpClient users. This is currently not the case, because bothDefaultManagedHttpClientConnectionandDefaultManagedAsyncClientConnectionare final andDefaultManagedHttpClientConnectionuses package-private classes (Logging...).So if you want to write your own, slightly modified
MyManagedHttpClientConnection(e.g., change some logging or call a callback when a method is invoked), you will need to extend the super classDefaultBHttpClientConnection(which is public non-final), copy a lot of code fromDefaultManagedHttpClientConnectionand possibly even create your own copies ofLoggingInputStream,LoggingOutputStream, andLoggingSocketHolder. Something that could be done with very few lines of code, maybe even in an anonymous class, has then become multiple classes with several hundred LoC to review and maintain (especially ifDefaultBHttpClientConnectionorDefaultManagedHttpClientConnectionare changed in future versions of HttpClient).I suggest to
DefaultManagedHttpClientConnectionandDefaultManagedAsyncClientConnectionpublic non-finalLoggingInputStream,LoggingOutputStream, andLoggingSocketHolderpublicThis shouldn't hurt anyone (doesn't break APIs) and help some users like our project.