diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/HttpTool.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/HttpTool.java index 181ea3b1..2b86578c 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/HttpTool.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/HttpTool.java @@ -51,14 +51,17 @@ public class HttpTool { protected void initHttpClient(HttpToolConfig httpToolConfig) { httpClient = new OkHttpClient.Builder() - .connectTimeout(httpToolConfig.connectTimeoutSeconds, TimeUnit.SECONDS) // 设置链接超时时间,默认10秒 + // 设置链接超时时间,默认10秒 + .connectTimeout(httpToolConfig.connectTimeoutSeconds, TimeUnit.SECONDS) .readTimeout(httpToolConfig.readTimeoutSeconds, TimeUnit.SECONDS) .writeTimeout(httpToolConfig.writeTimeoutSeconds, TimeUnit.SECONDS) .cookieJar(new CookieJar() { + @Override public void saveFromResponse(HttpUrl httpUrl, List list) { cookieStore.put(httpUrl.host(), list); } + @Override public List loadForRequest(HttpUrl httpUrl) { List cookies = cookieStore.get(httpUrl.host()); return cookies != null ? cookies : new ArrayList(); @@ -211,9 +214,12 @@ public class HttpTool { 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()) ); } @@ -255,10 +261,15 @@ public class HttpTool { } public enum HTTPMethod { + /** http GET */ GET, + /** http POST */ POST, + /** http PUT */ PUT, + /** http HEAD */ HEAD, + /** http DELETE */ DELETE; private HTTPMethod() { diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/ByteArrayStreamWrapper.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/ByteArrayStreamWrapper.java index 93c592a3..8d05d74e 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/ByteArrayStreamWrapper.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/ByteArrayStreamWrapper.java @@ -20,15 +20,17 @@ public class ByteArrayStreamWrapper extends ServletInputStream { * @param data a byte[] value */ public ByteArrayStreamWrapper(byte[] data) { - if (data == null) + if (data == null) { data = new byte[0]; + } this.data = data; } @Override public int read() throws IOException { - if (idx == data.length) + if (idx == data.length) { return -1; + } // I have to AND the byte with 0xff in order to ensure that it is returned as an unsigned integer // the lack of this was causing a weird bug when manually unzipping gzipped request bodies return data[idx++] & 0xff; diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/RequestContentDataExtractor.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/RequestContentDataExtractor.java index 543f5e96..5293299d 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/RequestContentDataExtractor.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/RequestContentDataExtractor.java @@ -42,6 +42,9 @@ import static org.springframework.util.StringUtils.isEmpty; import static org.springframework.util.StringUtils.tokenizeToStringArray; import static org.springframework.util.StringUtils.uriDecode; +/** + * @author tanghc + */ public class RequestContentDataExtractor { public static MultiValueMap extract(HttpServletRequest request) throws IOException { return (request instanceof MultipartHttpServletRequest) ? diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/RouteLoader.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/RouteLoader.java index 61981395..7dba7bfd 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/RouteLoader.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/RouteLoader.java @@ -8,7 +8,18 @@ import java.util.function.Consumer; * @author tanghc */ public interface RouteLoader { + /** + * 加载路由 + * + * @param serviceRouteInfo 服务路由信息 + * @param callback 加载成功后回调 + */ void load(ServiceRouteInfo serviceRouteInfo, Consumer callback); + /** + * 移除某个微服务下的所有路由信息 + * + * @param serviceId 服务id + */ void remove(String serviceId); } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/param/ZuulParameterUtil.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/param/ZuulParameterUtil.java index ed8158ad..6e45a8b6 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/param/ZuulParameterUtil.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/param/ZuulParameterUtil.java @@ -89,7 +89,7 @@ public class ZuulParameterUtil { log.error("修改上传文件请求参数失败, apiParam:{}", apiParam, e); } } else if(HttpMethod.GET.name().equalsIgnoreCase(request.getMethod())) { - Map> newParams = new HashMap<>(); + Map> newParams = new HashMap<>(apiParam.size() * 2); for (Map.Entry entry : apiParam.entrySet()) { Object value = entry.getValue(); if (value instanceof List) { diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/easyopen/EasyopenServiceRouteController.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/easyopen/EasyopenServiceRouteController.java index c07623a2..afff6f8d 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/easyopen/EasyopenServiceRouteController.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/easyopen/EasyopenServiceRouteController.java @@ -7,6 +7,9 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.web.bind.annotation.RestController; +/** + * @author tanghc + */ @RestController public class EasyopenServiceRouteController extends ServiceRouteController implements ApplicationContextAware { diff --git a/sop-test/src/main/java/com/gitee/sop/test/Client.java b/sop-test/src/main/java/com/gitee/sop/test/Client.java index ce719139..a4c9e5a7 100644 --- a/sop-test/src/main/java/com/gitee/sop/test/Client.java +++ b/sop-test/src/main/java/com/gitee/sop/test/Client.java @@ -118,6 +118,12 @@ public class Client { } public interface Callback { + /** + * 请求成功后回调 + * + * @param requestInfo 请求信息 + * @param responseData 返回结果 + */ void callback(RequestInfo requestInfo, String responseData); } @@ -347,6 +353,7 @@ public class Client { /** * 返回json跟节点名称 + * * @return 返回json跟节点名称 */ public String getDataNode() { diff --git a/sop-test/src/main/java/com/gitee/sop/test/HttpTool.java b/sop-test/src/main/java/com/gitee/sop/test/HttpTool.java index 862e0662..9008bb8b 100644 --- a/sop-test/src/main/java/com/gitee/sop/test/HttpTool.java +++ b/sop-test/src/main/java/com/gitee/sop/test/HttpTool.java @@ -51,14 +51,17 @@ public class HttpTool { protected void initHttpClient(HttpToolConfig httpToolConfig) { httpClient = new OkHttpClient.Builder() - .connectTimeout(httpToolConfig.connectTimeoutSeconds, TimeUnit.SECONDS) // 设置链接超时时间,默认10秒 + // 设置链接超时时间,默认10秒 + .connectTimeout(httpToolConfig.connectTimeoutSeconds, TimeUnit.SECONDS) .readTimeout(httpToolConfig.readTimeoutSeconds, TimeUnit.SECONDS) .writeTimeout(httpToolConfig.writeTimeoutSeconds, TimeUnit.SECONDS) .cookieJar(new CookieJar() { + @Override public void saveFromResponse(HttpUrl httpUrl, List list) { cookieStore.put(httpUrl.host(), list); } + @Override public List loadForRequest(HttpUrl httpUrl) { List cookies = cookieStore.get(httpUrl.host()); return cookies != null ? cookies : new ArrayList(); @@ -211,9 +214,12 @@ public class HttpTool { 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()) ); } @@ -255,10 +261,15 @@ public class HttpTool { } public enum HTTPMethod { + /** http GET */ GET, + /** http POST */ POST, + /** http PUT */ PUT, + /** http HEAD */ HEAD, + /** http DELETE */ DELETE; private HTTPMethod() { diff --git a/sop-website/src/main/java/com/gitee/sop/websiteserver/bean/HttpTool.java b/sop-website/src/main/java/com/gitee/sop/websiteserver/bean/HttpTool.java index 0a4e455d..d1cac2e7 100644 --- a/sop-website/src/main/java/com/gitee/sop/websiteserver/bean/HttpTool.java +++ b/sop-website/src/main/java/com/gitee/sop/websiteserver/bean/HttpTool.java @@ -51,14 +51,17 @@ public class HttpTool { protected void initHttpClient(HttpToolConfig httpToolConfig) { httpClient = new OkHttpClient.Builder() - .connectTimeout(httpToolConfig.connectTimeoutSeconds, TimeUnit.SECONDS) // 设置链接超时时间,默认10秒 + // 设置链接超时时间,默认10秒 + .connectTimeout(httpToolConfig.connectTimeoutSeconds, TimeUnit.SECONDS) .readTimeout(httpToolConfig.readTimeoutSeconds, TimeUnit.SECONDS) .writeTimeout(httpToolConfig.writeTimeoutSeconds, TimeUnit.SECONDS) .cookieJar(new CookieJar() { + @Override public void saveFromResponse(HttpUrl httpUrl, List list) { cookieStore.put(httpUrl.host(), list); } + @Override public List loadForRequest(HttpUrl httpUrl) { List cookies = cookieStore.get(httpUrl.host()); return cookies != null ? cookies : new ArrayList(); @@ -211,9 +214,12 @@ public class HttpTool { 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()) ); } @@ -255,10 +261,15 @@ public class HttpTool { } public enum HTTPMethod { + /** http GET */ GET, + /** http POST */ POST, + /** http PUT */ PUT, + /** http HEAD */ HEAD, + /** http DELETE */ DELETE; private HTTPMethod() {