mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
新增restful模式
This commit is contained in:
@@ -6,6 +6,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
@@ -50,4 +51,9 @@ public class ApiRequestContext {
|
||||
* 原始参数
|
||||
*/
|
||||
private JSONObject rawParams;
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
private Map<String, String> headers;
|
||||
}
|
||||
|
@@ -93,9 +93,11 @@ public class ParamExecutorImpl implements ParamExecutor<HttpServletRequest, Http
|
||||
.uploadContext(uploadContext)
|
||||
.traceId(UUID.randomUUID().toString().replace("-", ""))
|
||||
.rawParams(params)
|
||||
.headers(RequestUtil.getHeaders(request))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
protected String getTag(HttpServletRequest request) {
|
||||
return request.getHeader(apiConfig.getHeaderKeyTag());
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ import com.gitee.sop.support.dto.FileData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.common.utils.ClassUtils;
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
import org.apache.dubbo.rpc.RpcContextAttachment;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -100,13 +101,14 @@ public class RouteServiceImpl implements RouteService {
|
||||
protected Object doRoute(ApiRequestContext apiRequestContext, ApiInfoDTO apiInfo) {
|
||||
String tag = apiRequestContext.getTag();
|
||||
// 设置隔离环境
|
||||
RpcContextAttachment clientAttachment = RpcContext.getClientAttachment();
|
||||
if (StringUtils.hasText(tag)) {
|
||||
RpcContext.getClientAttachment().setAttachment(SopConstants.DUBBO_TAG, tag);
|
||||
clientAttachment.setAttachment(SopConstants.DUBBO_TAG, tag);
|
||||
}
|
||||
String paramInfo = apiInfo.getParamInfo();
|
||||
List<ParamInfoDTO> paramInfoList = JSON.parseArray(paramInfo, ParamInfoDTO.class);
|
||||
OpenContext openRequest = buildOpenContext(apiRequestContext);
|
||||
RpcContext.getClientAttachment().setAttachment(SopConstants.OPEN_CONTEXT, JSON.toJSONString(openRequest));
|
||||
clientAttachment.setAttachment(SopConstants.OPEN_CONTEXT, JSON.toJSONString(openRequest));
|
||||
return genericServiceInvoker.invoke(
|
||||
apiInfo.getInterfaceClassName(),
|
||||
apiInfo.getMethodName(),
|
||||
@@ -201,6 +203,7 @@ public class RouteServiceImpl implements RouteService {
|
||||
defaultOpenRequest.setNotifyUrl(apiRequest.getNotifyUrl());
|
||||
defaultOpenRequest.setTraceId(apiRequestContext.getTraceId());
|
||||
defaultOpenRequest.setLocale(apiRequestContext.getLocale());
|
||||
defaultOpenRequest.setHeaders(apiRequestContext.getHeaders());
|
||||
|
||||
defaultOpenRequest.initContext();
|
||||
return defaultOpenRequest;
|
||||
|
@@ -21,6 +21,8 @@ import java.net.InetAddress;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -108,6 +110,17 @@ public class RequestUtil {
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public static Map<String, String> getHeaders(HttpServletRequest request) {
|
||||
Enumeration<String> headerNames = request.getHeaderNames();
|
||||
Map<String, String> headers = new LinkedHashMap<>();
|
||||
if (headerNames.hasMoreElements()) {
|
||||
String name = headerNames.nextElement();
|
||||
String value = request.getHeader(name);
|
||||
headers.put(name, value);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上传文件内容
|
||||
*
|
||||
|
Reference in New Issue
Block a user