mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
优化dubbo filter
This commit is contained in:
@@ -5,6 +5,7 @@ import com.gitee.sop.gateway.request.ApiRequestContext;
|
|||||||
import com.gitee.sop.gateway.response.Response;
|
import com.gitee.sop.gateway.response.Response;
|
||||||
import com.gitee.sop.gateway.service.ParamExecutor;
|
import com.gitee.sop.gateway.service.ParamExecutor;
|
||||||
import com.gitee.sop.gateway.service.RouteService;
|
import com.gitee.sop.gateway.service.RouteService;
|
||||||
|
import com.gitee.sop.gateway.util.RequestUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -95,6 +96,7 @@ public class IndexController {
|
|||||||
apiRequest.setMethod(apiName);
|
apiRequest.setMethod(apiName);
|
||||||
apiRequest.setVersion(v);
|
apiRequest.setVersion(v);
|
||||||
apiRequestContext.setIsRest(true);
|
apiRequestContext.setIsRest(true);
|
||||||
|
apiRequestContext.setWebContext(RequestUtil.buildWebContext(request));
|
||||||
Response apiResponse = restRouteService.route(apiRequestContext);
|
Response apiResponse = restRouteService.route(apiRequestContext);
|
||||||
paramExecutor.write(apiRequestContext, apiResponse, response);
|
paramExecutor.write(apiRequestContext, apiResponse, response);
|
||||||
}
|
}
|
||||||
|
@@ -14,8 +14,6 @@ import com.gitee.sop.gateway.service.Serde;
|
|||||||
import com.gitee.sop.gateway.util.RequestUtil;
|
import com.gitee.sop.gateway.util.RequestUtil;
|
||||||
import com.gitee.sop.gateway.util.ResponseUtil;
|
import com.gitee.sop.gateway.util.ResponseUtil;
|
||||||
import com.gitee.sop.support.constant.SopConstants;
|
import com.gitee.sop.support.constant.SopConstants;
|
||||||
import com.gitee.sop.support.context.DefaultWebContext;
|
|
||||||
import com.gitee.sop.support.context.WebContext;
|
|
||||||
import com.gitee.sop.support.dto.FileData;
|
import com.gitee.sop.support.dto.FileData;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
@@ -26,11 +24,9 @@ import org.springframework.http.MediaType;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求参数默认实现
|
* 请求参数默认实现
|
||||||
*
|
*
|
||||||
@@ -96,32 +92,10 @@ public class ParamExecutorImpl implements ParamExecutor<HttpServletRequest, Http
|
|||||||
.uploadContext(uploadContext)
|
.uploadContext(uploadContext)
|
||||||
.traceId(UUID.randomUUID().toString().replace("-", ""))
|
.traceId(UUID.randomUUID().toString().replace("-", ""))
|
||||||
.rawParams(params)
|
.rawParams(params)
|
||||||
.webContext(buildWebContext(request))
|
.isRest(false)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected WebContext buildWebContext(HttpServletRequest request) {
|
|
||||||
DefaultWebContext defaultWebContext = new DefaultWebContext();
|
|
||||||
defaultWebContext.setMethod(request.getMethod());
|
|
||||||
defaultWebContext.setPathInfo(request.getPathInfo());
|
|
||||||
defaultWebContext.setPathTranslated(request.getPathTranslated());
|
|
||||||
defaultWebContext.setContextPath(request.getContextPath());
|
|
||||||
defaultWebContext.setQueryString(request.getQueryString());
|
|
||||||
defaultWebContext.setRequestURI(request.getRequestURI());
|
|
||||||
defaultWebContext.setRequestURL(request.getRequestURL());
|
|
||||||
defaultWebContext.setServletPath(request.getServletPath());
|
|
||||||
defaultWebContext.setContentLength(request.getContentLength());
|
|
||||||
defaultWebContext.setContentType(request.getContentType());
|
|
||||||
defaultWebContext.setRemoteAddr(request.getRemoteAddr());
|
|
||||||
defaultWebContext.setRemoteHost(request.getRemoteHost());
|
|
||||||
defaultWebContext.setRemotePort(request.getRemotePort());
|
|
||||||
defaultWebContext.setLocale(request.getLocale());
|
|
||||||
defaultWebContext.setHeaders(RequestUtil.getHeaders(request));
|
|
||||||
defaultWebContext.setParamtreMap(new LinkedHashMap<>(request.getParameterMap()));
|
|
||||||
defaultWebContext.setRealIp(RequestUtil.getIP(request));
|
|
||||||
return defaultWebContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected ApiRequest convertApiRequest(HttpServletRequest request, JSONObject jsonObject) {
|
protected ApiRequest convertApiRequest(HttpServletRequest request, JSONObject jsonObject) {
|
||||||
ApiRequest apiRequest = new ApiRequest();
|
ApiRequest apiRequest = new ApiRequest();
|
||||||
|
@@ -120,7 +120,9 @@ public class RouteServiceImpl implements RouteService {
|
|||||||
List<ParamInfoDTO> paramInfoList = JSON.parseArray(paramInfo, ParamInfoDTO.class);
|
List<ParamInfoDTO> paramInfoList = JSON.parseArray(paramInfo, ParamInfoDTO.class);
|
||||||
OpenContext openRequest = buildOpenContext(apiRequestContext);
|
OpenContext openRequest = buildOpenContext(apiRequestContext);
|
||||||
clientAttachment.setObjectAttachment(SopConstants.OPEN_CONTEXT, openRequest);
|
clientAttachment.setObjectAttachment(SopConstants.OPEN_CONTEXT, openRequest);
|
||||||
clientAttachment.setObjectAttachment(SopConstants.WEB_CONTEXT, apiRequestContext.getWebContext());
|
if (apiRequestContext.getIsRest()) {
|
||||||
|
clientAttachment.setObjectAttachment(SopConstants.WEB_CONTEXT, apiRequestContext.getWebContext());
|
||||||
|
}
|
||||||
return genericServiceInvoker.invoke(
|
return genericServiceInvoker.invoke(
|
||||||
apiInfo.getInterfaceClassName(),
|
apiInfo.getInterfaceClassName(),
|
||||||
apiInfo.getMethodName(),
|
apiInfo.getMethodName(),
|
||||||
|
@@ -4,6 +4,8 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import com.gitee.sop.gateway.request.ApiUploadContext;
|
import com.gitee.sop.gateway.request.ApiUploadContext;
|
||||||
import com.gitee.sop.gateway.request.UploadContext;
|
import com.gitee.sop.gateway.request.UploadContext;
|
||||||
import com.gitee.sop.support.constant.SopConstants;
|
import com.gitee.sop.support.constant.SopConstants;
|
||||||
|
import com.gitee.sop.support.context.DefaultWebContext;
|
||||||
|
import com.gitee.sop.support.context.WebContext;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.fileupload.FileItem;
|
import org.apache.commons.fileupload.FileItem;
|
||||||
@@ -181,6 +183,28 @@ public class RequestUtil {
|
|||||||
return uploadInfo;
|
return uploadInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static WebContext buildWebContext(HttpServletRequest request) {
|
||||||
|
DefaultWebContext defaultWebContext = new DefaultWebContext();
|
||||||
|
defaultWebContext.setMethod(request.getMethod());
|
||||||
|
defaultWebContext.setPathInfo(request.getPathInfo());
|
||||||
|
defaultWebContext.setPathTranslated(request.getPathTranslated());
|
||||||
|
defaultWebContext.setContextPath(request.getContextPath());
|
||||||
|
defaultWebContext.setQueryString(request.getQueryString());
|
||||||
|
defaultWebContext.setRequestURI(request.getRequestURI());
|
||||||
|
defaultWebContext.setRequestURL(request.getRequestURL());
|
||||||
|
defaultWebContext.setServletPath(request.getServletPath());
|
||||||
|
defaultWebContext.setContentLength(request.getContentLength());
|
||||||
|
defaultWebContext.setContentType(request.getContentType());
|
||||||
|
defaultWebContext.setRemoteAddr(request.getRemoteAddr());
|
||||||
|
defaultWebContext.setRemoteHost(request.getRemoteHost());
|
||||||
|
defaultWebContext.setRemotePort(request.getRemotePort());
|
||||||
|
defaultWebContext.setLocale(request.getLocale());
|
||||||
|
defaultWebContext.setHeaders(RequestUtil.getHeaders(request));
|
||||||
|
defaultWebContext.setParamtreMap(new LinkedHashMap<>(request.getParameterMap()));
|
||||||
|
defaultWebContext.setRealIp(RequestUtil.getIP(request));
|
||||||
|
return defaultWebContext;
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class UploadInfo {
|
public static class UploadInfo {
|
||||||
private JSONObject apiParam;
|
private JSONObject apiParam;
|
||||||
|
Reference in New Issue
Block a user