diff --git a/README.md b/README.md index 3d04a52c..569547e3 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ SOP封装了开放平台大部分功能包括:签名验证、统一异常处 ## 项目特点 -- 接入方式简单,与老项目不冲突,老项目注册到注册中心,然后的方法上加上注解即可。 +- 接入方式简单,与老项目不冲突,老项目注册到注册中心,然后在方法上加上注解即可。 - 架构松耦合,业务代码实现在各自微服务上,SOP不参与业务实现,这也是Spring Cloud微服务体系带来的好处。 - 扩展简单,开放平台对应的功能各自独立,可以自定义实现自己的需求,如:更改参数,更改签名规则等。 -## 谁能使用这个项目 +## 谁可以使用这个项目 - 有现成的项目,想改造成开放平台供他人调用 - 有现成的项目,想暴露其中几个接口并通过开放平台供他人调用 diff --git a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/configuration/BaseZuulController.java b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/configuration/BaseZuulController.java index 399db035..37c3c2d7 100644 --- a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/configuration/BaseZuulController.java +++ b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/configuration/BaseZuulController.java @@ -23,7 +23,9 @@ public class BaseZuulController implements ErrorController { public static final String ERROR_PATH = "/error"; - // 错误最终会到这里来 + /** + * 错误最终会到这里来 + */ @RequestMapping(ERROR_PATH) @ResponseBody public Object error(HttpServletRequest request, HttpServletResponse response) { diff --git a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/filter/BaseZuulFilter.java b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/filter/BaseZuulFilter.java index 78dbc74b..d8a468a0 100644 --- a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/filter/BaseZuulFilter.java +++ b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/filter/BaseZuulFilter.java @@ -76,10 +76,15 @@ public abstract class BaseZuulFilter extends ZuulFilter { * Any filterType made be created or added and doRun by calling FilterProcessor.runFilters(type) */ public enum FilterType { + /** zuul过滤器pre类型 */ PRE("pre"), + /** zuul过滤器route类型 */ ROUTE("route"), + /** zuul过滤器post类型 */ POST("post"), + /** zuul过滤器error类型 */ ERROR("error"), + /** zuul过滤器static类型 */ STATIC("static"), ; diff --git a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ApiMetaChangeListener.java b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ApiMetaChangeListener.java index e95baaf1..ea2aded5 100644 --- a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ApiMetaChangeListener.java +++ b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ApiMetaChangeListener.java @@ -5,6 +5,9 @@ import org.springframework.data.redis.connection.MessageListener; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.serializer.RedisSerializer; +/** + * @author tanghc + */ public class ApiMetaChangeListener implements MessageListener { private ApiMetaManager apiMetaManager; diff --git a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultApiMetaContext.java b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultApiMetaContext.java index 2565119b..db1cbeed 100644 --- a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultApiMetaContext.java +++ b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultApiMetaContext.java @@ -16,10 +16,10 @@ import java.util.Map; @Slf4j public class DefaultApiMetaContext implements ApiMetaContext { - // key:nameVersion + /** key:nameVersion */ private Map nameVersionServiceIdMap = new HashMap<>(128); - // key: serviceId , value: md5 + /** key: serviceId , value: md5 */ private Map serviceIdMd5Map = new HashMap<>(16); @Override diff --git a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorEnum.java b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorEnum.java index e963f4f9..c9ce2aa9 100644 --- a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorEnum.java +++ b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorEnum.java @@ -56,8 +56,8 @@ public enum ErrorEnum { ; private ErrorMeta errorMeta; - ErrorEnum(String code, String sub_code) { - this.errorMeta = new ErrorMeta("open.error_", code, sub_code); + ErrorEnum(String code, String subCode) { + this.errorMeta = new ErrorMeta("open.error_", code, subCode); } public ErrorMeta getErrorMeta() { diff --git a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorImpl.java b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorImpl.java index 6fb66b87..cf5c72ed 100644 --- a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorImpl.java +++ b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorImpl.java @@ -2,6 +2,9 @@ package com.gitee.sop.gatewaycommon.message; import lombok.Data; +/** + * @author thc + */ @Data public class ErrorImpl implements Error { private String code; diff --git a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/session/ApiHttpSession.java b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/session/ApiHttpSession.java index 9cf28712..8dfe97a4 100644 --- a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/session/ApiHttpSession.java +++ b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/session/ApiHttpSession.java @@ -207,7 +207,7 @@ public class ApiHttpSession implements HttpSession, Serializable { * @return a representation of this session's serialized state */ public Serializable serializeState() { - HashMap state = new HashMap(); + HashMap state = new HashMap(16); for (Iterator> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry entry = it.next(); String name = entry.getKey(); diff --git a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/StreamUtil.java b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/StreamUtil.java index 343b0ae5..e9635b2c 100644 --- a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/StreamUtil.java +++ b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/StreamUtil.java @@ -101,30 +101,35 @@ public class StreamUtil { this.lock = lock; } + @Override public void write(int datum) throws IOException { synchronized (lock) { out.write(datum); } } + @Override public void write(byte[] data) throws IOException { synchronized (lock) { out.write(data); } } + @Override public void write(byte[] data, int offset, int length) throws IOException { synchronized (lock) { out.write(data, offset, length); } } + @Override public void flush() throws IOException { synchronized (lock) { out.flush(); } } + @Override public void close() throws IOException { synchronized (lock) { out.close(); diff --git a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/StringUtils.java b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/StringUtils.java index 0b3c01e7..38a97fd9 100644 --- a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/StringUtils.java +++ b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/StringUtils.java @@ -44,12 +44,14 @@ public abstract class StringUtils { } char[] chars = obj.toString().toCharArray(); int length = chars.length; - if(length < 1) + if(length < 1) { return false; + } int i = 0; - if(length > 1 && chars[0] == '-') + if(length > 1 && chars[0] == '-') { i = 1; + } for (; i < length; i++) { if (!Character.isDigit(chars[i])) { @@ -91,8 +93,9 @@ public abstract class StringUtils { * 过滤不可见字符 */ public static String stripNonValidXMLCharacters(String input) { - if (input == null || ("".equals(input))) + if (input == null || ("".equals(input))) { return ""; + } StringBuilder out = new StringBuilder(); char current; for (int i = 0; i < input.length(); i++) { @@ -100,8 +103,9 @@ public abstract class StringUtils { if ((current == 0x9) || (current == 0xA) || (current == 0xD) || ((current >= 0x20) && (current <= 0xD7FF)) || ((current >= 0xE000) && (current <= 0xFFFD)) - || ((current >= 0x10000) && (current <= 0x10FFFF))) + || ((current >= 0x10000) && (current <= 0x10FFFF))) { out.append(current); + } } return out.toString(); } diff --git a/sop-server-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceContext.java b/sop-server-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceContext.java index aba95ea6..86936fc5 100644 --- a/sop-server-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceContext.java +++ b/sop-server-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceContext.java @@ -5,13 +5,16 @@ import javax.servlet.http.HttpServletResponse; import java.util.Locale; import java.util.concurrent.ConcurrentHashMap; +/** + * @author tanghc + */ public class ServiceContext extends ConcurrentHashMap { public static final String REQUEST_KEY = "request"; public static final String RESPONSE_KEY = "response"; protected static Class contextClass = ServiceContext.class; - protected static final ThreadLocal threadLocal = new ThreadLocal() { + protected static final ThreadLocal THREAD_LOCAL = new ThreadLocal() { @Override protected ServiceContext initialValue() { try { @@ -47,7 +50,7 @@ public class ServiceContext extends ConcurrentHashMap { * @return the current ServiceContext */ public static ServiceContext getCurrentContext() { - return threadLocal.get(); + return THREAD_LOCAL.get(); } /** @@ -91,8 +94,11 @@ public class ServiceContext extends ConcurrentHashMap { * @param value */ public void set(String key, Object value) { - if (value != null) put(key, value); - else remove(key); + if (value != null) { + put(key, value); + } else { + remove(key); + } } /** @@ -129,10 +135,10 @@ public class ServiceContext extends ConcurrentHashMap { /** - * unsets the threadLocal context. Done at the end of the request. + * unsets the THREAD_LOCAL context. Done at the end of the request. */ public void unset() { - threadLocal.remove(); + THREAD_LOCAL.remove(); } diff --git a/sop-server-common/src/main/java/com/gitee/sop/servercommon/configuration/BaseServerConfiguration.java b/sop-server-common/src/main/java/com/gitee/sop/servercommon/configuration/BaseServerConfiguration.java index f4c32c01..23ea2098 100644 --- a/sop-server-common/src/main/java/com/gitee/sop/servercommon/configuration/BaseServerConfiguration.java +++ b/sop-server-common/src/main/java/com/gitee/sop/servercommon/configuration/BaseServerConfiguration.java @@ -49,7 +49,10 @@ public class BaseServerConfiguration extends WebMvcConfigurationSupport { super.addInterceptors(registry); } - // 自定义Mapping,详见@ApiMapping + /** + * 自定义Mapping,详见@ApiMapping + * @return + */ @Override protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() { ApiMetaManager apiMetaManager = new RedisApiMetaManager(redisTemplate); diff --git a/sop-server-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java b/sop-server-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java index 8f9f7a96..1c2b9c66 100644 --- a/sop-server-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java +++ b/sop-server-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java @@ -13,6 +13,9 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl import java.lang.reflect.Method; +/** + * @author tanghc + */ public class ApiMappingHandlerMapping extends RequestMappingHandlerMapping implements PriorityOrdered { private static StringValueResolver stringValueResolver = new ApiMappingStringValueResolver(); diff --git a/sop-server-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java b/sop-server-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java index c11c32f7..96e1ba8f 100644 --- a/sop-server-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java +++ b/sop-server-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java @@ -8,6 +8,9 @@ import org.springframework.web.servlet.mvc.condition.RequestCondition; import javax.servlet.http.HttpServletRequest; +/** + * @author tanghc + */ @Getter @Slf4j public class ApiMappingRequestCondition implements RequestCondition { @@ -26,8 +29,12 @@ public class ApiMappingRequestCondition implements RequestCondition 1 && chars[0] == '-') - i = 1; + if(length > 1 && chars[0] == '-') { + i = 1; + } for (; i < length; i++) { if (!Character.isDigit(chars[i])) { @@ -91,8 +93,9 @@ public abstract class StringUtils { * 过滤不可见字符 */ public static String stripNonValidXMLCharacters(String input) { - if (input == null || ("".equals(input))) - return ""; + if (input == null || ("".equals(input))) { + return ""; + } StringBuilder out = new StringBuilder(); char current; for (int i = 0; i < input.length(); i++) { @@ -100,8 +103,9 @@ public abstract class StringUtils { if ((current == 0x9) || (current == 0xA) || (current == 0xD) || ((current >= 0x20) && (current <= 0xD7FF)) || ((current >= 0xE000) && (current <= 0xFFFD)) - || ((current >= 0x10000) && (current <= 0x10FFFF))) - out.append(current); + || ((current >= 0x10000) && (current <= 0x10FFFF))) { + out.append(current); + } } return out.toString(); }