Hi John, Santiago,
In the MicroProfile Rest Client project, I have proposed an SPI (though really it could be an API instead) that allows components to get first access to a RestClientBuilder (MP's version of JAX-RS's ClientBuilder) before the user does. One of the main use cases was for other technologies to automatically plug in their providers as "out-of-the-box" for all users of the builder APIs.
Here is a concrete use case:
* An organization wants all outbound REST invocations to be logged into OpenTracing or some similar framework. The simplest approach would be to add a ClientRequestFilter that does the logging, adds a trace headers, etc.
* That organization may not have complete control over the code that goes into their application server (i.e. many different developers, using third-party libraries, etc.), so they may not be able to add the filter to all clients.
Given that scenario (and we ran into this already in MP), I proposed adding a notification mechanism that would allow components to be notified when new builders were created. That way, they could pre-configure the builder before the user got access to the builder (that way, the user could always undo something they didn't like if necessary). So, if an organization wanted to use OpenTracing on all REST client requests, they could add their ClientRequestFilter to the builder, and the user code would not need to do anything in order to take advantage of this feature.
It works using the ServiceLoader pattern - the OpenTracing component would have a META-INF/services/org.eclipse.microprofile.rest.client.spi.ProviderRegistrar (I'm starting to think this should be renamed to something like NewClientNotification) file that points to a class that implements an interface that looks like this:
public interface ProviderRegistrar {
void onNewBuilder(RestClientBuilder builder);
}
Then, the OpenTracing implementation of that interface could register providers, set properties, etc. When all implementations of the ProviderRegistrar interface have been invoked, then the RestClientBuilder would return to the user for them to build with.
It would be fairly simple to add to JAX-RS if we wanted to. Just let me know, and I can spin up a PR to resolve John's issue #596.
Thanks,
Andy