@@ -63,16 +63,19 @@ public final class HttpServiceProxyFactory {
6363
6464 private final @ Nullable StringValueResolver embeddedValueResolver ;
6565
66+ private final List <ProxyFactoryCustomizer > proxyCustomizers ;
6667
6768 private HttpServiceProxyFactory (
6869 HttpExchangeAdapter exchangeAdapter , List <HttpServiceArgumentResolver > argumentResolvers ,
6970 List <HttpRequestValues .Processor > requestValuesProcessor ,
70- @ Nullable StringValueResolver embeddedValueResolver ) {
71+ @ Nullable StringValueResolver embeddedValueResolver ,
72+ List <ProxyFactoryCustomizer > proxyCustomizers ) {
7173
7274 this .exchangeAdapter = exchangeAdapter ;
7375 this .argumentResolvers = argumentResolvers ;
7476 this .requestValuesProcessor = new CompositeHttpRequestValuesProcessor (requestValuesProcessor );
7577 this .embeddedValueResolver = embeddedValueResolver ;
78+ this .proxyCustomizers = proxyCustomizers ;
7679 }
7780
7881
@@ -84,7 +87,6 @@ private HttpServiceProxyFactory(
8487 * @return the created proxy
8588 */
8689 public <S > S createClient (Class <S > serviceType ) {
87-
8890 List <HttpServiceMethod > httpServiceMethods =
8991 MethodIntrospector .selectMethods (serviceType , this ::isExchangeMethod ).stream ()
9092 .map (method -> createHttpServiceMethod (serviceType , method ))
@@ -97,6 +99,9 @@ public <S> S createClient(Class<S> serviceType) {
9799 private <S > S getProxy (Class <S > serviceType , List <HttpServiceMethod > httpServiceMethods ) {
98100 MethodInterceptor interceptor = new HttpServiceMethodInterceptor (httpServiceMethods );
99101 ProxyFactory factory = new ProxyFactory (serviceType , interceptor );
102+ for (var customizer : this .proxyCustomizers ) {
103+ customizer .customize (factory , serviceType );
104+ }
100105 return (S ) factory .getProxy (serviceType .getClassLoader ());
101106 }
102107
@@ -147,6 +152,8 @@ public static final class Builder {
147152
148153 private @ Nullable StringValueResolver embeddedValueResolver ;
149154
155+ private final List <ProxyFactoryCustomizer > proxyCustomizers = new ArrayList <>();
156+
150157 private Builder () {
151158 }
152159
@@ -216,6 +223,19 @@ public Builder embeddedValueResolver(StringValueResolver embeddedValueResolver)
216223 return this ;
217224 }
218225
226+ /**
227+ * Register an {@link ProxyFactoryCustomizer} that can
228+ * manipulating the {@link ProxyFactory} before creating proxy.
229+ *
230+ * @param customizer the customizer to add
231+ * @return this same builder instance
232+ * @since 7.1
233+ */
234+ public Builder proxyCustomizer (ProxyFactoryCustomizer customizer ) {
235+ this .proxyCustomizers .add (customizer );
236+ return this ;
237+ }
238+
219239 /**
220240 * Build the {@link HttpServiceProxyFactory} instance.
221241 */
@@ -225,7 +245,7 @@ public HttpServiceProxyFactory build() {
225245
226246 return new HttpServiceProxyFactory (
227247 adapterToUse , initArgumentResolvers (), this .requestValuesProcessors ,
228- this .embeddedValueResolver );
248+ this .embeddedValueResolver , this . proxyCustomizers );
229249 }
230250
231251 @ SuppressWarnings ({"DataFlowIssue" , "NullAway" })
@@ -313,4 +333,18 @@ public void process(
313333 }
314334 }
315335
336+ /**
337+ * Callback interface used during HttpService proxy creation. Allows manipulating the {@link ProxyFactory} creating the
338+ * HttpService.
339+ *
340+ * @author Dung Dang Minh
341+ */
342+ public interface ProxyFactoryCustomizer {
343+ /**
344+ * Manipulates the {@link ProxyFactory}, e.g. add further interceptors to it.
345+ *
346+ * @param factory will never be {@literal null}.
347+ */
348+ void customize (ProxyFactory factory , Class <?> serviceType );
349+ }
316350}
0 commit comments