pull/1/head
tanghc 5 years ago
parent ba7f9a4e4d
commit 6c9f5528f2
  1. 19
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/HttpTool.java
  2. 6
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/ByteArrayStreamWrapper.java
  3. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/RequestContentDataExtractor.java
  4. 11
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/RouteLoader.java
  5. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/param/ZuulParameterUtil.java
  6. 3
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/easyopen/EasyopenServiceRouteController.java
  7. 7
      sop-test/src/main/java/com/gitee/sop/test/Client.java
  8. 19
      sop-test/src/main/java/com/gitee/sop/test/HttpTool.java
  9. 19
      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<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>();
@ -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() {

@ -20,15 +20,17 @@ public class ByteArrayStreamWrapper extends ServletInputStream {
* @param data a <code>byte[]</code> 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;

@ -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<String, Object> extract(HttpServletRequest request) throws IOException {
return (request instanceof MultipartHttpServletRequest) ?

@ -8,7 +8,18 @@ import java.util.function.Consumer;
* @author tanghc
*/
public interface RouteLoader {
/**
* 加载路由
*
* @param serviceRouteInfo 服务路由信息
* @param callback 加载成功后回调
*/
void load(ServiceRouteInfo serviceRouteInfo, Consumer<Object> callback);
/**
* 移除某个微服务下的所有路由信息
*
* @param serviceId 服务id
*/
void remove(String serviceId);
}

@ -89,7 +89,7 @@ public class ZuulParameterUtil {
log.error("修改上传文件请求参数失败, apiParam:{}", apiParam, e);
}
} else if(HttpMethod.GET.name().equalsIgnoreCase(request.getMethod())) {
Map<String, List<String>> newParams = new HashMap<>();
Map<String, List<String>> newParams = new HashMap<>(apiParam.size() * 2);
for (Map.Entry<String, Object> entry : apiParam.entrySet()) {
Object value = entry.getValue();
if (value instanceof List) {

@ -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 {

@ -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() {

@ -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<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>();
@ -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() {

@ -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<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>();
@ -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() {

Loading…
Cancel
Save