OkHttpClient is final
See original GitHub issueWhat is the point of OkHttpClient
be a final class?
Some frameworks, like spring, make intense use of proxies for almost everything.
I had a use case where I use to build the feign clients manually and now I’m trying to use spring-cloud-opentracing to do some distributed tracing.
One problem I’m facing is, on that package there’s a Aspect in order to decorate the client the their TracingClient
, but the problem is: the aspect tries to make a proxy of the client implementation but the OkHttpClient is final.
tl;dr What is the possibility of making the OkHttpClient not final?
edit: The spring cloud opentracing feign can be found here: https://github.com/opentracing-contrib/java-spring-cloud/blob/master/instrument-starters/opentracing-spring-cloud-feign-starter/src/main/java/io/opentracing/contrib/spring/cloud/feign/FeignTracingAutoConfiguration.java#L80
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Based on my understanding of the history of this project and it’s modules, the
Client
interface is meant to be “open for extension, closed for modification” following the Open-Closed Principle. Both theApacheHttpClient
and theOkHttpClient
arefinal
in order to adhere to this.With regards to
OpenTracing
, there is anOpenTracing
implementation forFeign
available that appears to indicate that you can use the providedOkHttpClient
withOpenTracing
https://github.com/OpenFeign/feign-opentracing
In your particular case, you want to use Spring’s Open Tracing support for Spring Boot, which as you’ve pointed out, uses an
Aspect
to instrument a Feign client that is not using aTracingClient
explicitly. Since you have mentioned that you are manually configuringFeign
, if you use aTracingClient
explicitly, theAspect
is not necessary.Looking at both
feign-opentracing
and the Spring project, if you want to use a providedClient
, you must useTracingClient
directly.Now, with that said, I don’t see an issue with changing the current
Client
implementations away fromfinal
. Let’s ask the other contributors what they think.@velo, @spencergibb, @adriancole Thoughts?
Couldn’t do as you suggested.
I created a springboot autoconfiguration which creates a bean for TracingClient decorated with OkHttpClient. I think it’s probably for the best to keep OkHttpClient as final.