mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Polish alibaba/spring-cloud-alibaba#1758 : [CodeBase] Sync the source code from greenwich to finichley
This commit is contained in:
parent
201a4eaa01
commit
8cbd14b2bb
@ -67,14 +67,12 @@ import static com.alibaba.nacos.api.PropertyKeyConst.USERNAME;
|
||||
@ConfigurationProperties("spring.cloud.nacos.discovery")
|
||||
public class NacosDiscoveryProperties {
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(NacosDiscoveryProperties.class);
|
||||
|
||||
/**
|
||||
* Prefix of {@link NacosDiscoveryProperties}.
|
||||
*/
|
||||
public static final String PREFIX = "spring.cloud.nacos.discovery";
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(NacosDiscoveryProperties.class);
|
||||
private static final Pattern PATTERN = Pattern.compile("-(\\w)");
|
||||
|
||||
/**
|
||||
|
@ -42,21 +42,37 @@ public class NacosServiceInstance implements ServiceInstance {
|
||||
return serviceId;
|
||||
}
|
||||
|
||||
public void setServiceId(String serviceId) {
|
||||
this.serviceId = serviceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecure() {
|
||||
return secure;
|
||||
}
|
||||
|
||||
public void setSecure(boolean secure) {
|
||||
this.secure = secure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getUri() {
|
||||
return DefaultServiceInstance.getUri(this);
|
||||
@ -67,22 +83,6 @@ public class NacosServiceInstance implements ServiceInstance {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setServiceId(String serviceId) {
|
||||
this.serviceId = serviceId;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void setSecure(boolean secure) {
|
||||
this.secure = secure;
|
||||
}
|
||||
|
||||
public void setMetadata(Map<String, String> metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
@ -32,13 +32,11 @@ import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
*/
|
||||
public class NacosDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(NacosDiscoveryClient.class);
|
||||
|
||||
/**
|
||||
* Nacos Discovery Client Description.
|
||||
*/
|
||||
public static final String DESCRIPTION = "Spring Cloud Nacos Discovery Client";
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(NacosDiscoveryClient.class);
|
||||
private NacosServiceDiscovery serviceDiscovery;
|
||||
|
||||
public NacosDiscoveryClient(NacosServiceDiscovery nacosServiceDiscovery) {
|
||||
|
@ -57,8 +57,8 @@ public class NacosDiscoveryClientConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.watch.enabled", matchIfMissing = true)
|
||||
public NacosWatch nacosWatch(NacosServiceManager nacosServiceManager,
|
||||
NacosDiscoveryProperties nacosDiscoveryProperties,
|
||||
ObjectProvider<TaskScheduler> taskExecutorObjectProvider) {
|
||||
NacosDiscoveryProperties nacosDiscoveryProperties,
|
||||
ObjectProvider<TaskScheduler> taskExecutorObjectProvider) {
|
||||
return new NacosWatch(nacosServiceManager, nacosDiscoveryProperties,
|
||||
taskExecutorObjectProvider);
|
||||
}
|
||||
|
@ -46,33 +46,8 @@ public class NacosServiceDiscovery {
|
||||
this.nacosServiceManager = nacosServiceManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all instances for the given service.
|
||||
* @param serviceId id of service
|
||||
* @return list of instances
|
||||
* @throws NacosException nacosException
|
||||
*/
|
||||
public List<ServiceInstance> getInstances(String serviceId) throws NacosException {
|
||||
String group = discoveryProperties.getGroup();
|
||||
List<Instance> instances = namingService().selectInstances(serviceId, group,
|
||||
true);
|
||||
return hostToServiceInstanceList(instances, serviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the names of all services.
|
||||
* @return list of service names
|
||||
* @throws NacosException nacosException
|
||||
*/
|
||||
public List<String> getServices() throws NacosException {
|
||||
String group = discoveryProperties.getGroup();
|
||||
ListView<String> services = namingService().getServicesOfServer(1,
|
||||
Integer.MAX_VALUE, group);
|
||||
return services.getData();
|
||||
}
|
||||
|
||||
public static List<ServiceInstance> hostToServiceInstanceList(
|
||||
List<Instance> instances, String serviceId) {
|
||||
List<Instance> instances, String serviceId) {
|
||||
List<ServiceInstance> result = new ArrayList<>(instances.size());
|
||||
for (Instance instance : instances) {
|
||||
ServiceInstance serviceInstance = hostToServiceInstance(instance, serviceId);
|
||||
@ -84,7 +59,7 @@ public class NacosServiceDiscovery {
|
||||
}
|
||||
|
||||
public static ServiceInstance hostToServiceInstance(Instance instance,
|
||||
String serviceId) {
|
||||
String serviceId) {
|
||||
if (instance == null || !instance.isEnabled() || !instance.isHealthy()) {
|
||||
return null;
|
||||
}
|
||||
@ -111,6 +86,31 @@ public class NacosServiceDiscovery {
|
||||
return nacosServiceInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all instances for the given service.
|
||||
* @param serviceId id of service
|
||||
* @return list of instances
|
||||
* @throws NacosException nacosException
|
||||
*/
|
||||
public List<ServiceInstance> getInstances(String serviceId) throws NacosException {
|
||||
String group = discoveryProperties.getGroup();
|
||||
List<Instance> instances = namingService().selectInstances(serviceId, group,
|
||||
true);
|
||||
return hostToServiceInstanceList(instances, serviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the names of all services.
|
||||
* @return list of service names
|
||||
* @throws NacosException nacosException
|
||||
*/
|
||||
public List<String> getServices() throws NacosException {
|
||||
String group = discoveryProperties.getGroup();
|
||||
ListView<String> services = namingService().getServicesOfServer(1,
|
||||
Integer.MAX_VALUE, group);
|
||||
return services.getData();
|
||||
}
|
||||
|
||||
private NamingService namingService() {
|
||||
return nacosServiceManager
|
||||
.getNamingService(discoveryProperties.getNacosProperties());
|
||||
|
@ -51,26 +51,18 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycle {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(NacosWatch.class);
|
||||
|
||||
private Map<String, EventListener> listenerMap = new ConcurrentHashMap<>(16);
|
||||
|
||||
private final AtomicBoolean running = new AtomicBoolean(false);
|
||||
|
||||
private final AtomicLong nacosWatchIndex = new AtomicLong(0);
|
||||
|
||||
private final NacosDiscoveryProperties properties;
|
||||
private final TaskScheduler taskScheduler;
|
||||
private Map<String, EventListener> listenerMap = new ConcurrentHashMap<>(16);
|
||||
private ApplicationEventPublisher publisher;
|
||||
|
||||
private ScheduledFuture<?> watchFuture;
|
||||
|
||||
private NacosServiceManager nacosServiceManager;
|
||||
|
||||
private final NacosDiscoveryProperties properties;
|
||||
|
||||
private final TaskScheduler taskScheduler;
|
||||
|
||||
public NacosWatch(NacosServiceManager nacosServiceManager,
|
||||
NacosDiscoveryProperties properties,
|
||||
ObjectProvider<TaskScheduler> taskScheduler) {
|
||||
NacosDiscoveryProperties properties,
|
||||
ObjectProvider<TaskScheduler> taskScheduler) {
|
||||
this.nacosServiceManager = nacosServiceManager;
|
||||
this.properties = properties;
|
||||
this.taskScheduler = taskScheduler.getIfAvailable(NacosWatch::getTaskScheduler);
|
||||
|
@ -47,7 +47,7 @@ public class NacosDiscoveryEndpoint {
|
||||
private NacosDiscoveryProperties nacosDiscoveryProperties;
|
||||
|
||||
public NacosDiscoveryEndpoint(NacosServiceManager nacosServiceManager,
|
||||
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||
this.nacosServiceManager = nacosServiceManager;
|
||||
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ public class NacosAutoServiceRegistration
|
||||
private NacosRegistration registration;
|
||||
|
||||
public NacosAutoServiceRegistration(ServiceRegistry<Registration> serviceRegistry,
|
||||
AutoServiceRegistrationProperties autoServiceRegistrationProperties,
|
||||
NacosRegistration registration) {
|
||||
AutoServiceRegistrationProperties autoServiceRegistrationProperties,
|
||||
NacosRegistration registration) {
|
||||
super(serviceRegistry, autoServiceRegistrationProperties);
|
||||
this.registration = registration;
|
||||
}
|
||||
|
@ -72,6 +72,16 @@ public class NacosRegistration implements Registration, ServiceInstance {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
private static void customize(
|
||||
List<NacosRegistrationCustomizer> registrationCustomizers,
|
||||
NacosRegistration registration) {
|
||||
if (registrationCustomizers != null) {
|
||||
for (NacosRegistrationCustomizer customizer : registrationCustomizers) {
|
||||
customizer.customize(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
@ -112,16 +122,6 @@ public class NacosRegistration implements Registration, ServiceInstance {
|
||||
customize(registrationCustomizers, this);
|
||||
}
|
||||
|
||||
private static void customize(
|
||||
List<NacosRegistrationCustomizer> registrationCustomizers,
|
||||
NacosRegistration registration) {
|
||||
if (registrationCustomizers != null) {
|
||||
for (NacosRegistrationCustomizer customizer : registrationCustomizers) {
|
||||
customizer.customize(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServiceId() {
|
||||
return nacosDiscoveryProperties.getService();
|
||||
|
@ -42,7 +42,7 @@ public class NacosRibbonClientConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ServerList<?> ribbonServerList(IClientConfig config,
|
||||
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||
if (this.propertiesFactory.isSet(ServerList.class, config.getClientName())) {
|
||||
ServerList serverList = this.propertiesFactory.get(ServerList.class, config,
|
||||
config.getClientName());
|
||||
|
@ -122,7 +122,7 @@ public class MockNamingService implements NamingService {
|
||||
|
||||
@Override
|
||||
public List<Instance> getAllInstances(String serviceName, String groupName,
|
||||
boolean subscribe) throws NacosException {
|
||||
boolean subscribe) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -134,19 +134,19 @@ public class MockNamingService implements NamingService {
|
||||
|
||||
@Override
|
||||
public List<Instance> getAllInstances(String serviceName, String groupName,
|
||||
List<String> clusters) throws NacosException {
|
||||
List<String> clusters) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Instance> getAllInstances(String serviceName, List<String> clusters,
|
||||
boolean subscribe) throws NacosException {
|
||||
boolean subscribe) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Instance> getAllInstances(String serviceName, String groupName,
|
||||
List<String> clusters, boolean subscribe) throws NacosException {
|
||||
List<String> clusters, boolean subscribe) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -158,43 +158,43 @@ public class MockNamingService implements NamingService {
|
||||
|
||||
@Override
|
||||
public List<Instance> selectInstances(String serviceName, String groupName,
|
||||
boolean healthy) throws NacosException {
|
||||
boolean healthy) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Instance> selectInstances(String serviceName, boolean healthy,
|
||||
boolean subscribe) throws NacosException {
|
||||
boolean subscribe) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Instance> selectInstances(String serviceName, String groupName,
|
||||
boolean healthy, boolean subscribe) throws NacosException {
|
||||
boolean healthy, boolean subscribe) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Instance> selectInstances(String serviceName, List<String> clusters,
|
||||
boolean healthy) throws NacosException {
|
||||
boolean healthy) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Instance> selectInstances(String serviceName, String groupName,
|
||||
List<String> clusters, boolean healthy) throws NacosException {
|
||||
List<String> clusters, boolean healthy) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Instance> selectInstances(String serviceName, List<String> clusters,
|
||||
boolean healthy, boolean subscribe) throws NacosException {
|
||||
boolean healthy, boolean subscribe) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Instance> selectInstances(String serviceName, String groupName,
|
||||
List<String> clusters, boolean healthy, boolean subscribe)
|
||||
List<String> clusters, boolean healthy, boolean subscribe)
|
||||
throws NacosException {
|
||||
return null;
|
||||
}
|
||||
@ -218,7 +218,7 @@ public class MockNamingService implements NamingService {
|
||||
|
||||
@Override
|
||||
public Instance selectOneHealthyInstance(String serviceName, String groupName,
|
||||
boolean subscribe) throws NacosException {
|
||||
boolean subscribe) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -230,19 +230,19 @@ public class MockNamingService implements NamingService {
|
||||
|
||||
@Override
|
||||
public Instance selectOneHealthyInstance(String serviceName, String groupName,
|
||||
List<String> clusters) throws NacosException {
|
||||
List<String> clusters) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instance selectOneHealthyInstance(String serviceName, List<String> clusters,
|
||||
boolean subscribe) throws NacosException {
|
||||
boolean subscribe) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instance selectOneHealthyInstance(String serviceName, String groupName,
|
||||
List<String> clusters, boolean subscribe) throws NacosException {
|
||||
List<String> clusters, boolean subscribe) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -302,19 +302,19 @@ public class MockNamingService implements NamingService {
|
||||
|
||||
@Override
|
||||
public ListView<String> getServicesOfServer(int pageNo, int pageSize,
|
||||
String groupName) throws NacosException {
|
||||
String groupName) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListView<String> getServicesOfServer(int pageNo, int pageSize,
|
||||
AbstractSelector selector) throws NacosException {
|
||||
AbstractSelector selector) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListView<String> getServicesOfServer(int pageNo, int pageSize,
|
||||
String groupName, AbstractSelector selector) throws NacosException {
|
||||
String groupName, AbstractSelector selector) throws NacosException {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -61,18 +61,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
"spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848" }, webEnvironment = RANDOM_PORT)
|
||||
public class NacosAutoServiceRegistrationIpNetworkInterfaceTests {
|
||||
|
||||
@Autowired
|
||||
private NacosRegistration registration;
|
||||
|
||||
@Autowired
|
||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties properties;
|
||||
|
||||
@Autowired
|
||||
private InetUtils inetUtils;
|
||||
|
||||
static {
|
||||
try {
|
||||
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
||||
@ -90,6 +78,15 @@ public class NacosAutoServiceRegistrationIpNetworkInterfaceTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private NacosRegistration registration;
|
||||
@Autowired
|
||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties properties;
|
||||
@Autowired
|
||||
private InetUtils inetUtils;
|
||||
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
assertThat(registration).isNotNull();
|
||||
|
@ -57,15 +57,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
"spring.cloud.nacos.discovery.ip=123.123.123.123" }, webEnvironment = RANDOM_PORT)
|
||||
public class NacosAutoServiceRegistrationIpTests {
|
||||
|
||||
@Autowired
|
||||
private NacosRegistration registration;
|
||||
|
||||
@Autowired
|
||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties properties;
|
||||
|
||||
static {
|
||||
try {
|
||||
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
||||
@ -83,6 +74,13 @@ public class NacosAutoServiceRegistrationIpTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private NacosRegistration registration;
|
||||
@Autowired
|
||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties properties;
|
||||
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
assertThat(registration).isNotNull();
|
||||
|
@ -58,15 +58,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
"spring.cloud.nacos.discovery.port=8888" }, webEnvironment = RANDOM_PORT)
|
||||
public class NacosAutoServiceRegistrationManagementPortTests {
|
||||
|
||||
@Autowired
|
||||
private NacosRegistration registration;
|
||||
|
||||
@Autowired
|
||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties properties;
|
||||
|
||||
static {
|
||||
try {
|
||||
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
||||
@ -84,6 +75,13 @@ public class NacosAutoServiceRegistrationManagementPortTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private NacosRegistration registration;
|
||||
@Autowired
|
||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties properties;
|
||||
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
assertThat(registration).isNotNull();
|
||||
|
@ -57,15 +57,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
"spring.cloud.nacos.discovery.port=8888" }, webEnvironment = RANDOM_PORT)
|
||||
public class NacosAutoServiceRegistrationPortTests {
|
||||
|
||||
@Autowired
|
||||
private NacosRegistration registration;
|
||||
|
||||
@Autowired
|
||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties properties;
|
||||
|
||||
static {
|
||||
try {
|
||||
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
||||
@ -83,6 +74,13 @@ public class NacosAutoServiceRegistrationPortTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private NacosRegistration registration;
|
||||
@Autowired
|
||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties properties;
|
||||
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
assertThat(registration).isNotNull();
|
||||
|
@ -74,24 +74,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
"spring.cloud.nacos.discovery.ip-delete-timeout=9" }, webEnvironment = RANDOM_PORT)
|
||||
public class NacosAutoServiceRegistrationTests {
|
||||
|
||||
@Autowired
|
||||
private NacosRegistration registration;
|
||||
|
||||
@Autowired
|
||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties properties;
|
||||
|
||||
@Autowired
|
||||
private NacosServiceManager nacosServiceManager;
|
||||
|
||||
@Autowired
|
||||
private InetUtils inetUtils;
|
||||
|
||||
static {
|
||||
try {
|
||||
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
||||
@ -109,6 +91,19 @@ public class NacosAutoServiceRegistrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private NacosRegistration registration;
|
||||
@Autowired
|
||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties properties;
|
||||
@Autowired
|
||||
private NacosServiceManager nacosServiceManager;
|
||||
@Autowired
|
||||
private InetUtils inetUtils;
|
||||
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
assertThat(registration).isNotNull();
|
||||
|
@ -61,7 +61,7 @@ public class NacosRibbonClientConfigurationTests {
|
||||
static class NacosRibbonTestConfiguration {
|
||||
|
||||
@Bean
|
||||
IClientConfig iClientConfig() {
|
||||
IClientConfig iClientConfig() {
|
||||
DefaultClientConfigImpl config = new DefaultClientConfigImpl();
|
||||
config.setClientName("myapp");
|
||||
return config;
|
||||
@ -69,7 +69,7 @@ public class NacosRibbonClientConfigurationTests {
|
||||
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class CommonTestConfig {
|
||||
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
RestTemplate loadBalancedRestTemplate() {
|
||||
RestTemplate loadBalancedRestTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public final class NacosMockTest {
|
||||
}
|
||||
|
||||
public static Instance serviceInstance(String serviceName, boolean isHealthy,
|
||||
Map<String, String> metadata) {
|
||||
Map<String, String> metadata) {
|
||||
Instance instance = new Instance();
|
||||
instance.setInstanceId(UUID.randomUUID().toString());
|
||||
instance.setServiceName(serviceName);
|
||||
@ -41,7 +41,7 @@ public final class NacosMockTest {
|
||||
}
|
||||
|
||||
public static Instance serviceInstance(String serviceName, boolean isHealthy,
|
||||
String host, int port, Map<String, String> metadata) {
|
||||
String host, int port, Map<String, String> metadata) {
|
||||
Instance instance = new Instance();
|
||||
instance.setIp(host);
|
||||
instance.setPort(port);
|
||||
|
@ -36,11 +36,9 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class SeataFeignClient implements Client {
|
||||
|
||||
private final Client delegate;
|
||||
|
||||
private final BeanFactory beanFactory;
|
||||
|
||||
private static final int MAP_SIZE = 16;
|
||||
private final Client delegate;
|
||||
private final BeanFactory beanFactory;
|
||||
|
||||
SeataFeignClient(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
|
@ -65,19 +65,19 @@ public class SeataFeignClientAutoConfiguration {
|
||||
protected static class FeignBeanPostProcessorConfiguration {
|
||||
|
||||
@Bean
|
||||
SeataBeanPostProcessor seataBeanPostProcessor(
|
||||
SeataBeanPostProcessor seataBeanPostProcessor(
|
||||
SeataFeignObjectWrapper seataFeignObjectWrapper) {
|
||||
return new SeataBeanPostProcessor(seataFeignObjectWrapper);
|
||||
}
|
||||
|
||||
@Bean
|
||||
SeataContextBeanPostProcessor seataContextBeanPostProcessor(
|
||||
SeataContextBeanPostProcessor seataContextBeanPostProcessor(
|
||||
BeanFactory beanFactory) {
|
||||
return new SeataContextBeanPostProcessor(beanFactory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
SeataFeignObjectWrapper seataFeignObjectWrapper(BeanFactory beanFactory) {
|
||||
SeataFeignObjectWrapper seataFeignObjectWrapper(BeanFactory beanFactory) {
|
||||
return new SeataFeignObjectWrapper(beanFactory);
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,9 @@ import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
|
||||
public class SeataLoadBalancerFeignClient extends LoadBalancerFeignClient {
|
||||
|
||||
SeataLoadBalancerFeignClient(Client delegate,
|
||||
CachingSpringLoadBalancerFactory lbClientFactory,
|
||||
SpringClientFactory clientFactory,
|
||||
SeataFeignObjectWrapper seataFeignObjectWrapper) {
|
||||
CachingSpringLoadBalancerFactory lbClientFactory,
|
||||
SpringClientFactory clientFactory,
|
||||
SeataFeignObjectWrapper seataFeignObjectWrapper) {
|
||||
super((Client) seataFeignObjectWrapper.wrap(delegate), lbClientFactory,
|
||||
clientFactory);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class SeataHystrixAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
SeataHystrixConcurrencyStrategy seataHystrixConcurrencyStrategy() {
|
||||
SeataHystrixConcurrencyStrategy seataHystrixConcurrencyStrategy() {
|
||||
return new SeataHystrixConcurrencyStrategy();
|
||||
}
|
||||
|
||||
|
@ -35,17 +35,16 @@ import org.springframework.web.client.RestTemplate;
|
||||
@Configuration
|
||||
public class SeataRestTemplateAutoConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
private Collection<RestTemplate> restTemplates;
|
||||
@Autowired
|
||||
private SeataRestTemplateInterceptor seataRestTemplateInterceptor;
|
||||
|
||||
@Bean
|
||||
public SeataRestTemplateInterceptor seataRestTemplateInterceptor() {
|
||||
return new SeataRestTemplateInterceptor();
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
private Collection<RestTemplate> restTemplates;
|
||||
|
||||
@Autowired
|
||||
private SeataRestTemplateInterceptor seataRestTemplateInterceptor;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
if (this.restTemplates != null) {
|
||||
|
@ -34,7 +34,7 @@ public class SeataRestTemplateInterceptor implements ClientHttpRequestIntercepto
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes,
|
||||
ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {
|
||||
ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {
|
||||
HttpRequestWrapper requestWrapper = new HttpRequestWrapper(httpRequest);
|
||||
|
||||
String xid = RootContext.getXID();
|
||||
|
@ -42,7 +42,7 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler) {
|
||||
Object handler) {
|
||||
|
||||
String xid = RootContext.getXID();
|
||||
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
||||
@ -61,7 +61,7 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler, Exception e) {
|
||||
Object handler, Exception e) {
|
||||
if (StringUtils.isNotBlank(RootContext.getXID())) {
|
||||
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
||||
|
||||
|
@ -27,16 +27,14 @@ import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
*/
|
||||
final class BlockClassRegistry {
|
||||
|
||||
private static final Map<String, Method> FALLBACK_MAP = new ConcurrentHashMap<>();
|
||||
private static final Map<String, Method> BLOCK_HANDLER_MAP = new ConcurrentHashMap<>();
|
||||
private static final Map<String, Method> URL_CLEANER_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
private BlockClassRegistry() {
|
||||
|
||||
}
|
||||
|
||||
private static final Map<String, Method> FALLBACK_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Map<String, Method> BLOCK_HANDLER_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Map<String, Method> URL_CLEANER_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
static Method lookupFallback(Class<?> clazz, String name) {
|
||||
return FALLBACK_MAP.get(getKey(clazz, name));
|
||||
}
|
||||
|
@ -154,8 +154,8 @@ public class SentinelAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SentinelDataSourceHandler sentinelDataSourceHandler(
|
||||
DefaultListableBeanFactory beanFactory, SentinelProperties sentinelProperties,
|
||||
Environment env) {
|
||||
DefaultListableBeanFactory beanFactory, SentinelProperties sentinelProperties,
|
||||
Environment env) {
|
||||
return new SentinelDataSourceHandler(beanFactory, sentinelProperties, env);
|
||||
}
|
||||
|
||||
|
@ -56,16 +56,15 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
||||
.getLogger(SentinelBeanPostProcessor.class);
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
private ConcurrentHashMap<String, SentinelRestTemplate> cache = new ConcurrentHashMap<>();
|
||||
|
||||
public SentinelBeanPostProcessor(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
private ConcurrentHashMap<String, SentinelRestTemplate> cache = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition,
|
||||
Class<?> beanType, String beanName) {
|
||||
Class<?> beanType, String beanName) {
|
||||
if (checkSentinelProtect(beanDefinition, beanType, beanName)) {
|
||||
SentinelRestTemplate sentinelRestTemplate;
|
||||
if (beanDefinition.getSource() instanceof StandardMethodMetadata) {
|
||||
@ -166,7 +165,7 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
||||
}
|
||||
|
||||
private boolean checkSentinelProtect(RootBeanDefinition beanDefinition,
|
||||
Class<?> beanType, String beanName) {
|
||||
Class<?> beanType, String beanName) {
|
||||
return beanName != null && beanType == RestTemplate.class
|
||||
&& checkMethodMetadataReadingVisitor(beanDefinition);
|
||||
}
|
||||
|
@ -52,23 +52,16 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton {
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(SentinelDataSourceHandler.class);
|
||||
|
||||
private final String DATA_TYPE_FIELD = "dataType";
|
||||
private final String CUSTOM_DATA_TYPE = "custom";
|
||||
private final String CONVERTER_CLASS_FIELD = "converterClass";
|
||||
private final DefaultListableBeanFactory beanFactory;
|
||||
private final SentinelProperties sentinelProperties;
|
||||
private final Environment env;
|
||||
private List<String> dataTypeList = Arrays.asList("json", "xml");
|
||||
|
||||
private final String DATA_TYPE_FIELD = "dataType";
|
||||
|
||||
private final String CUSTOM_DATA_TYPE = "custom";
|
||||
|
||||
private final String CONVERTER_CLASS_FIELD = "converterClass";
|
||||
|
||||
private final DefaultListableBeanFactory beanFactory;
|
||||
|
||||
private final SentinelProperties sentinelProperties;
|
||||
|
||||
private final Environment env;
|
||||
|
||||
public SentinelDataSourceHandler(DefaultListableBeanFactory beanFactory,
|
||||
SentinelProperties sentinelProperties, Environment env) {
|
||||
SentinelProperties sentinelProperties, Environment env) {
|
||||
this.beanFactory = beanFactory;
|
||||
this.sentinelProperties = sentinelProperties;
|
||||
this.env = env;
|
||||
|
@ -55,7 +55,7 @@ public class SentinelProtectInterceptor implements ClientHttpRequestInterceptor
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
|
||||
ClientHttpRequestExecution execution) throws IOException {
|
||||
ClientHttpRequestExecution execution) throws IOException {
|
||||
URI uri = request.getURI();
|
||||
String hostResource = request.getMethod().toString() + ":" + uri.getScheme()
|
||||
+ "://" + uri.getHost()
|
||||
@ -107,7 +107,7 @@ public class SentinelProtectInterceptor implements ClientHttpRequestInterceptor
|
||||
}
|
||||
|
||||
private ClientHttpResponse handleBlockException(HttpRequest request, byte[] body,
|
||||
ClientHttpRequestExecution execution, BlockException ex) {
|
||||
ClientHttpRequestExecution execution, BlockException ex) {
|
||||
Object[] args = new Object[] { request, body, execution, ex };
|
||||
// handle degrade
|
||||
if (isDegradeFailure(ex)) {
|
||||
|
@ -63,7 +63,7 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator {
|
||||
private SentinelProperties sentinelProperties;
|
||||
|
||||
public SentinelHealthIndicator(DefaultListableBeanFactory beanFactory,
|
||||
SentinelProperties sentinelProperties) {
|
||||
SentinelProperties sentinelProperties) {
|
||||
this.beanFactory = beanFactory;
|
||||
this.sentinelProperties = sentinelProperties;
|
||||
}
|
||||
@ -76,7 +76,7 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator {
|
||||
// detail
|
||||
if (!sentinelProperties.isEnabled()) {
|
||||
detailMap.put("enabled", false);
|
||||
builder.up().withDetails(detailMap);
|
||||
withDetails(builder.up(), detailMap);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -144,11 +144,16 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
// If Dashboard and DataSource are both OK, the health status is UP
|
||||
if (dashboardUp && dataSourceUp) {
|
||||
builder.up().withDetails(detailMap);
|
||||
withDetails(builder.up(), detailMap);
|
||||
}
|
||||
else {
|
||||
builder.unknown().withDetails(detailMap);
|
||||
withDetails(builder.down(), detailMap);
|
||||
}
|
||||
}
|
||||
|
||||
private void withDetails(Health.Builder builder, Map<String, Object> detailMap) {
|
||||
for (String key : detailMap.keySet()) {
|
||||
builder.withDetail(key, detailMap.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,13 +32,12 @@ import feign.MethodMetadata;
|
||||
*/
|
||||
public class SentinelContractHolder implements Contract {
|
||||
|
||||
private final Contract delegate;
|
||||
|
||||
/**
|
||||
* map key is constructed by ClassFullName + configKey. configKey is constructed by
|
||||
* {@link feign.Feign#configKey}
|
||||
*/
|
||||
public final static Map<String, MethodMetadata> METADATA_MAP = new HashMap<>();
|
||||
private final Contract delegate;
|
||||
|
||||
public SentinelContractHolder(Contract delegate) {
|
||||
this.delegate = delegate;
|
||||
|
@ -76,7 +76,7 @@ public final class SentinelFeign {
|
||||
super.invocationHandlerFactory(new InvocationHandlerFactory() {
|
||||
@Override
|
||||
public InvocationHandler create(Target target,
|
||||
Map<Method, MethodHandler> dispatch) {
|
||||
Map<Method, MethodHandler> dispatch) {
|
||||
// using reflect get fallback and fallbackFactory properties from
|
||||
// FeignClientFactoryBean because FeignClientFactoryBean is a package
|
||||
// level class, we can not use it in our package
|
||||
|
@ -53,7 +53,7 @@ public class SentinelInvocationHandler implements InvocationHandler {
|
||||
private Map<Method, Method> fallbackMethodMap;
|
||||
|
||||
SentinelInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch,
|
||||
FallbackFactory fallbackFactory) {
|
||||
FallbackFactory fallbackFactory) {
|
||||
this.target = checkNotNull(target, "target");
|
||||
this.dispatch = checkNotNull(dispatch, "dispatch");
|
||||
this.fallbackFactory = fallbackFactory;
|
||||
@ -65,13 +65,23 @@ public class SentinelInvocationHandler implements InvocationHandler {
|
||||
this.dispatch = checkNotNull(dispatch, "dispatch");
|
||||
}
|
||||
|
||||
static Map<Method, Method> toFallbackMethod(Map<Method, MethodHandler> dispatch) {
|
||||
Map<Method, Method> result = new LinkedHashMap<>();
|
||||
for (Method method : dispatch.keySet()) {
|
||||
method.setAccessible(true);
|
||||
result.put(method, method);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(final Object proxy, final Method method, final Object[] args)
|
||||
throws Throwable {
|
||||
if ("equals".equals(method.getName())) {
|
||||
try {
|
||||
Object otherHandler = args.length > 0 && args[0] != null
|
||||
? Proxy.getInvocationHandler(args[0]) : null;
|
||||
? Proxy.getInvocationHandler(args[0])
|
||||
: null;
|
||||
return equals(otherHandler);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
@ -99,7 +109,7 @@ public class SentinelInvocationHandler implements InvocationHandler {
|
||||
}
|
||||
else {
|
||||
String resourceName = methodMetadata.template().method().toUpperCase()
|
||||
+ ":" + hardCodedTarget.url() + methodMetadata.template().path();
|
||||
+ ":" + hardCodedTarget.url() + methodMetadata.template().url();
|
||||
Entry entry = null;
|
||||
try {
|
||||
ContextUtil.enter(resourceName);
|
||||
@ -166,13 +176,4 @@ public class SentinelInvocationHandler implements InvocationHandler {
|
||||
return target.toString();
|
||||
}
|
||||
|
||||
static Map<Method, Method> toFallbackMethod(Map<Method, MethodHandler> dispatch) {
|
||||
Map<Method, Method> result = new LinkedHashMap<>();
|
||||
for (Method method : dispatch.keySet()) {
|
||||
method.setAccessible(true);
|
||||
result.put(method, method);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -61,14 +61,6 @@ public class ContextIdSentinelFeignTests {
|
||||
assertThat(echoService.equals(fooService)).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ SentinelFeignAutoConfiguration.class })
|
||||
@EnableFeignClients
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
@FeignClient(contextId = "echoService", name = "service-provider", fallback = EchoServiceFallback.class, configuration = FeignConfiguration.class)
|
||||
public interface EchoService {
|
||||
|
||||
@ -85,6 +77,14 @@ public class ContextIdSentinelFeignTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ SentinelFeignAutoConfiguration.class })
|
||||
@EnableFeignClients
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
public static class FeignConfiguration {
|
||||
|
||||
@Bean
|
||||
|
@ -232,7 +232,7 @@ public class SentinelAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.getInterceptors().add(mock(ClientHttpRequestInterceptor.class));
|
||||
return restTemplate;
|
||||
@ -240,18 +240,18 @@ public class SentinelAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(blockHandlerClass = ExceptionUtil.class, blockHandler = "handleException")
|
||||
RestTemplate restTemplateWithBlockClass() {
|
||||
RestTemplate restTemplateWithBlockClass() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(fallbackClass = ExceptionUtil.class, fallback = "fallbackException")
|
||||
RestTemplate restTemplateWithFallbackClass() {
|
||||
RestTemplate restTemplateWithFallbackClass() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@Bean
|
||||
RestTemplate restTemplateWithoutBlockClass() {
|
||||
RestTemplate restTemplateWithoutBlockClass() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -260,13 +260,13 @@ public class SentinelAutoConfigurationTests {
|
||||
public static class ExceptionUtil {
|
||||
|
||||
public static SentinelClientHttpResponse handleException(HttpRequest request,
|
||||
byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
|
||||
byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
|
||||
System.out.println("Oops: " + ex.getClass().getCanonicalName());
|
||||
return new SentinelClientHttpResponse("Oops");
|
||||
}
|
||||
|
||||
public static SentinelClientHttpResponse fallbackException(HttpRequest request,
|
||||
byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
|
||||
byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
|
||||
System.out.println("Oops: " + ex.getClass().getCanonicalName());
|
||||
return new SentinelClientHttpResponse("Oops fallback");
|
||||
}
|
||||
|
@ -118,24 +118,6 @@ public class SentinelFeignTests {
|
||||
assertThat(echoService.equals(fooService)).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ SentinelFeignAutoConfiguration.class })
|
||||
@EnableFeignClients
|
||||
public static class TestConfig {
|
||||
|
||||
@Bean
|
||||
public EchoServiceFallback echoServiceFallback() {
|
||||
return new EchoServiceFallback();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CustomFallbackFactory customFallbackFactory() {
|
||||
return new CustomFallbackFactory();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@FeignClient(value = "test-service", fallback = EchoServiceFallback.class)
|
||||
public interface EchoService {
|
||||
|
||||
@ -172,6 +154,24 @@ public class SentinelFeignTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ SentinelFeignAutoConfiguration.class })
|
||||
@EnableFeignClients
|
||||
public static class TestConfig {
|
||||
|
||||
@Bean
|
||||
public EchoServiceFallback echoServiceFallback() {
|
||||
return new EchoServiceFallback();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CustomFallbackFactory customFallbackFactory() {
|
||||
return new CustomFallbackFactory();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class EchoServiceFallback implements EchoService {
|
||||
|
||||
@Override
|
||||
|
@ -114,14 +114,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig1 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(fallback = "fbk")
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -131,14 +131,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig2 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(fallbackClass = ExceptionUtil.class)
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -148,14 +148,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig3 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(blockHandler = "blk")
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -165,14 +165,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig4 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(blockHandlerClass = ExceptionUtil.class)
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -182,14 +182,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig5 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(blockHandlerClass = ExceptionUtil.class, blockHandler = "handleException", fallbackClass = ExceptionUtil.class, fallback = "fallbackException", urlCleanerClass = UrlCleanUtil.class, urlCleaner = "clean")
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -199,14 +199,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig6 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(blockHandlerClass = ExceptionUtil.class, blockHandler = "handleException1")
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -216,14 +216,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig7 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(fallbackClass = ExceptionUtil.class, fallback = "fallbackException1")
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -233,14 +233,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig8 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(blockHandlerClass = ExceptionUtil.class, blockHandler = "handleException2")
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -250,14 +250,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig9 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(fallbackClass = ExceptionUtil.class, fallback = "fallbackException2")
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -267,20 +267,20 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig10 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate
|
||||
RestTemplate restTemplate2() {
|
||||
RestTemplate restTemplate2() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -290,14 +290,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig11 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(urlCleaner = "cln")
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -307,14 +307,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig12 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(urlCleanerClass = UrlCleanUtil.class)
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -324,14 +324,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig13 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(urlCleanerClass = UrlCleanUtil.class, urlCleaner = "clean1")
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -341,14 +341,14 @@ public class SentinelRestTemplateTests {
|
||||
public static class TestConfig14 {
|
||||
|
||||
@Bean
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||
ApplicationContext applicationContext) {
|
||||
return new SentinelBeanPostProcessor(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SentinelRestTemplate(urlCleanerClass = UrlCleanUtil.class, urlCleaner = "clean2")
|
||||
RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@ -357,24 +357,24 @@ public class SentinelRestTemplateTests {
|
||||
public static class ExceptionUtil {
|
||||
|
||||
public static SentinelClientHttpResponse handleException(HttpRequest request,
|
||||
byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
|
||||
byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
|
||||
System.out.println("Oops: " + ex.getClass().getCanonicalName());
|
||||
return new SentinelClientHttpResponse("Oops");
|
||||
}
|
||||
|
||||
public static void handleException2(HttpRequest request, byte[] body,
|
||||
ClientHttpRequestExecution execution, BlockException ex) {
|
||||
ClientHttpRequestExecution execution, BlockException ex) {
|
||||
System.out.println("Oops: " + ex.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
public static SentinelClientHttpResponse fallbackException(HttpRequest request,
|
||||
byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
|
||||
byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
|
||||
System.out.println("Oops: " + ex.getClass().getCanonicalName());
|
||||
return new SentinelClientHttpResponse("Oops fallback");
|
||||
}
|
||||
|
||||
public static void fallbackException2(HttpRequest request, byte[] body,
|
||||
ClientHttpRequestExecution execution, BlockException ex) {
|
||||
ClientHttpRequestExecution execution, BlockException ex) {
|
||||
System.out.println("Oops: " + ex.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
|
@ -48,8 +48,8 @@ public class SidecarHealthChecker {
|
||||
private final ConfigurableEnvironment environment;
|
||||
|
||||
public SidecarHealthChecker(SidecarDiscoveryClient sidecarDiscoveryClient,
|
||||
HealthIndicator healthIndicator, SidecarProperties sidecarProperties,
|
||||
ConfigurableEnvironment environment) {
|
||||
HealthIndicator healthIndicator, SidecarProperties sidecarProperties,
|
||||
ConfigurableEnvironment environment) {
|
||||
this.sidecarDiscoveryClient = sidecarDiscoveryClient;
|
||||
this.healthIndicator = healthIndicator;
|
||||
this.sidecarProperties = sidecarProperties;
|
||||
|
@ -30,10 +30,8 @@ public class SidecarNacosDiscoveryClient implements SidecarDiscoveryClient {
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(SidecarNacosDiscoveryClient.class);
|
||||
|
||||
private NacosServiceManager nacosServiceManager;
|
||||
|
||||
private final SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties;
|
||||
private NacosServiceManager nacosServiceManager;
|
||||
|
||||
public SidecarNacosDiscoveryClient(NacosServiceManager nacosServiceManager,
|
||||
SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties) {
|
||||
|
@ -65,7 +65,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
@AutoConfigureAfter(name = {
|
||||
"org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration" })
|
||||
public class DubboLoadBalancedRestTemplateAutoConfiguration implements
|
||||
BeanClassLoaderAware, ApplicationContextAware, SmartInitializingSingleton {
|
||||
BeanClassLoaderAware, ApplicationContextAware, SmartInitializingSingleton {
|
||||
|
||||
private static final Class<DubboTransported> DUBBO_TRANSPORTED_CLASS = DubboTransported.class;
|
||||
|
||||
@ -111,7 +111,8 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements
|
||||
@Override
|
||||
public void afterSingletonsInstantiated() {
|
||||
loadBalancerInterceptorBean = retryLoadBalancerInterceptor != null
|
||||
? retryLoadBalancerInterceptor : loadBalancerInterceptor;
|
||||
? retryLoadBalancerInterceptor
|
||||
: loadBalancerInterceptor;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,7 +146,7 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements
|
||||
* Gets the annotation attributes {@link RestTemplate} bean being annotated
|
||||
* {@link DubboTransported @DubboTransported}.
|
||||
* @param beanName the bean name of {@link LoadBalanced @LoadBalanced}
|
||||
* {@link RestTemplate}
|
||||
* {@link RestTemplate}
|
||||
* @param attributesResolver {@link DubboTransportedAttributesResolver}
|
||||
* @return non-null {@link Map}
|
||||
*/
|
||||
@ -170,11 +171,11 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements
|
||||
* {@link LoadBalancerInterceptor} Bean.
|
||||
* @param restTemplate {@link LoadBalanced @LoadBalanced} {@link RestTemplate} Bean
|
||||
* @param dubboTranslatedAttributes the annotation dubboTranslatedAttributes
|
||||
* {@link RestTemplate} bean being annotated
|
||||
* {@link DubboTransported @DubboTransported}
|
||||
* {@link RestTemplate} bean being annotated
|
||||
* {@link DubboTransported @DubboTransported}
|
||||
*/
|
||||
private void adaptRestTemplate(RestTemplate restTemplate,
|
||||
Map<String, Object> dubboTranslatedAttributes) {
|
||||
Map<String, Object> dubboTranslatedAttributes) {
|
||||
|
||||
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(
|
||||
restTemplate.getInterceptors());
|
||||
|
@ -47,9 +47,9 @@ public class DubboOpenFeignAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public TargeterBeanPostProcessor targeterBeanPostProcessor(Environment environment,
|
||||
DubboServiceMetadataRepository dubboServiceMetadataRepository,
|
||||
DubboGenericServiceFactory dubboGenericServiceFactory,
|
||||
DubboGenericServiceExecutionContextFactory contextFactory) {
|
||||
DubboServiceMetadataRepository dubboServiceMetadataRepository,
|
||||
DubboGenericServiceFactory dubboGenericServiceFactory,
|
||||
DubboGenericServiceExecutionContextFactory contextFactory) {
|
||||
return new TargeterBeanPostProcessor(environment, dubboServiceMetadataRepository,
|
||||
dubboGenericServiceFactory, contextFactory);
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ public class DubboServiceDiscoveryAutoConfiguration {
|
||||
private final ThreadLocal<String> processedServiceNameThreadLocal;
|
||||
|
||||
ZookeeperConfiguration(ZookeeperDiscoveryProperties zookeeperDiscoveryProperties,
|
||||
ZookeeperServiceWatch zookeeperServiceWatch) {
|
||||
ZookeeperServiceWatch zookeeperServiceWatch) {
|
||||
this.zookeeperServiceWatch = zookeeperServiceWatch;
|
||||
this.rootPath = zookeeperDiscoveryProperties.getRoot();
|
||||
this.pathMatcher = new AntPathMatcher(NODE_PATH_SEPARATOR);
|
||||
|
@ -43,7 +43,7 @@ public class MissingSpringCloudRegistryConfigPropertyCondition
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
ConfigurableEnvironment environment = (ConfigurableEnvironment) context
|
||||
.getEnvironment();
|
||||
|
||||
|
@ -42,7 +42,7 @@ class DubboClientHttpResponse implements ClientHttpResponse {
|
||||
private final DubboHttpOutputMessage httpOutputMessage;
|
||||
|
||||
DubboClientHttpResponse(DubboHttpOutputMessage httpOutputMessage,
|
||||
GenericException exception) {
|
||||
GenericException exception) {
|
||||
this.httpStatus = exception != null ? HttpStatus.INTERNAL_SERVER_ERROR
|
||||
: HttpStatus.OK;
|
||||
this.statusText = exception != null ? exception.getExceptionMessage()
|
||||
|
@ -45,7 +45,7 @@ class DubboClientHttpResponseFactory {
|
||||
}
|
||||
|
||||
public ClientHttpResponse build(Object result, GenericException exception,
|
||||
RequestMetadata requestMetadata, RestMethodMetadata restMethodMetadata) {
|
||||
RequestMetadata requestMetadata, RestMethodMetadata restMethodMetadata) {
|
||||
|
||||
DubboHttpOutputMessage httpOutputMessage = new DubboHttpOutputMessage();
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class DubboMetadataInitializerInterceptor implements ClientHttpRequestInt
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
|
||||
ClientHttpRequestExecution execution) throws IOException {
|
||||
ClientHttpRequestExecution execution) throws IOException {
|
||||
|
||||
URI originalUri = request.getURI();
|
||||
|
||||
|
@ -66,11 +66,11 @@ public class DubboTransporterInterceptor implements ClientHttpRequestInterceptor
|
||||
private final PathMatcher pathMatcher = new AntPathMatcher();
|
||||
|
||||
public DubboTransporterInterceptor(
|
||||
DubboServiceMetadataRepository dubboServiceMetadataRepository,
|
||||
List<HttpMessageConverter<?>> messageConverters, ClassLoader classLoader,
|
||||
Map<String, Object> dubboTranslatedAttributes,
|
||||
DubboGenericServiceFactory serviceFactory,
|
||||
DubboGenericServiceExecutionContextFactory contextFactory) {
|
||||
DubboServiceMetadataRepository dubboServiceMetadataRepository,
|
||||
List<HttpMessageConverter<?>> messageConverters, ClassLoader classLoader,
|
||||
Map<String, Object> dubboTranslatedAttributes,
|
||||
DubboGenericServiceFactory serviceFactory,
|
||||
DubboGenericServiceExecutionContextFactory contextFactory) {
|
||||
this.repository = dubboServiceMetadataRepository;
|
||||
this.dubboTranslatedAttributes = dubboTranslatedAttributes;
|
||||
this.clientHttpResponseFactory = new DubboClientHttpResponseFactory(
|
||||
@ -81,7 +81,7 @@ public class DubboTransporterInterceptor implements ClientHttpRequestInterceptor
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
|
||||
ClientHttpRequestExecution execution) throws IOException {
|
||||
ClientHttpRequestExecution execution) throws IOException {
|
||||
|
||||
URI originalUri = request.getURI();
|
||||
|
||||
@ -125,7 +125,7 @@ public class DubboTransporterInterceptor implements ClientHttpRequestInterceptor
|
||||
}
|
||||
|
||||
protected void customizeRequest(MutableHttpServerRequest httpServerRequest,
|
||||
RestMethodMetadata dubboRestMethodMetadata, RequestMetadata clientMetadata) {
|
||||
RestMethodMetadata dubboRestMethodMetadata, RequestMetadata clientMetadata) {
|
||||
|
||||
RequestMetadata dubboRequestMetadata = dubboRestMethodMetadata.getRequest();
|
||||
String pathPattern = dubboRequestMetadata.getPath();
|
||||
|
@ -84,7 +84,7 @@ public class DubboNonWebApplicationEnvironmentPostProcessor
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||
SpringApplication application) {
|
||||
SpringApplication application) {
|
||||
WebApplicationType webApplicationType = application.getWebApplicationType();
|
||||
|
||||
if (!WebApplicationType.NONE.equals(webApplicationType)) { // Just works in
|
||||
@ -117,7 +117,7 @@ public class DubboNonWebApplicationEnvironmentPostProcessor
|
||||
* @param defaultProperties defaultProperties
|
||||
*/
|
||||
private void resetServerPort(ConfigurableEnvironment environment,
|
||||
Map<String, Object> defaultProperties) {
|
||||
Map<String, Object> defaultProperties) {
|
||||
|
||||
String serverPort = environment.getProperty(SERVER_PORT_PROPERTY_NAME,
|
||||
environment.getProperty(PORT_PROPERTY_NAME));
|
||||
@ -141,7 +141,8 @@ public class DubboNonWebApplicationEnvironmentPostProcessor
|
||||
DEFAULT_PROTOCOL);
|
||||
|
||||
return isRestProtocol(protocol)
|
||||
? environment.getProperty(PROTOCOL_PORT_PROPERTY_NAME) : null;
|
||||
? environment.getProperty(PROTOCOL_PORT_PROPERTY_NAME)
|
||||
: null;
|
||||
}
|
||||
|
||||
private String getRestPortFromProtocolsProperties(
|
||||
@ -181,7 +182,7 @@ public class DubboNonWebApplicationEnvironmentPostProcessor
|
||||
}
|
||||
|
||||
private void setServerPort(ConfigurableEnvironment environment, String serverPort,
|
||||
Map<String, Object> defaultProperties) {
|
||||
Map<String, Object> defaultProperties) {
|
||||
if (serverPort == null) {
|
||||
return;
|
||||
}
|
||||
@ -196,7 +197,7 @@ public class DubboNonWebApplicationEnvironmentPostProcessor
|
||||
* @param map Default Dubbo Properties
|
||||
*/
|
||||
private void addOrReplace(MutablePropertySources propertySources,
|
||||
Map<String, Object> map) {
|
||||
Map<String, Object> map) {
|
||||
MapPropertySource target = null;
|
||||
if (propertySources.contains(PROPERTY_SOURCE_NAME)) {
|
||||
PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME);
|
||||
|
@ -31,7 +31,7 @@ public class HttpMessageConverterHolder {
|
||||
private final HttpMessageConverter<?> converter;
|
||||
|
||||
public HttpMessageConverterHolder(MediaType mediaType,
|
||||
HttpMessageConverter<?> converter) {
|
||||
HttpMessageConverter<?> converter) {
|
||||
this.mediaType = mediaType;
|
||||
this.converter = converter;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class HttpRequestConsumersMatcher extends AbstractHttpRequestMatcher {
|
||||
/**
|
||||
* Creates a new instance from 0 or more "consumes" expressions.
|
||||
* @param consumes consumes expressions if 0 expressions are provided, the condition
|
||||
* will match to every request
|
||||
* will match to every request
|
||||
*/
|
||||
public HttpRequestConsumersMatcher(String... consumes) {
|
||||
this(consumes, null);
|
||||
@ -69,7 +69,7 @@ public class HttpRequestConsumersMatcher extends AbstractHttpRequestMatcher {
|
||||
}
|
||||
|
||||
private static Set<ConsumeMediaTypeExpression> parseExpressions(String[] consumes,
|
||||
String[] headers) {
|
||||
String[] headers) {
|
||||
Set<ConsumeMediaTypeExpression> result = new LinkedHashSet<>();
|
||||
if (headers != null) {
|
||||
for (String header : headers) {
|
||||
|
@ -34,10 +34,10 @@ public class HttpRequestParamsMatcher extends AbstractHttpRequestMatcher {
|
||||
|
||||
/**
|
||||
* @param params The pattern of params :
|
||||
* <ul>
|
||||
* <li>name=value</li>
|
||||
* <li>name</li>
|
||||
* </ul>
|
||||
* <ul>
|
||||
* <li>name=value</li>
|
||||
* <li>name</li>
|
||||
* </ul>
|
||||
*/
|
||||
public HttpRequestParamsMatcher(String... params) {
|
||||
this.expressions = parseExpressions(params);
|
||||
|
@ -59,7 +59,7 @@ public class HttpMessageConverterResolver {
|
||||
}
|
||||
|
||||
public HttpMessageConverterHolder resolve(HttpRequest request,
|
||||
Class<?> parameterType) {
|
||||
Class<?> parameterType) {
|
||||
|
||||
HttpMessageConverterHolder httpMessageConverterHolder = null;
|
||||
|
||||
@ -100,7 +100,7 @@ public class HttpMessageConverterResolver {
|
||||
* @return instance of {@link HttpMessageConverterHolder}
|
||||
*/
|
||||
public HttpMessageConverterHolder resolve(RequestMetadata requestMetadata,
|
||||
RestMethodMetadata restMethodMetadata) {
|
||||
RestMethodMetadata restMethodMetadata) {
|
||||
|
||||
HttpMessageConverterHolder httpMessageConverterHolder = null;
|
||||
|
||||
@ -190,7 +190,7 @@ public class HttpMessageConverterResolver {
|
||||
* @return non-null {@link List}
|
||||
*/
|
||||
private List<MediaType> getProducibleMediaTypes(RestMethodMetadata restMethodMetadata,
|
||||
Class<?> returnValueClass) {
|
||||
Class<?> returnValueClass) {
|
||||
RequestMetadata serverRequestMetadata = restMethodMetadata.getRequest();
|
||||
List<MediaType> mediaTypes = serverRequestMetadata.getProduceMediaTypes();
|
||||
if (!CollectionUtils.isEmpty(mediaTypes)) { // Empty
|
||||
@ -232,7 +232,7 @@ public class HttpMessageConverterResolver {
|
||||
* q-value of the former.
|
||||
*/
|
||||
private MediaType getMostSpecificMediaType(MediaType acceptType,
|
||||
MediaType produceType) {
|
||||
MediaType produceType) {
|
||||
MediaType produceTypeToUse = produceType.copyQualityValue(acceptType);
|
||||
return (MediaType.SPECIFICITY_COMPARATOR.compare(acceptType,
|
||||
produceTypeToUse) <= 0 ? acceptType : produceTypeToUse);
|
||||
|
@ -244,7 +244,7 @@ public abstract class HttpUtils {
|
||||
}
|
||||
|
||||
private static void addParam(MultiValueMap<String, String> paramsMap, String name,
|
||||
String value) {
|
||||
String value) {
|
||||
String paramValue = trimAllWhitespace(value);
|
||||
if (!StringUtils.hasText(paramValue)) {
|
||||
paramValue = EMPTY_VALUE;
|
||||
|
@ -30,7 +30,7 @@ public class DubboRestServiceMetadata {
|
||||
private final RestMethodMetadata restMethodMetadata;
|
||||
|
||||
public DubboRestServiceMetadata(ServiceRestMetadata serviceRestMetadata,
|
||||
RestMethodMetadata restMethodMetadata) {
|
||||
RestMethodMetadata restMethodMetadata) {
|
||||
this.serviceRestMetadata = serviceRestMetadata;
|
||||
this.restMethodMetadata = restMethodMetadata;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class MethodMetadata {
|
||||
}
|
||||
|
||||
private MethodParameterMetadata toMethodParameterMetadata(int index,
|
||||
Parameter parameter) {
|
||||
Parameter parameter) {
|
||||
MethodParameterMetadata metadata = new MethodParameterMetadata();
|
||||
metadata.setIndex(index);
|
||||
metadata.setName(parameter.getName());
|
||||
|
@ -111,7 +111,7 @@ public class RequestMetadata {
|
||||
}
|
||||
|
||||
private static void mediaTypes(HttpHeaders httpHeaders, String headerName,
|
||||
Collection<String> destination) {
|
||||
Collection<String> destination) {
|
||||
List<String> value = httpHeaders.get(headerName);
|
||||
List<MediaType> mediaTypes = parseMediaTypes(value);
|
||||
destination.addAll(toMediaTypeValues(mediaTypes));
|
||||
|
@ -397,7 +397,7 @@ public class DubboServiceMetadataRepository
|
||||
}
|
||||
|
||||
public Integer getDubboProtocolPort(ServiceInstance serviceInstance,
|
||||
String protocol) {
|
||||
String protocol) {
|
||||
return dubboMetadataUtils.getDubboProtocolPort(serviceInstance, protocol);
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ public class DubboServiceBeanMetadataResolver
|
||||
}
|
||||
|
||||
private List<MethodMetadata> parseAndValidateMetadata(Contract contract,
|
||||
Class<?> targetType) {
|
||||
Class<?> targetType) {
|
||||
List<MethodMetadata> methodMetadataList = Collections.emptyList();
|
||||
try {
|
||||
methodMetadataList = contract.parseAndValidatateMetadata(targetType);
|
||||
@ -171,7 +171,7 @@ public class DubboServiceBeanMetadataResolver
|
||||
}
|
||||
|
||||
protected RestMethodMetadata resolveMethodRestMetadata(MethodMetadata methodMetadata,
|
||||
Class<?> targetType, List<Method> feignContractMethods) {
|
||||
Class<?> targetType, List<Method> feignContractMethods) {
|
||||
String configKey = methodMetadata.configKey();
|
||||
Method feignContractMethod = getMatchedFeignContractMethod(targetType,
|
||||
feignContractMethods, configKey);
|
||||
|
@ -49,7 +49,7 @@ public class DubboTransportedMethodMetadataResolver {
|
||||
private final Contract contract;
|
||||
|
||||
public DubboTransportedMethodMetadataResolver(PropertyResolver propertyResolver,
|
||||
Contract contract) {
|
||||
Contract contract) {
|
||||
this.attributesResolver = new DubboTransportedAttributesResolver(
|
||||
propertyResolver);
|
||||
this.contract = contract;
|
||||
|
@ -50,9 +50,9 @@ public class TargeterBeanPostProcessor
|
||||
private ClassLoader classLoader;
|
||||
|
||||
public TargeterBeanPostProcessor(Environment environment,
|
||||
DubboServiceMetadataRepository dubboServiceMetadataRepository,
|
||||
DubboGenericServiceFactory dubboGenericServiceFactory,
|
||||
DubboGenericServiceExecutionContextFactory contextFactory) {
|
||||
DubboServiceMetadataRepository dubboServiceMetadataRepository,
|
||||
DubboGenericServiceFactory dubboGenericServiceFactory,
|
||||
DubboGenericServiceExecutionContextFactory contextFactory) {
|
||||
this.environment = environment;
|
||||
this.dubboServiceMetadataRepository = dubboServiceMetadataRepository;
|
||||
this.dubboGenericServiceFactory = dubboGenericServiceFactory;
|
||||
|
@ -98,7 +98,7 @@ class TargeterInvocationHandler implements InvocationHandler {
|
||||
}
|
||||
|
||||
private Object createDubboProxyIfRequired(FeignContext feignContext, Target target,
|
||||
Object defaultProxy) {
|
||||
Object defaultProxy) {
|
||||
|
||||
DubboInvocationHandler dubboInvocationHandler = createDubboInvocationHandler(
|
||||
feignContext, target, defaultProxy);
|
||||
@ -112,7 +112,7 @@ class TargeterInvocationHandler implements InvocationHandler {
|
||||
}
|
||||
|
||||
private DubboInvocationHandler createDubboInvocationHandler(FeignContext feignContext,
|
||||
Target target, Object defaultFeignClientProxy) {
|
||||
Target target, Object defaultFeignClientProxy) {
|
||||
|
||||
// Service name equals @FeignClient.name()
|
||||
String serviceName = target.name();
|
||||
@ -153,7 +153,7 @@ class TargeterInvocationHandler implements InvocationHandler {
|
||||
}
|
||||
|
||||
private Map<Method, FeignMethodMetadata> getFeignMethodMetadataMap(String serviceName,
|
||||
Map<DubboTransportedMethodMetadata, RestMethodMetadata> feignRestMethodMetadataMap) {
|
||||
Map<DubboTransportedMethodMetadata, RestMethodMetadata> feignRestMethodMetadataMap) {
|
||||
Map<Method, FeignMethodMetadata> feignMethodMetadataMap = new HashMap<>();
|
||||
|
||||
for (Map.Entry<DubboTransportedMethodMetadata, RestMethodMetadata> entry : feignRestMethodMetadataMap
|
||||
|
@ -99,10 +99,10 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
||||
private final ConfigurableApplicationContext applicationContext;
|
||||
|
||||
public AbstractSpringCloudRegistry(URL url, DiscoveryClient discoveryClient,
|
||||
DubboServiceMetadataRepository dubboServiceMetadataRepository,
|
||||
DubboMetadataServiceProxy dubboMetadataConfigServiceProxy,
|
||||
JSONUtils jsonUtils, DubboGenericServiceFactory dubboGenericServiceFactory,
|
||||
ConfigurableApplicationContext applicationContext) {
|
||||
DubboServiceMetadataRepository dubboServiceMetadataRepository,
|
||||
DubboMetadataServiceProxy dubboMetadataConfigServiceProxy,
|
||||
JSONUtils jsonUtils, DubboGenericServiceFactory dubboGenericServiceFactory,
|
||||
ConfigurableApplicationContext applicationContext) {
|
||||
super(url);
|
||||
this.servicesLookupInterval = url
|
||||
.getParameter(SERVICES_LOOKUP_INTERVAL_PARAM_NAME, 60L);
|
||||
@ -356,7 +356,7 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
||||
}
|
||||
|
||||
private List<URL> getExportedURLs(DubboMetadataService dubboMetadataService,
|
||||
URL url) {
|
||||
URL url) {
|
||||
String serviceInterface = url.getServiceInterface();
|
||||
String group = url.getParameter(GROUP_KEY);
|
||||
String version = url.getParameter(VERSION_KEY);
|
||||
|
@ -109,10 +109,10 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
||||
private final String currentApplicationName;
|
||||
|
||||
public DubboCloudRegistry(URL url, DiscoveryClient discoveryClient,
|
||||
DubboServiceMetadataRepository repository,
|
||||
DubboMetadataServiceProxy dubboMetadataConfigServiceProxy,
|
||||
JSONUtils jsonUtils, DubboGenericServiceFactory dubboGenericServiceFactory,
|
||||
ConfigurableApplicationContext applicationContext) {
|
||||
DubboServiceMetadataRepository repository,
|
||||
DubboMetadataServiceProxy dubboMetadataConfigServiceProxy,
|
||||
JSONUtils jsonUtils, DubboGenericServiceFactory dubboGenericServiceFactory,
|
||||
ConfigurableApplicationContext applicationContext) {
|
||||
|
||||
super(url);
|
||||
this.servicesLookupInterval = url
|
||||
@ -415,7 +415,7 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
||||
}
|
||||
|
||||
private List<URL> getExportedURLs(DubboMetadataService dubboMetadataService,
|
||||
URL subscribedURL) {
|
||||
URL subscribedURL) {
|
||||
String serviceInterface = subscribedURL.getServiceInterface();
|
||||
String group = subscribedURL.getParameter(GROUP_KEY);
|
||||
String version = subscribedURL.getParameter(VERSION_KEY);
|
||||
|
@ -40,10 +40,10 @@ public class SpringCloudRegistry extends AbstractSpringCloudRegistry {
|
||||
private final DubboServiceMetadataRepository dubboServiceMetadataRepository;
|
||||
|
||||
public SpringCloudRegistry(URL url, DiscoveryClient discoveryClient,
|
||||
DubboServiceMetadataRepository dubboServiceMetadataRepository,
|
||||
DubboMetadataServiceProxy dubboMetadataConfigServiceProxy,
|
||||
JSONUtils jsonUtils, DubboGenericServiceFactory dubboGenericServiceFactory,
|
||||
ConfigurableApplicationContext applicationContext) {
|
||||
DubboServiceMetadataRepository dubboServiceMetadataRepository,
|
||||
DubboMetadataServiceProxy dubboMetadataConfigServiceProxy,
|
||||
JSONUtils jsonUtils, DubboGenericServiceFactory dubboGenericServiceFactory,
|
||||
ConfigurableApplicationContext applicationContext) {
|
||||
super(url, discoveryClient, dubboServiceMetadataRepository,
|
||||
dubboMetadataConfigServiceProxy, jsonUtils, dubboGenericServiceFactory,
|
||||
applicationContext);
|
||||
|
@ -82,7 +82,7 @@ public class DubboGenericServiceFactory {
|
||||
}
|
||||
|
||||
private ReferenceBean<GenericService> build(ServiceRestMetadata serviceRestMetadata,
|
||||
Map<String, Object> dubboTranslatedAttributes) {
|
||||
Map<String, Object> dubboTranslatedAttributes) {
|
||||
String urlValue = serviceRestMetadata.getUrl();
|
||||
URL url = URL.valueOf(urlValue);
|
||||
String interfaceName = url.getServiceInterface();
|
||||
@ -127,8 +127,7 @@ public class DubboGenericServiceFactory {
|
||||
new PropertyEditorSupport() {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text)
|
||||
throws IllegalArgumentException {
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
// Trim all whitespace
|
||||
String content = StringUtils.trimAllWhitespace(text);
|
||||
if (!StringUtils.hasText(content)) { // No content , ignore
|
||||
|
@ -48,7 +48,7 @@ public abstract class AbstractNamedValueServiceParameterResolver
|
||||
|
||||
@Override
|
||||
public Object resolve(RestMethodMetadata restMethodMetadata,
|
||||
MethodParameterMetadata methodParameterMetadata, HttpServerRequest request) {
|
||||
MethodParameterMetadata methodParameterMetadata, HttpServerRequest request) {
|
||||
|
||||
Collection<String> names = getNames(restMethodMetadata, methodParameterMetadata);
|
||||
|
||||
@ -87,8 +87,8 @@ public abstract class AbstractNamedValueServiceParameterResolver
|
||||
|
||||
@Override
|
||||
public Object resolve(RestMethodMetadata restMethodMetadata,
|
||||
MethodParameterMetadata methodParameterMetadata,
|
||||
RestMethodMetadata clientRestMethodMetadata, Object[] arguments) {
|
||||
MethodParameterMetadata methodParameterMetadata,
|
||||
RestMethodMetadata clientRestMethodMetadata, Object[] arguments) {
|
||||
|
||||
Collection<String> names = getNames(restMethodMetadata, methodParameterMetadata);
|
||||
|
||||
@ -116,7 +116,7 @@ public abstract class AbstractNamedValueServiceParameterResolver
|
||||
}
|
||||
|
||||
protected Collection<String> getNames(RestMethodMetadata restMethodMetadata,
|
||||
MethodParameterMetadata methodParameterMetadata) {
|
||||
MethodParameterMetadata methodParameterMetadata) {
|
||||
|
||||
Map<Integer, Collection<String>> indexToName = restMethodMetadata
|
||||
.getIndexToName();
|
||||
|
@ -38,10 +38,10 @@ public interface DubboGenericServiceParameterResolver extends Ordered {
|
||||
* @return the result of resolve
|
||||
*/
|
||||
Object resolve(RestMethodMetadata restMethodMetadata,
|
||||
MethodParameterMetadata methodParameterMetadata, HttpServerRequest request);
|
||||
MethodParameterMetadata methodParameterMetadata, HttpServerRequest request);
|
||||
|
||||
Object resolve(RestMethodMetadata restMethodMetadata,
|
||||
MethodParameterMetadata methodParameterMetadata,
|
||||
RestMethodMetadata clientRestMethodMetadata, Object[] arguments);
|
||||
MethodParameterMetadata methodParameterMetadata,
|
||||
RestMethodMetadata clientRestMethodMetadata, Object[] arguments);
|
||||
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public class RequestBodyServiceParameterResolver
|
||||
}
|
||||
|
||||
private boolean supportParameter(RestMethodMetadata restMethodMetadata,
|
||||
MethodParameterMetadata methodParameterMetadata) {
|
||||
MethodParameterMetadata methodParameterMetadata) {
|
||||
|
||||
Integer index = methodParameterMetadata.getIndex();
|
||||
|
||||
@ -88,7 +88,7 @@ public class RequestBodyServiceParameterResolver
|
||||
|
||||
@Override
|
||||
public Object resolve(RestMethodMetadata restMethodMetadata,
|
||||
MethodParameterMetadata methodParameterMetadata, HttpServerRequest request) {
|
||||
MethodParameterMetadata methodParameterMetadata, HttpServerRequest request) {
|
||||
|
||||
if (!supportParameter(restMethodMetadata, methodParameterMetadata)) {
|
||||
return null;
|
||||
@ -117,8 +117,8 @@ public class RequestBodyServiceParameterResolver
|
||||
|
||||
@Override
|
||||
public Object resolve(RestMethodMetadata restMethodMetadata,
|
||||
MethodParameterMetadata methodParameterMetadata,
|
||||
RestMethodMetadata clientRestMethodMetadata, Object[] arguments) {
|
||||
MethodParameterMetadata methodParameterMetadata,
|
||||
RestMethodMetadata clientRestMethodMetadata, Object[] arguments) {
|
||||
|
||||
if (!supportParameter(restMethodMetadata, methodParameterMetadata)) {
|
||||
return null;
|
||||
|
@ -108,7 +108,7 @@ public class DubboMetadataUtils {
|
||||
}
|
||||
|
||||
public Integer getDubboProtocolPort(ServiceInstance serviceInstance,
|
||||
String protocol) {
|
||||
String protocol) {
|
||||
String protocolProperty = getDubboProtocolPropertyName(protocol);
|
||||
Map<String, String> metadata = serviceInstance.getMetadata();
|
||||
String protocolPort = metadata.get(protocolProperty);
|
||||
|
Loading…
x
Reference in New Issue
Block a user