Skip to content

Commit

Permalink
Revert "Use ObjectProvider for DeferringLoadBalancerExchangeFilterFun…
Browse files Browse the repository at this point in the history
…ction."

This reverts commit 8fdd79f.

# Conflicts:
#	spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/LoadBalancerWebClientBuilderBeanPostProcessor.java
  • Loading branch information
OlgaMaciaszek committed Jul 31, 2024
1 parent 20d6372 commit c1b08f8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 88 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,7 +55,7 @@ void tryResolveDelegate() {
if (delegate == null) {
delegate = exchangeFilterFunctionProvider.getIfAvailable();
if (delegate == null) {
throw new IllegalStateException("LoadBalancerExchangeFilterFunction not available.");
throw new IllegalStateException("ReactorLoadBalancerExchangeFilterFunction not available.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.web.reactive.function.client.WebClient;

Expand All @@ -47,10 +48,9 @@
@Conditional(LoadBalancerBeanPostProcessorAutoConfiguration.OnAnyLoadBalancerImplementationPresentCondition.class)
public class LoadBalancerBeanPostProcessorAutoConfiguration {

@SuppressWarnings("rawtypes")
@Bean
public static LoadBalancerWebClientBuilderBeanPostProcessor loadBalancerWebClientBuilderBeanPostProcessor(
ObjectProvider<DeferringLoadBalancerExchangeFilterFunction> deferringExchangeFilterFunction,
@Lazy DeferringLoadBalancerExchangeFilterFunction deferringExchangeFilterFunction,
ApplicationContext context) {
return new LoadBalancerWebClientBuilderBeanPostProcessor(deferringExchangeFilterFunction, context);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,10 +17,8 @@
package org.springframework.cloud.client.loadbalancer.reactive;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.SimpleObjectProvider;
import org.springframework.context.ApplicationContext;
import org.springframework.web.reactive.function.client.WebClient;

Expand All @@ -32,28 +30,15 @@
* @author Olga Maciaszek-Sharma
* @since 2.2.0
*/
@SuppressWarnings({ "removal", "rawtypes" })
public class LoadBalancerWebClientBuilderBeanPostProcessor implements BeanPostProcessor {

private final ObjectProvider<DeferringLoadBalancerExchangeFilterFunction> exchangeFilterFunctionObjectProvider;
private final DeferringLoadBalancerExchangeFilterFunction exchangeFilterFunction;

private final ApplicationContext context;

/**
* @deprecated in favour of
* {@link LoadBalancerWebClientBuilderBeanPostProcessor#LoadBalancerWebClientBuilderBeanPostProcessor(ObjectProvider, ApplicationContext)}
*/
@Deprecated(forRemoval = true)
public LoadBalancerWebClientBuilderBeanPostProcessor(
DeferringLoadBalancerExchangeFilterFunction exchangeFilterFunction, ApplicationContext context) {
this.exchangeFilterFunctionObjectProvider = new SimpleObjectProvider<>(exchangeFilterFunction);
this.context = context;
}

public LoadBalancerWebClientBuilderBeanPostProcessor(
ObjectProvider<DeferringLoadBalancerExchangeFilterFunction> exchangeFilterFunction,
ApplicationContext context) {
this.exchangeFilterFunctionObjectProvider = exchangeFilterFunction;
this.exchangeFilterFunction = exchangeFilterFunction;
this.context = context;
}

Expand All @@ -63,12 +48,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
if (context.findAnnotationOnBean(beanName, LoadBalanced.class) == null) {
return bean;
}
DeferringLoadBalancerExchangeFilterFunction exchangeFilterFunction = exchangeFilterFunctionObjectProvider
.getIfAvailable();
if (exchangeFilterFunction == null) {
throw new IllegalStateException("LoadBalancerExchangeFilterFunction not found");
}
((WebClient.Builder) bean).filter(exchangeFilterFunctionObjectProvider.getIfAvailable());
((WebClient.Builder) bean).filter(exchangeFilterFunction);
}
return bean;
}
Expand Down

0 comments on commit c1b08f8

Please sign in to comment.