Skip to content

Conversation

@dungdm93
Copy link

@dungdm93 dungdm93 commented Jan 29, 2026

The Spring Data project provides support for RepositoryProxyPostProcessor, which allows customization of the underlying ProxyFactory (e.g, registering additional interceptors) prior to proxy bean creation.

In contrast, HttpServiceProxyFactory, which is responsible for creating client proxies from HTTP service interfaces annotated with @HttpExchange, currently does not offer a straightforward extension point for registering interceptors (e.g., for tracing or cross-cutting concerns).

Example usage of HttpServiceProxyFactory.ProxyFactoryCustomizer:

public class OpenTelemetryHttpServiceProxyFactoryCustomizer implements HttpServiceProxyFactory.ProxyFactoryCustomizer {
    private final SingletonSupplier<OpenTelemetry> openTelemetry;
    private final HttpServiceGroup group;

    public OpenTelemetryHttpServiceProxyFactoryCustomizer(SingletonSupplier<OpenTelemetry> openTelemetry, HttpServiceGroup group) {
        this.openTelemetry = openTelemetry;
        this.group = group;
    }

    @Override
    public void customize(ProxyFactory factory, Class<?> serviceType) {
        var interceptor = new OpenTelemetryMethodInterceptor(openTelemetry.obtain(), group);
        factory.addAdvice(0, interceptor);
    }
}

@Component
public class OpenTelemetryRestClientHttpServiceGroupConfigurer implements RestClientHttpServiceGroupConfigurer {
    private final SingletonSupplier<OpenTelemetry> openTelemetry;

    public OpenTelemetryRestClientHttpServiceGroupConfigurer(SingletonSupplier<OpenTelemetry> openTelemetry) {
        this.openTelemetry = openTelemetry;
    }

    @Override
    public void configureGroups(Groups<RestClient.Builder> groups) {
        groups.forEachProxyFactory(this::configureProxyFactory);
    }

    private void configureProxyFactory(HttpServiceGroup group, HttpServiceProxyFactory.Builder builder) {
        var customizer = new OpenTelemetryHttpServiceProxyFactoryCustomizer(openTelemetry, group);
        builder.proxyCustomizer(customizer);
    }
}

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 29, 2026
@dungdm93 dungdm93 force-pushed the http-service-proxy.post-processor branch from 456e119 to c5ec8a0 Compare January 29, 2026 05:00
@rstoyanchev rstoyanchev self-assigned this Jan 29, 2026
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 29, 2026
@rstoyanchev rstoyanchev added this to the 7.0.4 milestone Jan 29, 2026
@rstoyanchev rstoyanchev changed the title Allow HttpServiceProxyFactory customize ProxyFactory prior to proxy bean creation Allow customization of the ProxyFactory in HttpServiceProxyFactory to create HTTP service proxies Jan 29, 2026
@rstoyanchev rstoyanchev changed the title Allow customization of the ProxyFactory in HttpServiceProxyFactory to create HTTP service proxies Allow customization of the ProxyFactory in HttpServiceProxyFactory used to create HTTP service proxies Jan 29, 2026
Copy link
Contributor

@rstoyanchev rstoyanchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. The request makes sense, however I would update the implementation a bit as suggested below. Having at least one test would also be a good idea.

Please, let me know if you will make those updates.

@dungdm93 dungdm93 force-pushed the http-service-proxy.post-processor branch from c5ec8a0 to 00bec12 Compare January 30, 2026 02:19
@dungdm93 dungdm93 requested a review from rstoyanchev January 30, 2026 02:53
…actory` before creating the proxy

Signed-off-by: Đặng Minh Dũng <[email protected]>
@dungdm93 dungdm93 force-pushed the http-service-proxy.post-processor branch from 00bec12 to b2d9da4 Compare January 30, 2026 15:04
@dungdm93
Copy link
Author

@rstoyanchev I update PR as your suggestion, could you please take a look.

Copy link
Contributor

@rstoyanchev rstoyanchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dungdm93.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants