Refactor deprecated code.

1. Spring 的 StringUtils#isEmpty 已经过时, 使用 spring-cloud-alibaba-commons 下的 StringUtils 替换, 如果同时还使用了
Spring StringUtils 的其他方法, 那么将使用 StringUtils#hasLength 取反替换

2. 移除类 NacosRefreshProperties

3. 优化pom, 删除重复依赖

4. 尽可能地优化 deprecated class and method

优化过后将完全消除打包构建时黄色警告⚠️
pull/2395/head
Freeman Lau 3 years ago
parent 2cda113014
commit 3c67351907

@ -16,14 +16,14 @@
package com.alibaba.cloud.examples;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.DubboReference;
/**
* @author fangjian
*/
public class FooServiceConsumer {
@Reference(version = "${foo.service.version}",
@DubboReference(version = "${foo.service.version}",
application = "${dubbo.application.id}",
url = "dubbo://localhost:12345?version=1.0.0", timeout = 30000)
private FooService fooService;

@ -16,12 +16,12 @@
package com.alibaba.cloud.examples;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.config.annotation.DubboService;
/**
* @author fangjian
*/
@Service(version = "${foo.service.version}", application = "${dubbo.application.id}",
@DubboService(version = "${foo.service.version}", application = "${dubbo.application.id}",
protocol = "${dubbo.protocol.id}", registry = "${dubbo.registry.id}")
public class FooServiceImpl implements FooService {

@ -17,14 +17,16 @@
package com.alibaba.cloud.examples;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @author lengleng
*/
@EnableFeignClients
@SpringCloudApplication
@SpringBootApplication
@EnableDiscoveryClient
public class ConsumerApplication {
public static void main(String[] args) {

@ -47,7 +47,6 @@ import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestTemplate;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
/**
@ -247,7 +246,7 @@ public class DubboSpringCloudConsumerBootstrap {
@PostMapping("/params")
String params(@RequestParam("b") String paramB, @RequestParam("a") int paramA);
@PostMapping(value = "/request/body/map", produces = APPLICATION_JSON_UTF8_VALUE)
@PostMapping(value = "/request/body/map", produces = APPLICATION_JSON_VALUE)
User requestBody(@RequestParam("param") String param,
@RequestBody Map<String, Object> data);

@ -85,7 +85,7 @@ public class SpringRestService implements RestService {
@Override
@PostMapping(value = "/request/body/map",
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
produces = MediaType.APPLICATION_JSON_VALUE)
public User requestBodyMap(@RequestBody Map<String, Object> data,
@RequestParam("param") String param) {
User user = new User();
@ -97,7 +97,7 @@ public class SpringRestService implements RestService {
}
@PostMapping(value = "/request/body/user",
consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
consumes = MediaType.APPLICATION_JSON_VALUE)
@Override
public Map<String, Object> requestBodyUser(@RequestBody User user) {
Map<String, Object> map = new HashMap<>();

@ -33,7 +33,7 @@ public class UserRemoteApplicationEvent extends RemoteApplicationEvent {
public UserRemoteApplicationEvent(Object source, User user, String originService,
String destinationService) {
super(source, originService, destinationService);
super(source, originService, DEFAULT_DESTINATION_FACTORY.getDestination(originService));
this.user = user;
}

@ -27,12 +27,6 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
@ -105,32 +99,6 @@
<optional>true</optional>
</dependency>
<!--spring boot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

@ -19,6 +19,7 @@ package com.alibaba.cloud.sentinel.datasource;
import java.util.Arrays;
import java.util.Optional;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.cloud.sentinel.datasource.config.AbstractDataSourceProperties;
import com.alibaba.csp.sentinel.slots.block.AbstractRule;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
@ -27,8 +28,6 @@ import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
import com.alibaba.csp.sentinel.slots.system.SystemRule;
import org.springframework.util.StringUtils;
/**
* Enum for {@link AbstractRule} class, using in
* {@link AbstractDataSourceProperties#ruleType}.

@ -16,9 +16,9 @@
package com.alibaba.cloud.sentinel.datasource.config;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.cloud.sentinel.datasource.factorybean.ConsulDataSourceFactoryBean;
import org.springframework.util.StringUtils;
/**
* Consul Properties class Using by {@link DataSourcePropertiesConfiguration} and

@ -18,10 +18,9 @@ package com.alibaba.cloud.sentinel.datasource.config;
import javax.validation.constraints.NotEmpty;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean;
import org.springframework.util.StringUtils;
/**
* Nacos Properties class Using by {@link DataSourcePropertiesConfiguration} and
* {@link NacosDataSourceFactoryBean}.

@ -19,9 +19,9 @@ package com.alibaba.cloud.sentinel.datasource.config;
import java.time.Duration;
import java.util.List;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.cloud.sentinel.datasource.factorybean.RedisDataSourceFactoryBean;
import org.springframework.util.StringUtils;
/**
* Redis Properties class Using by {@link DataSourcePropertiesConfiguration} and

@ -16,9 +16,9 @@
package com.alibaba.cloud.sentinel.datasource.config;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.cloud.sentinel.datasource.factorybean.ZookeeperDataSourceFactoryBean;
import org.springframework.util.StringUtils;
/**
* Zookeeper Properties class Using by {@link DataSourcePropertiesConfiguration} and

@ -24,6 +24,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
@ -35,8 +36,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
/**
* Convert sentinel rules for json or xml array Using strict mode to parse json or xml.
*

@ -18,12 +18,12 @@ package com.alibaba.cloud.sentinel.datasource.factorybean;
import java.util.Properties;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
import com.alibaba.nacos.api.PropertyKeyConst;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.util.StringUtils;
/**
* A {@link FactoryBean} for creating {@link NacosDataSource} instance.

@ -17,6 +17,7 @@
package com.alibaba.cloud.sentinel.datasource;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
import com.alibaba.cloud.commons.io.FileUtils;
@ -107,7 +108,7 @@ public class SentinelConverterTests {
private String readFileContent(String file) {
try {
return FileUtils.readFileToString(
ResourceUtils.getFile(StringUtils.trimAllWhitespace(file)));
ResourceUtils.getFile(StringUtils.trimAllWhitespace(file)), Charset.defaultCharset());
}
catch (IOException e) {
return "";

@ -109,7 +109,7 @@ public class SentinelGatewayAutoConfiguration {
ApiPredicateGroupItem.class);
SimpleModule module = new SimpleModule(
"PolymorphicApiPredicateItemDeserializerModule",
new Version(1, 0, 0, null));
new Version(1, 0, 0, null, null, null));
module.addDeserializer(ApiPredicateItem.class, deserializer);
objectMapper.registerModule(module);
}
@ -142,7 +142,7 @@ public class SentinelGatewayAutoConfiguration {
ApiPredicateGroupItem.class);
SimpleModule module = new SimpleModule(
"PolymorphicGatewayDeserializerModule",
new Version(1, 0, 0, null));
new Version(1, 0, 0, null, null, null));
module.addDeserializer(ApiPredicateItem.class, deserializer);
xmlMapper.registerModule(module);
}

@ -26,13 +26,6 @@
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>

@ -18,7 +18,6 @@ package com.alibaba.cloud.nacos;
import com.alibaba.cloud.nacos.refresh.NacosContextRefresher;
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
import com.alibaba.cloud.nacos.refresh.NacosRefreshProperties;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@ -47,11 +46,6 @@ public class NacosConfigAutoConfiguration {
return new NacosConfigProperties();
}
@Bean
public NacosRefreshProperties nacosRefreshProperties() {
return new NacosRefreshProperties();
}
@Bean
public NacosRefreshHistory nacosRefreshHistory() {
return new NacosRefreshHistory();

@ -30,6 +30,7 @@ import java.util.stream.Stream;
import javax.annotation.PostConstruct;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.spring.util.PropertySourcesUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.slf4j.Logger;
@ -40,7 +41,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;

@ -24,11 +24,11 @@ import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
import com.alibaba.cloud.nacos.parser.NacosDataParserHandler;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.PropertySource;
import org.springframework.util.StringUtils;
/**
* @author xiaojing

@ -24,6 +24,7 @@ import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
import com.alibaba.cloud.nacos.parser.NacosDataParserHandler;
import com.alibaba.cloud.nacos.refresh.NacosContextRefresher;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -33,7 +34,6 @@ import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
* @author xiaojing

@ -25,10 +25,11 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.alibaba.nacos.common.utils.StringUtils;
import org.springframework.boot.env.PropertySourceLoader;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.util.StringUtils;
/**
* Nacos-specific loader, If need to support other methods of parsing,you need to do the

@ -65,10 +65,10 @@ public final class NacosDataParserHandler {
*/
public List<PropertySource<?>> parseNacosData(String configName, String configValue,
String extension) throws IOException {
if (StringUtils.isEmpty(configValue)) {
if (!StringUtils.hasLength(configValue)) {
return Collections.emptyList();
}
if (StringUtils.isEmpty(extension)) {
if (!StringUtils.hasLength(extension)) {
extension = this.getFileExtension(configName);
}
for (PropertySourceLoader propertySourceLoader : propertySourceLoaders) {
@ -130,7 +130,7 @@ public final class NacosDataParserHandler {
* @return file extension, default {@code DEFAULT_EXTENSION} if don't get
*/
public String getFileExtension(String name) {
if (StringUtils.isEmpty(name)) {
if (!StringUtils.hasLength(name)) {
return DEFAULT_EXTENSION;
}
int idx = name.lastIndexOf(DOT);
@ -141,10 +141,10 @@ public final class NacosDataParserHandler {
}
private String getFileName(String name, String extension) {
if (StringUtils.isEmpty(extension)) {
if (!StringUtils.hasLength(extension)) {
return name;
}
if (StringUtils.isEmpty(name)) {
if (!StringUtils.hasLength(name)) {
return extension;
}
int idx = name.lastIndexOf(DOT);

@ -25,6 +25,7 @@ import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import com.alibaba.nacos.common.utils.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@ -35,7 +36,6 @@ import org.springframework.boot.env.PropertiesPropertySourceLoader;
import org.springframework.core.Ordered;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.util.StringUtils;
/**
* Parsing for XML requires overwriting the default

@ -45,6 +45,7 @@ import org.springframework.context.ApplicationListener;
*
* @author juven.xuxb
* @author pbting
* @author freeman
*/
public class NacosContextRefresher
implements ApplicationListener<ApplicationReadyEvent>, ApplicationContextAware {
@ -76,21 +77,6 @@ public class NacosContextRefresher
this.isRefreshEnabled = this.nacosConfigProperties.isRefreshEnabled();
}
/**
* recommend to use
* {@link NacosContextRefresher#NacosContextRefresher(NacosConfigManager, NacosRefreshHistory)}.
* @param refreshProperties refreshProperties
* @param refreshHistory refreshHistory
* @param configService configService
*/
@Deprecated
public NacosContextRefresher(NacosRefreshProperties refreshProperties,
NacosRefreshHistory refreshHistory, ConfigService configService) {
this.isRefreshEnabled = refreshProperties.isEnabled();
this.nacosRefreshHistory = refreshHistory;
this.configService = configService;
}
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
// many Spring context

@ -26,10 +26,10 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.Map;
import com.alibaba.nacos.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
public class NacosRefreshHistory {

@ -1,46 +0,0 @@
/*
* Copyright 2013-2018 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.nacos.refresh;
import com.alibaba.cloud.nacos.NacosConfigProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* @author xiaojing
*/
@Deprecated
@Component
public class NacosRefreshProperties {
/**
* recommend to use {@code NacosConfigProperties#refreshEnabled}
* {@link NacosConfigProperties#setRefreshEnabled(boolean)}.
*/
@Value("${spring.cloud.nacos.config.refresh.enabled:true}")
private boolean enabled = true;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

@ -16,6 +16,7 @@
package com.alibaba.cloud.nacos.registry;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.cloud.nacos.event.NacosDiscoveryInfoChangedEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -26,7 +27,6 @@ import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import org.springframework.context.event.EventListener;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* @author xiaojing

@ -80,7 +80,7 @@ public class NacosRegistration implements Registration, ServiceInstance {
Environment env = context.getEnvironment();
String endpointBasePath = env.getProperty(MANAGEMENT_ENDPOINT_BASE_PATH);
if (!StringUtils.isEmpty(endpointBasePath)) {
if (StringUtils.hasLength(endpointBasePath)) {
metadata.put(MANAGEMENT_ENDPOINT_BASE_PATH, endpointBasePath);
}
@ -90,10 +90,10 @@ public class NacosRegistration implements Registration, ServiceInstance {
String contextPath = env
.getProperty("management.server.servlet.context-path");
String address = env.getProperty("management.server.address");
if (!StringUtils.isEmpty(contextPath)) {
if (StringUtils.hasLength(contextPath)) {
metadata.put(MANAGEMENT_CONTEXT_PATH, contextPath);
}
if (!StringUtils.isEmpty(address)) {
if (StringUtils.hasLength(address)) {
metadata.put(MANAGEMENT_ADDRESS, address);
}
}

@ -19,6 +19,7 @@ package com.alibaba.cloud.nacos.registry;
import java.util.List;
import java.util.Properties;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.NacosServiceManager;
import com.alibaba.nacos.api.exception.NacosException;
@ -30,7 +31,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import org.springframework.util.StringUtils;
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;

@ -23,13 +23,13 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.cloud.commons.lang.StringUtils;
import feign.Client;
import feign.Request;
import feign.Response;
import io.seata.core.context.RootContext;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.util.StringUtils;
/**
* @author xiaojing
@ -74,8 +74,8 @@ public class SeataFeignClient implements Client {
seataXid.add(xid);
headers.put(RootContext.KEY_XID, seataXid);
return Request.create(request.method(), request.url(), headers, request.body(),
request.charset());
return Request.create(request.httpMethod(), request.url(), headers, request.body(),
request.charset(), null);
}
}

@ -39,7 +39,7 @@ public class SeataRestTemplateInterceptor implements ClientHttpRequestIntercepto
String xid = RootContext.getXID();
if (!StringUtils.isEmpty(xid)) {
if (StringUtils.hasLength(xid)) {
requestWrapper.getHeaders().add(RootContext.KEY_XID, xid);
}
return clientHttpRequestExecution.execute(requestWrapper, bytes);

@ -18,6 +18,7 @@ package com.alibaba.cloud.sentinel.custom;
import javax.annotation.PostConstruct;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.cloud.sentinel.SentinelProperties;
import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter;
import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter;
@ -46,7 +47,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import static com.alibaba.cloud.sentinel.SentinelConstants.BLOCK_PAGE_URL_CONF_KEY;
import static com.alibaba.csp.sentinel.config.SentinelConfig.setConfig;
@ -70,7 +70,7 @@ public class SentinelAutoConfiguration {
@PostConstruct
private void init() {
if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_DIR))
&& StringUtils.hasText(properties.getLog().getDir())) {
&& StringUtils.isNotBlank(properties.getLog().getDir())) {
System.setProperty(LogBase.LOG_DIR, properties.getLog().getDir());
}
if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_NAME_USE_PID))
@ -79,53 +79,53 @@ public class SentinelAutoConfiguration {
String.valueOf(properties.getLog().isSwitchPid()));
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.APP_NAME_PROP_KEY))
&& StringUtils.hasText(projectName)) {
&& StringUtils.isNotBlank(projectName)) {
System.setProperty(SentinelConfig.APP_NAME_PROP_KEY, projectName);
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))
&& StringUtils.hasText(properties.getTransport().getPort())) {
&& StringUtils.isNotBlank(properties.getTransport().getPort())) {
System.setProperty(TransportConfig.SERVER_PORT,
properties.getTransport().getPort());
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.CONSOLE_SERVER))
&& StringUtils.hasText(properties.getTransport().getDashboard())) {
&& StringUtils.isNotBlank(properties.getTransport().getDashboard())) {
System.setProperty(TransportConfig.CONSOLE_SERVER,
properties.getTransport().getDashboard());
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS))
&& StringUtils
.hasText(properties.getTransport().getHeartbeatIntervalMs())) {
.isNotBlank(properties.getTransport().getHeartbeatIntervalMs())) {
System.setProperty(TransportConfig.HEARTBEAT_INTERVAL_MS,
properties.getTransport().getHeartbeatIntervalMs());
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_CLIENT_IP))
&& StringUtils.hasText(properties.getTransport().getClientIp())) {
&& StringUtils.isNotBlank(properties.getTransport().getClientIp())) {
System.setProperty(TransportConfig.HEARTBEAT_CLIENT_IP,
properties.getTransport().getClientIp());
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.CHARSET))
&& StringUtils.hasText(properties.getMetric().getCharset())) {
&& StringUtils.isNotBlank(properties.getMetric().getCharset())) {
System.setProperty(SentinelConfig.CHARSET,
properties.getMetric().getCharset());
}
if (StringUtils
.isEmpty(System.getProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE))
&& StringUtils.hasText(properties.getMetric().getFileSingleSize())) {
&& StringUtils.isNotBlank(properties.getMetric().getFileSingleSize())) {
System.setProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE,
properties.getMetric().getFileSingleSize());
}
if (StringUtils
.isEmpty(System.getProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT))
&& StringUtils.hasText(properties.getMetric().getFileTotalCount())) {
&& StringUtils.isNotBlank(properties.getMetric().getFileTotalCount())) {
System.setProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT,
properties.getMetric().getFileTotalCount());
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.COLD_FACTOR))
&& StringUtils.hasText(properties.getFlow().getColdFactor())) {
&& StringUtils.isNotBlank(properties.getFlow().getColdFactor())) {
System.setProperty(SentinelConfig.COLD_FACTOR,
properties.getFlow().getColdFactor());
}
if (StringUtils.hasText(properties.getBlockPage())) {
if (StringUtils.isNotBlank(properties.getBlockPage())) {
setConfig(BLOCK_PAGE_URL_CONF_KEY, properties.getBlockPage());
}

@ -98,17 +98,17 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
private void checkBlock4RestTemplate(Class<?> blockClass, String blockMethod,
String beanName, String type) {
if (blockClass == void.class && StringUtils.isEmpty(blockMethod)) {
if (blockClass == void.class && !StringUtils.hasLength(blockMethod)) {
return;
}
if (blockClass != void.class && StringUtils.isEmpty(blockMethod)) {
if (blockClass != void.class && !StringUtils.hasLength(blockMethod)) {
log.error(
"{} class attribute exists but {} method attribute is not exists in bean[{}]",
type, type, beanName);
throw new IllegalArgumentException(type + " class attribute exists but "
+ type + " method attribute is not exists in bean[" + beanName + "]");
}
else if (blockClass == void.class && !StringUtils.isEmpty(blockMethod)) {
else if (blockClass == void.class && StringUtils.hasLength(blockMethod)) {
log.error(
"{} method attribute exists but {} class attribute is not exists in bean[{}]",
type, type, beanName);

@ -135,8 +135,8 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton {
String dataType = StringUtils.trimAllWhitespace(propertyValue.toString());
if (CUSTOM_DATA_TYPE.equals(dataType)) {
try {
if (StringUtils
.isEmpty(dataSourceProperties.getConverterClass())) {
if (!StringUtils
.hasLength(dataSourceProperties.getConverterClass())) {
throw new RuntimeException("[Sentinel Starter] DataSource "
+ dataSourceName
+ "dataType is custom, please set converter-class "

@ -72,7 +72,7 @@ public class SentinelClientHttpResponse extends AbstractClientHttpResponse {
public HttpHeaders getHeaders() {
Map<String, List<String>> headers = new HashMap<>();
headers.put(HttpHeaders.CONTENT_TYPE,
Arrays.asList(MediaType.APPLICATION_JSON_UTF8_VALUE));
Arrays.asList(MediaType.APPLICATION_JSON_VALUE));
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.putAll(headers);
return httpHeaders;

@ -105,11 +105,11 @@ public class SidecarConsulAutoRegistration extends ConsulAutoRegistration {
}
// add metadata from other properties. See createTags above.
if (!StringUtils.isEmpty(properties.getInstanceZone())) {
if (StringUtils.hasLength(properties.getInstanceZone())) {
metadata.put(properties.getDefaultZoneMetadataName(),
properties.getInstanceZone());
}
if (!StringUtils.isEmpty(properties.getInstanceGroup())) {
if (StringUtils.hasLength(properties.getInstanceGroup())) {
metadata.put("group", properties.getInstanceGroup());
}

@ -22,7 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
/**
* Dubbo exported URLs.
@ -36,7 +36,7 @@ public class DubboExportedURLsEndpoint {
@Autowired
private DubboMetadataService dubboMetadataService;
@ReadOperation(produces = APPLICATION_JSON_UTF8_VALUE)
@ReadOperation(produces = APPLICATION_JSON_VALUE)
public Object get() {
return dubboMetadataService.getAllExportedURLs();
}

@ -22,7 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
/**
* Dubbo Rest Metadata {@link Endpoint}.
@ -35,7 +35,7 @@ public class DubboRestMetadataEndpoint {
@Autowired
private DubboMetadataService dubboMetadataService;
@ReadOperation(produces = APPLICATION_JSON_UTF8_VALUE)
@ReadOperation(produces = APPLICATION_JSON_VALUE)
public String get() {
return dubboMetadataService.getServiceRestMetadata();
}

@ -22,7 +22,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.rpc.ExporterListener;
import org.apache.dubbo.rpc.Filter;
@ -80,7 +79,7 @@ public @interface DubboTransported {
* Whether to reconnect if connection is lost, if not specify, reconnect is enabled by
* default, and the interval for retry connecting is 2000 ms.
*
* @see Reference#reconnect()
* @see org.apache.dubbo.config.annotation.DubboReference#reconnect()
* @return reconnect time
*/
String reconnect() default "${dubbo.transport.reconnect:2000}";
@ -89,7 +88,7 @@ public @interface DubboTransported {
* Maximum connections service provider can accept, default value is 0 - connection is
* shared.
*
* @see Reference#connections()
* @see org.apache.dubbo.config.annotation.DubboReference#connections()
* @return maximum connections
*/
int connections() default 0;
@ -97,7 +96,7 @@ public @interface DubboTransported {
/**
* Service invocation retry times.
*
* @see Reference#retries()
* @see org.apache.dubbo.config.annotation.DubboReference#retries()
* @return retry times
*/
int retries() default DEFAULT_RETRIES;
@ -105,7 +104,7 @@ public @interface DubboTransported {
/**
* Load balance strategy, legal values include: random, roundrobin, leastactive.
*
* @see Reference#loadbalance()
* @see org.apache.dubbo.config.annotation.DubboReference#loadbalance()
* @return load balance strategy
*/
String loadbalance() default "${dubbo.transport.loadbalance:}";
@ -113,7 +112,7 @@ public @interface DubboTransported {
/**
* Maximum active requests allowed, default value is 0.
*
* @see Reference#actives()
* @see org.apache.dubbo.config.annotation.DubboReference#actives()
* @return maximum active requests
*/
int actives() default 0;
@ -121,7 +120,7 @@ public @interface DubboTransported {
/**
* Timeout value for service invocation, default value is 0.
*
* @see Reference#timeout()
* @see org.apache.dubbo.config.annotation.DubboReference#timeout()
* @return timeout for service invocation
*/
int timeout() default 0;
@ -130,7 +129,7 @@ public @interface DubboTransported {
* Specify cache implementation for service invocation, legal values include: lru,
* threadlocal, jcache.
*
* @see Reference#cache()
* @see org.apache.dubbo.config.annotation.DubboReference#cache()
* @return specify cache implementation for service invocation
*/
String cache() default "${dubbo.transport.cache:}";
@ -139,7 +138,7 @@ public @interface DubboTransported {
* Filters for service invocation.
*
* @see Filter
* @see Reference#filter()
* @see org.apache.dubbo.config.annotation.DubboReference#filter()
* @return filters for service invocation
*/
String[] filter() default {};
@ -148,7 +147,7 @@ public @interface DubboTransported {
* Listeners for service exporting and unexporting.
*
* @see ExporterListener
* @see Reference#listener()
* @see org.apache.dubbo.config.annotation.DubboReference#listener()
* @return listener
*/
String[] listener() default {};
@ -156,7 +155,7 @@ public @interface DubboTransported {
/**
* Customized parameter key-value pair, for example: {key1, value1, key2, value2}.
*
* @see Reference#parameters()
* @see org.apache.dubbo.config.annotation.DubboReference#parameters()
* @return parameters
*/
String[] parameters() default {};

@ -18,7 +18,7 @@ package com.alibaba.cloud.dubbo.autoconfigure.condition;
import java.util.Map;
import com.alibaba.cloud.dubbo.registry.SpringCloudRegistry;
import com.alibaba.cloud.dubbo.registry.DubboCloudRegistry;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
@ -32,10 +32,10 @@ import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.PROTOC
import static com.alibaba.spring.util.PropertySourcesUtils.getSubProperties;
/**
* Missing {@link SpringCloudRegistry} Property {@link Condition}.
* Missing {@link DubboCloudRegistry} Property {@link Condition}.
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see SpringCloudRegistry
* @see DubboCloudRegistry
* @see Condition
*/
public class MissingSpringCloudRegistryConfigPropertyCondition

@ -37,7 +37,7 @@ import static com.alibaba.cloud.dubbo.util.DubboCloudConstants.SPRING_CLOUD_REGI
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see RegistryFactory
* @see SpringCloudRegistry
* @see DubboCloudRegistry
*/
public class SpringCloudRegistryFactory extends AbstractRegistryFactory {

@ -99,7 +99,7 @@ public class DubboGenericServiceFactory {
return cache.computeIfAbsent(key, k -> {
ReferenceBean<GenericService> referenceBean = new ReferenceBean<>();
referenceBean.setGeneric(true);
referenceBean.setGeneric(Boolean.TRUE.toString());
referenceBean.setInterface(interfaceName);
referenceBean.setVersion(version);
referenceBean.setGroup(group);

@ -22,7 +22,6 @@ import java.util.Set;
import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.annotation.Service;
/**
* Dubbo Metadata Service is a core interface for service subscribers, it must keep the
@ -64,8 +63,8 @@ public interface DubboMetadataService {
* Get the json content of an exported List of {@link URL URLs} by the
* serviceInterface, group and version.
* @param serviceInterface The class name of service interface
* @param group {@link Service#group() the service group} (optional)
* @param version {@link Service#version() the service version} (optional)~
* @param group {@link org.apache.dubbo.config.annotation.DubboService#group() the service group} (optional)
* @param version {@link org.apache.dubbo.config.annotation.DubboService#version() the service version} (optional)
* @return non-null read-only {@link List}
* @see URL
*/

@ -108,7 +108,7 @@ public class RequestBodyServiceParameterResolver
}
catch (IOException e) {
throw new HttpMessageNotReadableException(
"I/O error while reading input message", e);
"I/O error while reading input message", e, null);
}
}

@ -20,10 +20,10 @@ import java.util.Arrays;
import java.util.List;
import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.spring.autoconfigure.RocketMQProperties;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>

@ -61,6 +61,7 @@ import org.springframework.integration.core.MessageProducer;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
@ -101,8 +102,8 @@ public class RocketMQMessageChannelBinder extends
// if producerGroup is empty, using destination
String extendedProducerGroup = producerProperties.getExtension().getGroup();
String producerGroup = StringUtils.isEmpty(extendedProducerGroup)
? destination.getName() : extendedProducerGroup;
String producerGroup = StringUtils.hasLength(extendedProducerGroup)
? extendedProducerGroup : destination.getName();
RocketMQBinderConfigurationProperties mergedProperties = RocketMQBinderUtils
.mergeProperties(rocketBinderConfigurationProperties,
@ -129,7 +130,7 @@ public class RocketMQMessageChannelBinder extends
DefaultMQProducer producer;
String ak = mergedProperties.getAccessKey();
String sk = mergedProperties.getSecretKey();
if (!StringUtils.isEmpty(ak) && !StringUtils.isEmpty(sk)) {
if (StringUtils.hasLength(ak) && StringUtils.hasLength(sk)) {
RPCHook rpcHook = new AclClientRPCHook(
new SessionCredentials(ak, sk));
producer = new DefaultMQProducer(producerGroup, rpcHook,
@ -318,7 +319,7 @@ public class RocketMQMessageChannelBinder extends
.getBeansOfType(ObjectMapper.class).values().iterator().next();
JacksonRocketMQHeaderMapper headerMapper = new JacksonRocketMQHeaderMapper(
objectMapper);
if (!StringUtils.isEmpty(trustedPackages)) {
if (!CollectionUtils.isEmpty(trustedPackages)) {
headerMapper.addTrustedPackages(trustedPackages);
}
return headerMapper;

@ -59,7 +59,7 @@ public class RocketMQComponent4BinderAutoConfiguration {
"${spring.cloud.stream.rocketmq.binder.access-key:${rocketmq.producer.access-key:}}");
String sk = environment.resolveRequiredPlaceholders(
"${spring.cloud.stream.rocketmq.binder.secret-key:${rocketmq.producer.secret-key:}}");
if (!StringUtils.isEmpty(ak) && !StringUtils.isEmpty(sk)) {
if (StringUtils.hasLength(ak) && StringUtils.hasLength(sk)) {
producer = new DefaultMQProducer(RocketMQBinderConstants.DEFAULT_GROUP,
new AclClientRPCHook(new SessionCredentials(ak, sk)));
producer.setVipChannelEnabled(false);
@ -67,7 +67,7 @@ public class RocketMQComponent4BinderAutoConfiguration {
else {
producer = new DefaultMQProducer(RocketMQBinderConstants.DEFAULT_GROUP);
}
if (StringUtils.isEmpty(configNameServer)) {
if (!StringUtils.hasLength(configNameServer)) {
configNameServer = RocketMQBinderConstants.DEFAULT_NAME_SERVER;
}
producer.setNamesrvAddr(configNameServer);

@ -126,7 +126,7 @@ public class RocketMQListenerBindingContainer
this.rocketMQMessageChannelBinder = rocketMQMessageChannelBinder;
this.consumeMode = rocketMQConsumerProperties.getExtension().getOrderly()
? ConsumeMode.ORDERLY : ConsumeMode.CONCURRENTLY;
if (StringUtils.isEmpty(rocketMQConsumerProperties.getExtension().getSql())) {
if (!StringUtils.hasLength(rocketMQConsumerProperties.getExtension().getSql())) {
this.selectorType = SelectorType.TAG;
this.selectorExpression = rocketMQConsumerProperties.getExtension().getTags();
}
@ -218,7 +218,7 @@ public class RocketMQListenerBindingContainer
String ak = rocketBinderConfigurationProperties.getAccessKey();
String sk = rocketBinderConfigurationProperties.getSecretKey();
if (!StringUtils.isEmpty(ak) && !StringUtils.isEmpty(sk)) {
if (StringUtils.hasLength(ak) && StringUtils.hasLength(sk)) {
RPCHook rpcHook = new AclClientRPCHook(new SessionCredentials(ak, sk));
consumer = new DefaultMQPushConsumer(consumerGroup, rpcHook,
new AllocateMessageQueueAveragely(),

@ -164,7 +164,7 @@ public class RocketMQMessageHandler extends AbstractMessageHandler implements Li
String tags = Optional
.ofNullable(message.getHeaders().get(RocketMQHeaders.TAGS)).orElse("")
.toString();
if (!StringUtils.isEmpty(tags)) {
if (StringUtils.hasLength(tags)) {
topicWithTags.append(":").append(tags);
}

@ -113,13 +113,13 @@ public class RocketMQMessageSource extends AbstractMessageSource<Object>
String tags = rocketMQConsumerProperties.getExtension().getTags();
String sql = rocketMQConsumerProperties.getExtension().getSql();
if (!StringUtils.isEmpty(tags) && !StringUtils.isEmpty(sql)) {
if (StringUtils.hasLength(tags) && StringUtils.hasLength(sql)) {
messageSelector = MessageSelector.byTag(tags);
}
else if (!StringUtils.isEmpty(tags)) {
else if (StringUtils.hasLength(tags)) {
messageSelector = MessageSelector.byTag(tags);
}
else if (!StringUtils.isEmpty(sql)) {
else if (StringUtils.hasLength(sql)) {
messageSelector = MessageSelector.bySql(sql);
}

@ -20,6 +20,7 @@ import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
@ -33,7 +34,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.ClassUtils;
@ -110,7 +110,7 @@ public class JacksonRocketMQHeaderMapper extends AbstractRocketMQHeaderMapper {
final Map<String, String> jsonTypes = decodeJsonTypes(source);
source.forEach((key, value) -> {
if (matches(key) && !(key.equals(JSON_TYPES))) {
if (jsonTypes != null && jsonTypes.containsKey(key)) {
if (jsonTypes.containsKey(key)) {
Class<?> type = Object.class;
String requestedType = jsonTypes.get(key);
boolean trusted = trusted(requestedType);
@ -205,7 +205,6 @@ public class JacksonRocketMQHeaderMapper extends AbstractRocketMQHeaderMapper {
return value;
}
@Nullable
private Map<String, String> decodeJsonTypes(Map<String, String> source) {
if (source.containsKey(JSON_TYPES)) {
String value = source.get(JSON_TYPES);
@ -218,7 +217,7 @@ public class JacksonRocketMQHeaderMapper extends AbstractRocketMQHeaderMapper {
log.error("Could not decode json types: " + value, e);
}
}
return null;
return Collections.emptyMap();
}
protected boolean trusted(String requestedType) {

Loading…
Cancel
Save