This is an automated email from the ASF dual-hosted git repository.

likeguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 96b1ca31ac [type:refactor] Optimize code for shenyu-sdk (#5874)
96b1ca31ac is described below

commit 96b1ca31ac4e0059748ad73dad252bf439ab4ed4
Author: po-168 <[email protected]>
AuthorDate: Thu Jan 2 20:41:11 2025 +0800

    [type:refactor] Optimize code for shenyu-sdk (#5874)
    
    * [type:refactor] Optimize code for shenyu-sdk
    
    * [type:refactor] Optimize code for shenyu-sdk
    
    ---------
    
    Co-authored-by: aias00 <[email protected]>
    Co-authored-by: likeguo <[email protected]>
---
 .../shenyu/sdk/feign/ShenyuClientCapability.java   |  6 ++-
 .../shenyu/sdk/feign/ShenyuClientsRegistrar.java   | 23 +++++------
 .../shenyu/sdk/okhttp/OkHttpShenyuSdkClient.java   |  5 ++-
 .../sdk/spring/NoFallbackAvailableException.java   |  2 +
 .../shenyu/sdk/spring/ShenyuClientsRegistrar.java  | 44 +++++++++++-----------
 .../annotation/CookieValueParameterProcessor.java  | 14 ++++---
 .../annotation/PathVariableParameterProcessor.java |  9 +++--
 .../annotation/RequestParamParameterProcessor.java |  5 ++-
 .../apache/shenyu/sdk/spring/factory/Contract.java |  3 +-
 .../proxy/ShenyuClientInvocationHandler.java       |  3 +-
 .../spring/proxy/ShenyuClientMethodHandler.java    |  3 +-
 .../sdk/spring/support/SpringMvcContract.java      | 19 +++++-----
 12 files changed, 77 insertions(+), 59 deletions(-)

diff --git 
a/shenyu-sdk/shenyu-sdk-feign/src/main/java/org/apache/shenyu/sdk/feign/ShenyuClientCapability.java
 
b/shenyu-sdk/shenyu-sdk-feign/src/main/java/org/apache/shenyu/sdk/feign/ShenyuClientCapability.java
index 2d490d48e2..20f5d3f29c 100644
--- 
a/shenyu-sdk/shenyu-sdk-feign/src/main/java/org/apache/shenyu/sdk/feign/ShenyuClientCapability.java
+++ 
b/shenyu-sdk/shenyu-sdk-feign/src/main/java/org/apache/shenyu/sdk/feign/ShenyuClientCapability.java
@@ -20,7 +20,6 @@ package org.apache.shenyu.sdk.feign;
 import feign.Capability;
 import feign.Client;
 import feign.Request;
-import java.net.URI;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.BeanFactory;
@@ -30,6 +29,9 @@ import 
org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalance
 import 
org.springframework.cloud.openfeign.loadbalancer.RetryableFeignBlockingLoadBalancerClient;
 import org.springframework.util.Assert;
 
+import java.net.URI;
+import java.util.Objects;
+
 /**
  * custom a shenyu client capability to enrich clients.
  */
@@ -51,7 +53,7 @@ public final class ShenyuClientCapability implements 
Capability {
             Client delegate = finalDelegate;
             final URI originalUri = URI.create(request.url());
             String serviceId = originalUri.getHost();
-            Assert.state(serviceId != null, "Request URI does not contain a 
valid hostname: " + originalUri);
+            Assert.state(Objects.nonNull(serviceId), "Request URI does not 
contain a valid hostname: " + originalUri);
             if (finalDelegate instanceof FeignBlockingLoadBalancerClient) {
                 delegate = ((FeignBlockingLoadBalancerClient) 
finalDelegate).getDelegate();
             } else if (finalDelegate instanceof 
RetryableFeignBlockingLoadBalancerClient) {
diff --git 
a/shenyu-sdk/shenyu-sdk-feign/src/main/java/org/apache/shenyu/sdk/feign/ShenyuClientsRegistrar.java
 
b/shenyu-sdk/shenyu-sdk-feign/src/main/java/org/apache/shenyu/sdk/feign/ShenyuClientsRegistrar.java
index 3c8686d49e..f539d6103f 100644
--- 
a/shenyu-sdk/shenyu-sdk-feign/src/main/java/org/apache/shenyu/sdk/feign/ShenyuClientsRegistrar.java
+++ 
b/shenyu-sdk/shenyu-sdk-feign/src/main/java/org/apache/shenyu/sdk/feign/ShenyuClientsRegistrar.java
@@ -17,6 +17,7 @@
 
 package org.apache.shenyu.sdk.feign;
 
+import org.apache.commons.collections4.MapUtils;
 import org.apache.shenyu.common.utils.JsonUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -111,7 +112,7 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
     private void registerDefaultConfiguration(final AnnotationMetadata 
metadata, final BeanDefinitionRegistry registry) {
         Map<String, Object> defaultAttrs = 
metadata.getAnnotationAttributes(EnableShenyuClients.class.getName(), true);
 
-        if (defaultAttrs != null && 
defaultAttrs.containsKey("defaultConfiguration")) {
+        if (MapUtils.isNotEmpty(defaultAttrs) && 
defaultAttrs.containsKey("defaultConfiguration")) {
             String name;
             if (metadata.hasEnclosingClass()) {
                 name = "default." + metadata.getEnclosingClassName();
@@ -133,7 +134,7 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
         Map<String, Object> attrs = 
metadata.getAnnotationAttributes(EnableShenyuClients.class.getName());
         final Class<?>[] clients = attrs == null ? null : (Class<?>[]) 
attrs.get("clients");
         LOG.info("clients:{}", JsonUtils.toJson(clients));
-        if (clients == null || clients.length == 0) {
+        if (Objects.isNull(clients) || clients.length == 0) {
             ClassPathScanningCandidateComponentProvider scanner = getScanner();
             scanner.setResourceLoader(this.resourceLoader);
             scanner.addIncludeFilter(new 
AnnotationTypeFilter(ShenyuClient.class));
@@ -185,12 +186,12 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
             factoryBean.setPath(getPath(beanFactory, attributes));
             
factoryBean.setDismiss404(Boolean.parseBoolean(String.valueOf(attributes.get("dismiss404"))));
             Object fallback = attributes.get("fallback");
-            if (fallback != null) {
+            if (Objects.nonNull(fallback)) {
                 factoryBean.setFallback(fallback instanceof Class ? (Class<?>) 
fallback
                                             : 
ClassUtils.resolveClassName(fallback.toString(), null));
             }
             Object fallbackFactory = attributes.get("fallbackFactory");
-            if (fallbackFactory != null) {
+            if (Objects.nonNull(fallbackFactory)) {
                 factoryBean.setFallbackFactory(fallbackFactory instanceof 
Class ? (Class<?>) fallbackFactory
                                                    : 
ClassUtils.resolveClassName(fallbackFactory.toString(), null));
             }
@@ -245,16 +246,16 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
 
     private String resolve(final ConfigurableBeanFactory beanFactory, final 
String value) {
         if (StringUtils.hasText(value)) {
-            if (beanFactory == null) {
+            if (Objects.isNull(beanFactory)) {
                 return this.environment.resolvePlaceholders(value);
             }
             BeanExpressionResolver resolver = 
beanFactory.getBeanExpressionResolver();
             String resolved = beanFactory.resolveEmbeddedValue(value);
-            if (resolver == null) {
+            if (Objects.isNull(resolver)) {
                 return resolved;
             }
             Object evaluateValue = resolver.evaluate(resolved, new 
BeanExpressionContext(beanFactory, null));
-            if (evaluateValue != null) {
+            if (Objects.nonNull(evaluateValue)) {
                 return String.valueOf(evaluateValue);
             }
             return null;
@@ -311,7 +312,7 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
     }
 
     private String getQualifier(final Map<String, Object> client) {
-        if (client == null) {
+        if (Objects.isNull(client)) {
             return null;
         }
         String qualifier = (String) client.get("qualifier");
@@ -322,7 +323,7 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
     }
 
     private String[] getQualifiers(final Map<String, Object> client) {
-        if (client == null) {
+        if (Objects.isNull(client)) {
             return null;
         }
         List<String> qualifierList = new ArrayList<>(Arrays.asList((String[]) 
client.get("qualifiers")));
@@ -360,7 +361,7 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
         } catch (URISyntaxException e) {
             host = null;
         }
-        Assert.state(host != null, "Service id not legal hostname (" + name + 
")");
+        Assert.state(Objects.nonNull(host), "Service id not legal hostname (" 
+ name + ")");
         return name;
     }
 
@@ -441,7 +442,7 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
     }
 
     private String getClientName(final Map<String, Object> client) {
-        if (client == null) {
+        if (Objects.isNull(client)) {
             return null;
         }
         String value = (String) client.get("contextId");
diff --git 
a/shenyu-sdk/shenyu-sdk-okhttp/src/main/java/org/apache/shenyu/sdk/okhttp/OkHttpShenyuSdkClient.java
 
b/shenyu-sdk/shenyu-sdk-okhttp/src/main/java/org/apache/shenyu/sdk/okhttp/OkHttpShenyuSdkClient.java
index c78979fec6..f82f58bcab 100644
--- 
a/shenyu-sdk/shenyu-sdk-okhttp/src/main/java/org/apache/shenyu/sdk/okhttp/OkHttpShenyuSdkClient.java
+++ 
b/shenyu-sdk/shenyu-sdk-okhttp/src/main/java/org/apache/shenyu/sdk/okhttp/OkHttpShenyuSdkClient.java
@@ -23,6 +23,7 @@ import okhttp3.OkHttpClient;
 import okhttp3.Request;
 import okhttp3.RequestBody;
 import okhttp3.Response;
+import okhttp3.ResponseBody;
 import okhttp3.internal.Util;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.sdk.core.ShenyuRequest;
@@ -33,6 +34,7 @@ import org.apache.shenyu.spi.Join;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
@@ -103,7 +105,8 @@ public class OkHttpShenyuSdkClient extends 
AbstractShenyuSdkClient {
         try (Response okhttpResponse = okHttpClient
                 .newCall(okhttpRequest)
                 .execute()) {
-            String bodyStr = okhttpResponse.body() == null ? null : 
okhttpResponse.body().string();
+            ResponseBody responseBody = okhttpResponse.body();
+            String bodyStr = Objects.isNull(responseBody) ? null : 
responseBody.string();
             return new ShenyuResponse(okhttpResponse.code(), null,
                     
okhttpResponse.headers().names().stream().collect(Collectors.toMap(name -> 
name, name -> okhttpResponse.headers().values(name))),
                     bodyStr, request);
diff --git 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/NoFallbackAvailableException.java
 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/NoFallbackAvailableException.java
index 60e6b48e4b..0b0d43816b 100644
--- 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/NoFallbackAvailableException.java
+++ 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/NoFallbackAvailableException.java
@@ -19,6 +19,8 @@ package org.apache.shenyu.sdk.spring;
 
 public class NoFallbackAvailableException extends RuntimeException {
 
+    private static final long serialVersionUID = 5196228762350964700L;
+
     public NoFallbackAvailableException(final String message, final Throwable 
cause) {
 
         super(message, cause);
diff --git 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/ShenyuClientsRegistrar.java
 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/ShenyuClientsRegistrar.java
index cbc32c65fc..1a3f577d31 100644
--- 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/ShenyuClientsRegistrar.java
+++ 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/ShenyuClientsRegistrar.java
@@ -17,6 +17,8 @@
 
 package org.apache.shenyu.sdk.spring;
 
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.FactoryBean;
 import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
 import org.springframework.beans.factory.config.BeanDefinition;
@@ -40,7 +42,6 @@ import 
org.springframework.core.type.filter.AnnotationTypeFilter;
 import org.springframework.util.Assert;
 import org.springframework.util.ClassUtils;
 import org.springframework.util.ObjectUtils;
-import org.springframework.util.StringUtils;
 
 import java.net.MalformedURLException;
 import java.net.URI;
@@ -53,6 +54,7 @@ import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
 
@@ -147,12 +149,12 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
             factoryBean.setUrl(getUrl(beanFactory, attributes));
             factoryBean.setPath(getPath(beanFactory, attributes));
             Object fallback = attributes.get("fallback");
-            if (fallback != null) {
+            if (Objects.nonNull(fallback)) {
                 factoryBean.setFallback(fallback instanceof Class ? (Class<?>) 
fallback
                         : ClassUtils.resolveClassName(fallback.toString(), 
null));
             }
             Object fallbackFactory = attributes.get("fallbackFactory");
-            if (fallbackFactory != null) {
+            if (Objects.nonNull(fallbackFactory)) {
                 factoryBean.setFallbackFactory(fallbackFactory instanceof 
Class ? (Class<?>) fallbackFactory
                         : 
ClassUtils.resolveClassName(fallbackFactory.toString(), null));
             }
@@ -189,7 +191,7 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
 
     private String getContextId(final ConfigurableBeanFactory beanFactory, 
final Map<String, Object> attributes) {
         String contextId = (String) attributes.get("contextId");
-        if (!StringUtils.hasText(contextId)) {
+        if (StringUtils.isBlank(contextId)) {
             return getName(attributes);
         }
 
@@ -198,17 +200,17 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
     }
 
     private String resolve(final ConfigurableBeanFactory beanFactory, final 
String value) {
-        if (StringUtils.hasText(value)) {
-            if (beanFactory == null) {
+        if (StringUtils.isNotBlank(value)) {
+            if (Objects.isNull(beanFactory)) {
                 return this.environment.resolvePlaceholders(value);
             }
             String resolved = beanFactory.resolveEmbeddedValue(value);
             BeanExpressionResolver resolver = 
beanFactory.getBeanExpressionResolver();
-            if (resolver == null) {
+            if (Objects.isNull(resolver)) {
                 return resolved;
             }
             Object evaluateValue = resolver.evaluate(resolved, new 
BeanExpressionContext(beanFactory, null));
-            if (evaluateValue != null) {
+            if (Objects.nonNull(evaluateValue)) {
                 return String.valueOf(evaluateValue);
             }
             return null;
@@ -247,12 +249,12 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
 
         Set<String> basePackages = new HashSet<>();
         for (String pkg : (String[]) attributes.get("value")) {
-            if (StringUtils.hasText(pkg)) {
+            if (StringUtils.isNotBlank(pkg)) {
                 basePackages.add(pkg);
             }
         }
         for (String pkg : (String[]) attributes.get("basePackages")) {
-            if (StringUtils.hasText(pkg)) {
+            if (StringUtils.isNotBlank(pkg)) {
                 basePackages.add(pkg);
             }
         }
@@ -267,26 +269,26 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
     }
 
     private String getQualifier(final Map<String, Object> client) {
-        if (client == null) {
+        if (Objects.isNull(client)) {
             return null;
         }
         String qualifier = (String) client.get("qualifier");
-        if (StringUtils.hasText(qualifier)) {
+        if (StringUtils.isNotBlank(qualifier)) {
             return qualifier;
         }
         return null;
     }
 
     private String[] getQualifiers(final Map<String, Object> client) {
-        if (client == null) {
+        if (Objects.isNull(client)) {
             return null;
         }
         List<String> qualifierList = new ArrayList<>(Arrays.asList((String[]) 
client.get("qualifiers")));
-        qualifierList.removeIf(qualifier -> !StringUtils.hasText(qualifier));
-        if (qualifierList.isEmpty() && getQualifier(client) != null) {
+        qualifierList.removeIf(qualifier -> StringUtils.isBlank(qualifier));
+        if (CollectionUtils.isEmpty(qualifierList) && 
StringUtils.isNotBlank(getQualifier(client))) {
             qualifierList = Collections.singletonList(getQualifier(client));
         }
-        return !qualifierList.isEmpty() ? qualifierList.toArray(new String[0]) 
: null;
+        return CollectionUtils.isNotEmpty(qualifierList) ? 
qualifierList.toArray(new String[0]) : null;
     }
 
     @Override
@@ -301,7 +303,7 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
      * @return the name
      */
     static String getName(final String name) {
-        if (!StringUtils.hasText(name)) {
+        if (StringUtils.isBlank(name)) {
             return "";
         }
         String host;
@@ -340,7 +342,7 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
      */
     String getName(final ConfigurableBeanFactory beanFactory, final 
Map<String, Object> attributes) {
         String name = (String) attributes.get("name");
-        if (!StringUtils.hasText(name)) {
+        if (StringUtils.isBlank(name)) {
             name = (String) attributes.get("value");
         }
         name = resolve(beanFactory, name);
@@ -355,7 +357,7 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
      */
     static String getUrl(final String url) {
         String resultUrl = url;
-        if (StringUtils.hasText(resultUrl) && !(resultUrl.startsWith("#{") && 
resultUrl.contains("}"))) {
+        if (StringUtils.isNotBlank(resultUrl) && !(resultUrl.startsWith("#{") 
&& resultUrl.contains("}"))) {
             if (!resultUrl.contains("://")) {
                 resultUrl = "http://"; + resultUrl;
             }
@@ -373,7 +375,7 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
 
     private String getUrl(final ConfigurableBeanFactory beanFactory, final 
Map<String, Object> attributes) {
         String url = resolve(beanFactory, (String) attributes.get("url"));
-        if (!StringUtils.hasText(url)) {
+        if (StringUtils.isBlank(url)) {
             return getUrl(getName(beanFactory, attributes));
         }
         return getUrl(url);
@@ -392,7 +394,7 @@ public class ShenyuClientsRegistrar implements 
ImportBeanDefinitionRegistrar, Re
      */
     static String getPath(final String path) {
         String resultPath = path;
-        if (StringUtils.hasText(resultPath)) {
+        if (StringUtils.isNotBlank(resultPath)) {
             resultPath = resultPath.trim();
             if (!resultPath.startsWith("/")) {
                 resultPath = "/" + resultPath;
diff --git 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/CookieValueParameterProcessor.java
 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/CookieValueParameterProcessor.java
index ca9e8ee885..e54991f642 100644
--- 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/CookieValueParameterProcessor.java
+++ 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/CookieValueParameterProcessor.java
@@ -17,19 +17,21 @@
 
 package org.apache.shenyu.sdk.spring.annotation;
 
-import static com.google.common.base.Strings.emptyToNull;
 import com.google.common.collect.Lists;
-import java.lang.annotation.Annotation;
-import java.util.Collection;
-import java.util.Map;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.sdk.core.ShenyuRequest;
 import org.apache.shenyu.sdk.core.common.RequestTemplate;
-import static org.apache.shenyu.sdk.core.util.Util.checkState;
 import org.apache.shenyu.sdk.spring.factory.AnnotatedParameterProcessor;
 import org.springframework.http.HttpHeaders;
 import org.springframework.web.bind.annotation.CookieValue;
 
+import java.lang.annotation.Annotation;
+import java.util.Collection;
+import java.util.Map;
+
+import static org.apache.shenyu.sdk.core.util.Util.checkState;
+
 
 /**
  * annotation processor.
@@ -48,7 +50,7 @@ public class CookieValueParameterProcessor implements 
AnnotatedParameterProcesso
         RequestTemplate requestTemplate = shenyuRequest.getRequestTemplate();
         CookieValue cookie = ANNOTATION.cast(annotation);
         String name = cookie.value().trim();
-        checkState(emptyToNull(name) != null, "Cookie.name() was empty on 
parameter %s", requestTemplate.getMethod());
+        checkState(StringUtils.isNotBlank(name), "Cookie.name() was empty on 
parameter %s", requestTemplate.getMethod());
         Collection<String> cookieExpression = 
requestTemplate.getHeaders().getOrDefault(HttpHeaders.COOKIE, 
Lists.newArrayList());
         cookieExpression.add(String.format("%s=%s", name, arg));
         Map<String, Collection<String>> headers = shenyuRequest.getHeaders();
diff --git 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/PathVariableParameterProcessor.java
 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/PathVariableParameterProcessor.java
index 89edc062ad..75771b4114 100644
--- 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/PathVariableParameterProcessor.java
+++ 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/PathVariableParameterProcessor.java
@@ -17,16 +17,17 @@
 
 package org.apache.shenyu.sdk.spring.annotation;
 
-import static com.google.common.base.Strings.emptyToNull;
-import java.lang.annotation.Annotation;
-import java.util.Map;
 import org.apache.commons.lang3.RegExUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.sdk.core.ShenyuRequest;
 import org.apache.shenyu.sdk.core.common.RequestTemplate;
 import static org.apache.shenyu.sdk.core.util.Util.checkState;
 import org.apache.shenyu.sdk.spring.factory.AnnotatedParameterProcessor;
 import org.springframework.web.bind.annotation.PathVariable;
 
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
 /**
  * {@link PathVariable} parameter processor.
  */
@@ -43,7 +44,7 @@ public class PathVariableParameterProcessor implements 
AnnotatedParameterProcess
     public boolean processArgument(final ShenyuRequest shenyuRequest, final 
Annotation annotation, final Object arg) {
         String name = ANNOTATION.cast(annotation).value();
         RequestTemplate requestTemplate = shenyuRequest.getRequestTemplate();
-        checkState(arg instanceof String && emptyToNull(name) != null || arg 
instanceof Map,
+        checkState(arg instanceof String && StringUtils.isNotBlank(name) || 
arg instanceof Map,
             "PathVariable Object class pls is String or Map<String, String> 
and PathVariable annotation value could not be empty when String class at the 
method %s.", requestTemplate.getMethod());
 
         if (arg instanceof String) {
diff --git 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/RequestParamParameterProcessor.java
 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/RequestParamParameterProcessor.java
index b3dfe656a6..cad6cbaf55 100644
--- 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/RequestParamParameterProcessor.java
+++ 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/annotation/RequestParamParameterProcessor.java
@@ -17,10 +17,11 @@
 
 package org.apache.shenyu.sdk.spring.annotation;
 
-import static com.google.common.base.Strings.emptyToNull;
 import com.google.common.collect.Maps;
 import java.lang.annotation.Annotation;
 import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.sdk.core.ShenyuRequest;
 import org.apache.shenyu.sdk.core.common.RequestTemplate;
 import static org.apache.shenyu.sdk.core.util.Util.checkState;
@@ -45,7 +46,7 @@ public class RequestParamParameterProcessor implements 
AnnotatedParameterProcess
         RequestTemplate requestTemplate = shenyuRequest.getRequestTemplate();
         RequestParam requestParam = ANNOTATION.cast(annotation);
         String name = requestParam.value();
-        checkState(emptyToNull(name) != null || arg instanceof Map, 
"RequestParam.value() was empty on parameter %s#%s",
+        checkState(StringUtils.isNotBlank(name) || arg instanceof Map, 
"RequestParam.value() was empty on parameter %s#%s",
             requestTemplate.getMethod().getDeclaringClass().getSimpleName(), 
requestTemplate.getMethod().getName());
         StringBuilder pathResult = new 
StringBuilder(requestTemplate.getPath());
         Map<Object, Object> params = Maps.newHashMap();
diff --git 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/factory/Contract.java
 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/factory/Contract.java
index d989a10791..e624863d00 100644
--- 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/factory/Contract.java
+++ 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/factory/Contract.java
@@ -33,6 +33,7 @@ import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import static org.apache.shenyu.sdk.core.util.Util.checkState;
 
@@ -104,7 +105,7 @@ public interface Contract extends ResourceLoaderAware {
             List<RequestTemplate.ParamMetadata> params = new 
ArrayList<>(parameters.length);
             for (int index = 0; index < parameters.length; index++) {
                 Annotation[] annotations = parameters[index].getAnnotations();
-                if (annotations == null || annotations.length == 0) {
+                if (Objects.isNull(annotations) || annotations.length == 0) {
                     continue;
                 }
                 params.add(new RequestTemplate.ParamMetadata(annotations, 
parameters[index].getType(), index));
diff --git 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/proxy/ShenyuClientInvocationHandler.java
 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/proxy/ShenyuClientInvocationHandler.java
index be22d08037..96daaee7fa 100644
--- 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/proxy/ShenyuClientInvocationHandler.java
+++ 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/proxy/ShenyuClientInvocationHandler.java
@@ -41,6 +41,7 @@ import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
@@ -84,7 +85,7 @@ public class ShenyuClientInvocationHandler implements 
InvocationHandler {
             result = handler.invoke(args);
         } catch (Throwable throwable) {
             LOG.error("ShenYu Client invoke error  ", throwable);
-            if (fallbackFactory == null) {
+            if (Objects.isNull(fallbackFactory)) {
                 throw new NoFallbackAvailableException("No fallback 
available.", throwable);
             }
             Object fallback = fallbackFactory.create(throwable);
diff --git 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/proxy/ShenyuClientMethodHandler.java
 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/proxy/ShenyuClientMethodHandler.java
index b0b18be6ba..5673096c5d 100644
--- 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/proxy/ShenyuClientMethodHandler.java
+++ 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/proxy/ShenyuClientMethodHandler.java
@@ -34,6 +34,7 @@ import 
org.springframework.web.client.HttpClientErrorException;
 import java.io.IOException;
 import java.lang.annotation.Annotation;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * ShenyuClientMethodHandler.
@@ -74,7 +75,7 @@ public class ShenyuClientMethodHandler {
     }
 
     private Object handlerResponse(final ShenyuResponse shenyuResponse, final 
Class<?> returnType) {
-        if (shenyuResponse == null || void.class == returnType) {
+        if (Objects.isNull(shenyuResponse) || void.class == returnType) {
             return null;
         } else if (ShenyuResponse.class == returnType) {
             return shenyuResponse;
diff --git 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/support/SpringMvcContract.java
 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/support/SpringMvcContract.java
index de29ba0b08..c2aa046fcf 100644
--- 
a/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/support/SpringMvcContract.java
+++ 
b/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/support/SpringMvcContract.java
@@ -17,6 +17,7 @@
 
 package org.apache.shenyu.sdk.spring.support;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.sdk.core.ShenyuRequest;
 import org.apache.shenyu.sdk.core.common.RequestTemplate;
 import org.apache.shenyu.sdk.spring.ShenyuClientFactoryBean;
@@ -25,7 +26,6 @@ import 
org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.core.io.DefaultResourceLoader;
 import org.springframework.core.io.ResourceLoader;
 import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 
@@ -33,6 +33,7 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Objects;
 
 import static 
org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation;
 
@@ -80,11 +81,11 @@ public class SpringMvcContract extends 
Contract.BaseContract {
         checkAtMostOne(method, methodMapping.value(), "value");
         if (methodMapping.value().length > 0) {
             String pathValue = methodMapping.value()[0];
-            if (pathValue != null && !pathValue.isEmpty()) {
+            if (StringUtils.isNotBlank(pathValue)) {
                 pathValue = resolve(pathValue);
                 // Append path from @RequestMapping if value is present on 
method
                 if (!pathValue.startsWith("/")
-                        && 
StringUtils.hasText(shenyuClientFactoryBean.getPath())
+                        && 
StringUtils.isNotBlank(shenyuClientFactoryBean.getPath())
                         && !shenyuClientFactoryBean.getPath().endsWith("/")) {
                     pathValue = "/" + pathValue;
                 }
@@ -106,7 +107,7 @@ public class SpringMvcContract extends 
Contract.BaseContract {
     private void parseProduces(final RequestTemplate requestTemplate, final 
RequestMapping annotation) {
         String[] serverProduces = annotation.produces();
         String clientAccepts = serverProduces.length == 0 ? null : 
serverProduces[0].isEmpty() ? null : serverProduces[0];
-        if (clientAccepts != null) {
+        if (Objects.nonNull(clientAccepts)) {
             requestTemplate.getHeaders().put(ACCEPT, 
Collections.singleton(clientAccepts));
         }
     }
@@ -114,7 +115,7 @@ public class SpringMvcContract extends 
Contract.BaseContract {
     private void parseConsumes(final RequestTemplate requestTemplate, final 
RequestMapping annotation) {
         String[] serverConsumes = annotation.consumes();
         String clientProduces = serverConsumes.length == 0 ? null : 
serverConsumes[0].isEmpty() ? null : serverConsumes[0];
-        if (clientProduces != null) {
+        if (Objects.nonNull(clientProduces)) {
             requestTemplate.getHeaders().put(CONTENT_TYPE, 
Collections.singleton(clientProduces));
         }
     }
@@ -130,20 +131,20 @@ public class SpringMvcContract extends 
Contract.BaseContract {
     }
 
     private String resolve(final String value) {
-        if (StringUtils.hasText(value) && resourceLoader instanceof 
ConfigurableApplicationContext) {
+        if (StringUtils.isNotBlank(value) && resourceLoader instanceof 
ConfigurableApplicationContext) {
             return ((ConfigurableApplicationContext) 
resourceLoader).getEnvironment().resolvePlaceholders(value);
         }
         return value;
     }
 
     private void checkOne(final Method method, final Object[] values, final 
String fieldName) {
-        Assert.state(values != null && values.length == 1,
+        Assert.state(Objects.nonNull(values) && values.length == 1,
                 String.format("Method %s can only contain 1 %s field. Found: 
%s",
-                        method.getName(), fieldName, values == null ? null : 
Arrays.asList(values)));
+                        method.getName(), fieldName, Objects.isNull(values) ? 
null : Arrays.asList(values)));
     }
 
     private void checkAtMostOne(final Method method, final Object[] values, 
final String fieldName) {
-        Assert.state(values != null && (values.length == 0 || values.length == 
1),
+        Assert.state(Objects.nonNull(values) && (values.length == 0 || 
values.length == 1),
                 String.format("Method %s can only contain at most 1 %s field. 
Found: %s",
                         method.getName(), fieldName, Arrays.asList(values)));
     }

Reply via email to