tanghc 5 years ago
parent d42c9e9ba4
commit fdf9f341fd
  1. 10
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/IPBlacklistApi.java
  2. 5
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/LogApi.java
  3. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/ServiceApi.java
  4. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/result/LogMonitorInstanceVO.java
  5. 3
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ZookeeperContext.java
  6. 3
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/common/AdminErrors.java
  7. 6
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/common/IdGen.java
  8. 9
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/common/RSATool.java
  9. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/IsvInfo.java
  10. 5
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/interceptor/LoginInterceptor.java
  11. 5
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/mapper/IsvInfoMapper.java
  12. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/BeanInitializer.java
  13. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ConfigLimitDto.java
  14. 11
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ErrorEntity.java
  15. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteConfig.java
  16. 19
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteStatus.java
  17. 16
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/TargetRoute.java
  18. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/ReadBodyRoutePredicateFactory.java
  19. 16
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/IPBlacklistManager.java
  20. 8
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/RoutePermissionManager.java
  21. 10
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/BaseParamBuilder.java
  22. 9
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/BaseExecutorAdapter.java
  23. 17
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/secret/IsvManager.java
  24. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RequestUtil.java
  25. 25
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/filter/PreLimitFilter.java
  26. 3
      sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/bean/ServiceInstance.java
  27. 3
      sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/RegistryService.java
  28. 4
      sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/impl/RegistryServiceNacos.java
  29. 6
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/BaseServiceConfiguration.java
  30. 4
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/EasyopenDocSupportController.java
  31. 6
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/SopHandlerMethodArgumentResolver.java
  32. 7
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/SwaggerSupport.java
  33. 4
      sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RestServlet.java
  34. 3
      sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbIPBlacklistManager.java
  35. 2
      sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbIsvManager.java
  36. 2
      sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbLimitConfigManager.java
  37. 2
      sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbRouteConfigManager.java
  38. 4
      sop-gateway/src/main/java/com/gitee/sop/gateway/mapper/IsvInfoMapper.java
  39. 21
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/client/OpenHttp.java
  40. 4
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/RequestForm.java
  41. 4
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/RequestMethod.java
  42. 1
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/SdkConfig.java
  43. 3
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/SopSdkConstants.java
  44. 3
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/exception/SdkException.java
  45. 8
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/request/BaseRequest.java
  46. 2
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/response/BaseResponse.java
  47. 1
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/BaseNCodec.java
  48. 4
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/FileUtil.java
  49. 6
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/HexUtil.java
  50. 4
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/MD5Util.java

@ -14,7 +14,6 @@ import com.gitee.sop.adminserver.api.service.param.ConfigIpBlackForm;
import com.gitee.sop.adminserver.api.service.param.ConfigIpBlacklistPageParam;
import com.gitee.sop.adminserver.api.service.result.ConfigIpBlacklistVO;
import com.gitee.sop.adminserver.bean.ChannelMsg;
import com.gitee.sop.adminserver.bean.ConfigLimitDto;
import com.gitee.sop.adminserver.bean.ZookeeperContext;
import com.gitee.sop.adminserver.common.BizException;
import com.gitee.sop.adminserver.entity.ConfigIpBlacklist;
@ -93,6 +92,13 @@ public class IPBlacklistApi {
}
enum BlacklistMsgType {
ADD, DELETE
/**
* 黑名单消息类型添加
*/
ADD,
/**
* 黑名单消息类型删除
*/
DELETE
}
}

@ -40,6 +40,7 @@ public class LogApi {
public static final String LOG_MONITOR_INSTANCE = "log.monitor.instance";
public static final String CODE_SUCCESS = "10000";
private static final String CODE_KEY = "code";
@Autowired
ConfigCommonMapper configCommonMapper;
@ -135,7 +136,7 @@ public class LogApi {
try {
String json = this.requestLogServer(ipPort, "listErrors");
JSONObject jsonObject = JSON.parseObject(json);
if (!CODE_SUCCESS.equals(jsonObject.getString("code"))) {
if (!CODE_SUCCESS.equals(jsonObject.getString(CODE_KEY))) {
log.error("请求结果:{}", json);
throw new BizException("添加失败");
}
@ -147,7 +148,7 @@ public class LogApi {
private String requestLogServer(String ipPort, String path) throws Exception {
DefaultMd5Verifier md5Verifier = new DefaultMd5Verifier();
Map<String, Object> params = new HashMap<>();
Map<String, Object> params = new HashMap<>(16);
params.put("time", System.currentTimeMillis());
String sign = md5Verifier.buildSign(params, secret);
params.put("sign", sign);

@ -115,7 +115,7 @@ public class ServiceApi {
List<ServiceInstanceVO> listService(ServiceSearchParam param) {
List<ServiceInfo> serviceInfos;
try {
serviceInfos = registryService.listAllService(1, 99999/* 获取所有实例 */);
serviceInfos = registryService.listAllService(1, 99999);
} catch (Exception e) {
log.error("获取服务实例失败", e);
return Collections.emptyList();

@ -9,7 +9,7 @@ import lombok.Data;
public class LogMonitorInstanceVO {
private String id;
private int treeId;
// 表主键
/** 表主键 */
private long rawId;
private String name;
private String version;

@ -22,6 +22,7 @@ import org.springframework.util.Assert;
import java.io.Closeable;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Executors;
import static com.gitee.sop.adminserver.bean.SopAdminConstants.SOP_MSG_CHANNEL_PATH;
@ -307,7 +308,7 @@ public class ZookeeperContext {
String data = new String(nodeData);
if (StringUtils.isNotBlank(data) && !initData.equals(data)) {
listenCallback.onError(data);
new Thread(new ZKClose(cache, client)).start();
Executors.newSingleThreadExecutor().execute(() -> new ZKClose(cache, client));
}
}
});

@ -9,7 +9,8 @@ import com.gitee.easyopen.message.ErrorMeta;
public class AdminErrors {
private AdminErrors(){}
static String isvModule = "isv.error_"; // error_zh_CN2.properties内容前缀
/** error_zh_CN2.properties内容前缀 */
static String isvModule = "isv.error_";
public static final ErrorMeta NO_LOGIN = new ErrorMeta(isvModule, "-100", "用户未登录");

@ -124,9 +124,9 @@ public class IdGen {
lastTimestamp = timestamp;
//移位并通过或运算拼到一起组成64位的ID
return ((timestamp - twepoch) << timestampLeftShift) //
| (datacenterId << datacenterIdShift) //
| (workerId << workerIdShift) //
return ((timestamp - twepoch) << timestampLeftShift)
| (datacenterId << datacenterIdShift)
| (workerId << workerIdShift)
| sequence;
}

@ -309,7 +309,14 @@ public class RSATool {
}
public enum KeyLength {
LENGTH_1024(1024), LENGTH_2048(2048);
/**
* 秘钥长度1024
*/
LENGTH_1024(1024),
/**
* 秘钥长度2048
*/
LENGTH_2048(2048);
private int length;
KeyLength(int length) {

@ -28,7 +28,7 @@ public class IsvInfo {
/** appKey, 数据库字段:app_key */
private String appKey;
// 不再使用,转移到isv_keys表
/** 不再使用,转移到isv_keys表 */
private String secret = "";
/** 公钥,不再使用,转移到isv_keys表 数据库字段:pub_key */

@ -15,6 +15,8 @@ import javax.servlet.http.HttpServletResponse;
*/
public class LoginInterceptor extends ApiInterceptorAdapter {
public static final String PREFIX = "nologin.";
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object serviceObj, Object argu)
throws Exception {
@ -28,7 +30,8 @@ public class LoginInterceptor extends ApiInterceptorAdapter {
@Override
public boolean match(ApiMeta apiMeta) {
String name = apiMeta.getName();
if (name.startsWith("nologin.")) { // 以‘nologin.’开头的接口不拦截
// 以‘nologin.’开头的接口不拦截
if (name.startsWith(PREFIX)) {
return false;
} else {
return true;

@ -13,6 +13,11 @@ import org.apache.ibatis.annotations.Select;
*/
public interface IsvInfoMapper extends CrudMapper<IsvInfo, Long> {
/**
* 获取isv详细信息
* @param appKey appKey
* @return 返回详细信息没有返回null
*/
@Select("SELECT " +
" t.app_key appKey " +
" ,t.status " +

@ -4,5 +4,8 @@ package com.gitee.sop.gatewaycommon.bean;
* @author tanghc
*/
public interface BeanInitializer {
/**
* 执行加载操作
*/
void load();
}

@ -13,6 +13,9 @@ import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author thc
*/
@Data
public class ConfigLimitDto {

@ -6,6 +6,9 @@ import lombok.ToString;
import java.util.Objects;
/**
* @author thc
*/
@Getter
@Setter
@ToString
@ -19,8 +22,12 @@ public class ErrorEntity {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ErrorEntity that = (ErrorEntity) o;
return id.equals(that.id);
}

@ -8,7 +8,7 @@ import lombok.Data;
@Data
public class RouteConfig {
public static final byte STATUS_ENABLE = 1;
private static final byte STATUS_ENABLE = RouteStatus.ENABLE.getStatus();
/**
* 路由id

@ -1,22 +1,33 @@
package com.gitee.sop.gatewaycommon.bean;
/**
* 路由状态
*
* @author tanghc
*/
public enum RouteStatus {
/**
* 路由状态0待审核
*/
AUDIT(0, "待审核"),
/**
* 路由状态1已启用
*/
ENABLE(1, "已启用"),
/**
* 路由状态2已禁用
*/
DISABLE(2, "已禁用"),
;
private int status;
private byte status;
private String description;
RouteStatus(int status, String description) {
this.status = status;
RouteStatus(Integer status, String description) {
this.status = status.byteValue();
this.description = description;
}
public int getStatus() {
public byte getStatus() {
return status;
}

@ -4,9 +4,25 @@ package com.gitee.sop.gatewaycommon.bean;
* @author tanghc
*/
public interface TargetRoute<R extends BaseServiceRouteInfo, E extends BaseRouteDefinition, T> {
/**
* 返回服务信息
*
* @return 返回服务信息
*/
R getServiceRouteInfo();
/**
* 返回微服务路由对象
*
* @return 返回微服务路由对象
*/
E getRouteDefinition();
/**
* 返回网关路由对象
*
* @return 返回网关路由对象
*/
T getTargetRouteDefinition();
}

@ -44,7 +44,7 @@ public class ReadBodyRoutePredicateFactory extends AbstractRoutePredicateFactory
private static final String TEST_ATTRIBUTE = "read_body_predicate_test_attribute";
private static final String CACHE_REQUEST_BODY_OBJECT_KEY = "cachedRequestBodyObject";
private static final List<HttpMessageReader<?>> messageReaders = HandlerStrategies.withDefaults().messageReaders();
private static final List<HttpMessageReader<?>> HTTP_MESSAGE_READERS = HandlerStrategies.withDefaults().messageReaders();
public ReadBodyRoutePredicateFactory() {
@ -108,7 +108,7 @@ public class ReadBodyRoutePredicateFactory extends AbstractRoutePredicateFactory
return cachedFlux;
}
};
return ServerRequest.create(exchange.mutate().request(mutatedRequest).build(), messageReaders)
return ServerRequest.create(exchange.mutate().request(mutatedRequest).build(), HTTP_MESSAGE_READERS)
.bodyToMono(inClass)
.doOnNext(objectValue -> {
exchange.getAttributes().put(CACHE_REQUEST_BODY_OBJECT_KEY, objectValue);

@ -7,10 +7,26 @@ import com.gitee.sop.gatewaycommon.bean.BeanInitializer;
*/
public interface IPBlacklistManager extends BeanInitializer {
/**
* 添加IP
*
* @param ip ip
*/
void add(String ip);
/**
* 移除黑名单IP
*
* @param ip ip
*/
void remove(String ip);
/**
* ip是否在黑名单中
*
* @param ip ip
* @return true在黑名单中
*/
boolean contains(String ip);
}

@ -6,7 +6,15 @@ import com.gitee.sop.gatewaycommon.bean.IsvRoutePermission;
* @author tanghc
*/
public interface RoutePermissionManager {
/**
* 加载路由授权
*/
void load();
/**
* 更新路由授权信息
*
* @param isvRoutePermission 授权信息
*/
void update(IsvRoutePermission isvRoutePermission);
}

@ -17,8 +17,18 @@ import java.util.Optional;
@Slf4j
public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
/**
* 构建请求参数
* @param ctx 请求request
* @return 返回请求参数
*/
public abstract Map<String, String> buildRequestParams(T ctx);
/**
* 返回客户端ip
* @param ctx 请求request
* @return 返回ip
*/
public abstract String getIP(T ctx);
@Override

@ -275,6 +275,13 @@ public abstract class BaseExecutorAdapter<T, R> implements ResultExecutor<T, R>
}
enum ErrorType {
UNKNOWN, BIZ
/**
* 未知错误
*/
UNKNOWN,
/**
* 业务错误
*/
BIZ
}
}

@ -5,14 +5,31 @@ import com.gitee.sop.gatewaycommon.bean.Isv;
/**
* Isv管理
*
* @author tanghc
*/
public interface IsvManager<T extends Isv> extends BeanInitializer {
/**
* 更新isv
*
* @param t isv
*/
void update(T t);
/**
* 删除isv
*
* @param appKey isv对应的appKey
*/
void remove(String appKey);
/**
* 获取isv
*
* @param appKey isv对应的key
* @return 返回isv
*/
T getIsv(String appKey);
}

@ -105,7 +105,7 @@ public class RequestUtil {
DiskFileItemFactory factory = new DiskFileItemFactory();
//2、创建一个文件上传解析器
ServletFileUpload upload = new ServletFileUpload(factory);
Map<String, String> params = new HashMap<>();
Map<String, String> params = new HashMap<>(16);
try {
List<FileItem> fileItems = upload.parseRequest(request);
for (FileItem fileItem : fileItems) {

@ -21,6 +21,7 @@ import java.util.List;
/**
* 限流拦截器
*
* @author tanghc
*/
public class PreLimitFilter extends BaseZuulFilter {
@ -36,8 +37,7 @@ public class PreLimitFilter extends BaseZuulFilter {
}
@Override
protected Object doRun(RequestContext requestContext) throws ZuulException
{
protected Object doRun(RequestContext requestContext) throws ZuulException {
ApiConfig apiConfig = ApiConfig.getInstance();
// 限流功能未开启,直接返回
if (!apiConfig.isOpenLimit()) {
@ -75,14 +75,21 @@ public class PreLimitFilter extends BaseZuulFilter {
// 最多7种情况
String[] limitKeys = new String[]{
routeId, // 根据路由ID限流
appKey, // 根据appKey限流
routeId + appKey, // 根据路由ID + appKey限流
// 根据路由ID限流
routeId,
// 根据appKey限流
appKey,
// 根据路由ID + appKey限流
routeId + appKey,
ip, // 根据ip限流
ip + routeId, // 根据ip+路由id限流
ip + appKey, // 根据ip+appKey限流
ip + routeId + appKey, // 根据ip+路由id+appKey限流
// 根据ip限流
ip,
// 根据ip+路由id限流
ip + routeId,
// 根据ip+appKey限流
ip + appKey,
// 根据ip+路由id+appKey限流
ip + routeId + appKey,
};
List<ConfigLimitDto> limitConfigList = new ArrayList<>();

@ -2,6 +2,9 @@ package com.gitee.sop.registryapi.bean;
import lombok.Data;
/**
* @author thc
*/
@Data
public class ServiceInstance {
/**

@ -15,6 +15,7 @@ public interface RegistryService {
* @param pageNo 当前页码
* @param pageSize 分页大小
* @return 返回服务列表
* @throws Exception 获取失败抛出异常
*/
List<ServiceInfo> listAllService(int pageNo, int pageSize) throws Exception;
@ -22,6 +23,7 @@ public interface RegistryService {
* 服务上线
*
* @param serviceInstance
* @throws Exception 服务上线失败抛出异常
*/
void onlineInstance(ServiceInstance serviceInstance) throws Exception;
@ -29,6 +31,7 @@ public interface RegistryService {
* 服务下线
*
* @param serviceInstance
* @throws Exception 服务下线失败抛出异常
*/
void offlineInstance(ServiceInstance serviceInstance) throws Exception;

@ -73,7 +73,7 @@ public class RegistryServiceNacos implements RegistryService {
@Override
public void onlineInstance(ServiceInstance serviceInstance) throws Exception {
Map<String, String> params = new HashMap<>();
Map<String, String> params = new HashMap<>(8);
// 上线,把权重设置成1
params.put("weight", "1");
this.updateInstance(serviceInstance, params);
@ -81,7 +81,7 @@ public class RegistryServiceNacos implements RegistryService {
@Override
public void offlineInstance(ServiceInstance serviceInstance) throws Exception {
Map<String, String> params = new HashMap<>();
Map<String, String> params = new HashMap<>(8);
// 下线,把权重设置成0
params.put("weight", "0");
this.updateInstance(serviceInstance, params);

@ -73,7 +73,11 @@ public class BaseServiceConfiguration extends WebMvcConfigurationSupport
doAfter();
}
// springboot启动完成后执行
/**
* springboot启动完成后执行
* @param args 启动参数
* @throws Exception 出错异常
*/
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("-----服务器启动完毕-----");

@ -19,6 +19,10 @@ public abstract class EasyopenDocSupportController {
private SwaggerValidator swaggerValidator;
/**
* 获取文档标题
* @return 返回文档标题
*/
public abstract String getDocTitle();
public EasyopenDocSupportController() {

@ -7,5 +7,11 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
* @author tanghc
*/
public interface SopHandlerMethodArgumentResolver extends HandlerMethodArgumentResolver {
/**
* 设置requestMappingHandlerAdapter
*
* @param requestMappingHandlerAdapter requestMappingHandlerAdapter
*/
void setRequestMappingHandlerAdapter(RequestMappingHandlerAdapter requestMappingHandlerAdapter);
}

@ -10,8 +10,15 @@ import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
/**
* @author thc
*/
public abstract class SwaggerSupport {
/**
* 获取文档标题
* @return 返回文档标题
*/
protected abstract String getDocTitle();
@Bean

@ -12,6 +12,10 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* 传统web开发入口
* @author thc
*/
@WebServlet(urlPatterns = "/rest/*")
public class RestServlet extends HttpServlet {

@ -15,6 +15,7 @@ import java.util.List;
/**
* 限流配置管理
*
* @author tanghc
*/
@Slf4j
@ -52,6 +53,8 @@ public class DbIPBlacklistManager extends DefaultIPBlacklistManager {
log.info("移除IP黑名单,ip:{}", ip);
remove(ip);
break;
default:
log.error("IP黑名单,错误的消息指令,nodeData:{}", nodeData);
}
});
}

@ -56,6 +56,8 @@ public class DbIsvManager extends CacheIsvManager {
log.info("删除ISV,isvDefinition:{}", isvDefinition);
remove(isvDefinition.getAppKey());
break;
default:
log.error("ISV信息,错误的消息指令,nodeData:{}", nodeData);
}
});

@ -60,6 +60,8 @@ public class DbLimitConfigManager extends DefaultLimitConfigManager {
log.info("更新限流配置信息,configLimitDto:{}", configLimitDto);
update(configLimitDto);
break;
default:
log.error("限流配置信息,错误的消息指令,nodeData:{}", nodeData);
}
});
}

@ -84,6 +84,8 @@ public class DbRouteConfigManager extends DefaultRouteConfigManager {
log.info("更新路由配置信息,routeConfigDto:{}", routeConfig);
update(routeConfig);
break;
default:
log.error("路由配置信息,错误的消息指令,nodeData:{}", nodeData);
}
});
}

@ -13,6 +13,10 @@ import java.util.List;
*/
public interface IsvInfoMapper extends CrudMapper<IsvInfo, Long> {
/**
* 获取所有的isv信息
* @return 所有的isv信息
*/
@Select("SELECT " +
" t.app_key appKey " +
" ,t.status " +

@ -44,14 +44,17 @@ public class OpenHttp {
protected void initHttpClient(OpenConfig openConfig) {
httpClient = new OkHttpClient.Builder()
.connectTimeout(openConfig.getConnectTimeoutSeconds(), TimeUnit.SECONDS) // 设置链接超时时间,默认10秒
// 设置链接超时时间
.connectTimeout(openConfig.getConnectTimeoutSeconds(), TimeUnit.SECONDS)
.readTimeout(openConfig.getReadTimeoutSeconds(), TimeUnit.SECONDS)
.writeTimeout(openConfig.getWriteTimeoutSeconds(), TimeUnit.SECONDS)
.cookieJar(new CookieJar() {
@Override
public void saveFromResponse(HttpUrl httpUrl, List<Cookie> list) {
cookieStore.put(httpUrl.host(), list);
}
@Override
public List<Cookie> loadForRequest(HttpUrl httpUrl) {
List<Cookie> cookies = cookieStore.get(httpUrl.host());
return cookies != null ? cookies : new ArrayList<Cookie>();
@ -79,8 +82,9 @@ public class OpenHttp {
/**
* 请求json数据contentType=application/json
* @param url 请求路径
* @param json json数据
*
* @param url 请求路径
* @param json json数据
* @param header header
* @return 返回响应结果
* @throws IOException
@ -188,9 +192,14 @@ public class OpenHttp {
bodyBuilder.setType(MultipartBody.FORM);
for (UploadFile uploadFile : files) {
bodyBuilder.addFormDataPart(uploadFile.getName(), // 请求的名字
uploadFile.getFileName(), // 文件的文字,服务器端用来解析的
RequestBody.create(null, uploadFile.getFileData()) // 创建RequestBody,把上传的文件放入
bodyBuilder.addFormDataPart(
// 请求的名字
uploadFile.getName(),
// 文件的文字,服务器端用来解析的
uploadFile.getFileName(),
// 创建RequestBody,把上传的文件放入
RequestBody.create(null, uploadFile.getFileData())
);
}

@ -6,6 +6,10 @@ import lombok.Setter;
import java.util.List;
import java.util.Map;
/**
* 请求form
* @author thc
*/
@Getter
@Setter
public class RequestForm {

@ -1,5 +1,9 @@
package com.gitee.sop.sdk.common;
/**
* 请求方法枚举
* @author thc
*/
public enum RequestMethod {
GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE

@ -2,6 +2,7 @@ package com.gitee.sop.sdk.common;
/**
* @deprecated 已废弃使用com.gitee.sop.sdk.common.OpenConfig
* @author thc
*/
@Deprecated
public class SdkConfig {

@ -1,5 +1,8 @@
package com.gitee.sop.sdk.common;
/**
* @author thc
*/
public class SopSdkConstants {
public static String DATA_SUFFIX = "_response";

@ -1,5 +1,8 @@
package com.gitee.sop.sdk.exception;
/**
* @author thc
*/
public class SdkException extends RuntimeException {
private static final long serialVersionUID = -1108392076700488161L;

@ -31,6 +31,8 @@ import java.util.Map;
* biz_content String 请求参数的集合最大长度不限除公共参数外所有请求参数都必须放在这个参数中传递具体参照各产品快速接入文档
*
* @param <T> 对应的Response对象
*
* @author thc
*/
public abstract class BaseRequest<T extends BaseResponse> {
@ -47,6 +49,10 @@ public abstract class BaseRequest<T extends BaseResponse> {
private Class<T> responseClass = (Class<T>) ClassUtil.getSuperClassGenricType(this.getClass(), 0);;
/**
* 定义接口名称
* @return 接口名称
*/
protected abstract String method();
public BaseRequest() {
@ -80,7 +86,7 @@ public abstract class BaseRequest<T extends BaseResponse> {
public RequestForm createRequestForm(OpenConfig openConfig) {
// 公共请求参数
Map<String, String> params = new HashMap<String, String>();
Map<String, String> params = new HashMap<String, String>(16);
params.put(openConfig.getMethodName(), this.method);
params.put(openConfig.getFormatName(), openConfig.getFormatType());
params.put(openConfig.getCharsetName(), openConfig.getCharset());

@ -16,7 +16,7 @@ import lombok.Setter;
* },
* "sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
* }
*
* @author thc
*/
@Setter
@Getter

@ -77,6 +77,7 @@ public abstract class BaseNCodec {
* @return a String useful for debugging.
*/
@SuppressWarnings("boxing") // OK to ignore boxing here
@Override
public String toString() {
return String.format("%s[buffer=%s, currentLinePos=%s, eof=%s, ibitWorkArea=%s, lbitWorkArea=%s, " +
"modulus=%s, pos=%s, readPos=%s]", this.getClass().getSimpleName(), Arrays.toString(buffer),

@ -7,6 +7,10 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/**
* 文件工具类
* @author thc
*/
public class FileUtil {
/**

@ -1,5 +1,9 @@
package com.gitee.sop.sdk.util;
/**
* hex工具类
* @author thc
*/
public class HexUtil {
private static final String ZERO = "0";
private static final String CHARS = "0123456789ABCDEF";
@ -30,7 +34,7 @@ public class HexUtil {
* @return byte[]
*/
public static byte[] hex2bytes(String hexString) {
if (hexString == null || hexString.equals("")) {
if (hexString == null || "".equalsIgnoreCase(hexString)) {
return null;
}
hexString = hexString.toUpperCase();

@ -2,6 +2,10 @@ package com.gitee.sop.sdk.util;
import java.security.MessageDigest;
/**
* MD5工具类
* @author thc
*/
public class MD5Util {
private static final String MD5 = "MD5";

Loading…
Cancel
Save