mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
新增restful模式
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
package com.gitee.sop.gateway.common;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
public final class SopConstants {
|
||||
|
||||
private SopConstants() {
|
||||
}
|
||||
|
||||
public static final Charset CHARSET_UTF8 = StandardCharsets.UTF_8;
|
||||
public static final String UTF8 = "UTF-8";
|
||||
public static final String NULL = "null";
|
||||
public static final String DUBBO_TAG = "dubbo.tag";
|
||||
public static final String OPEN_CONTEXT = "open.context";
|
||||
public static final String DEFAULT_VERSION = "1.0";
|
||||
|
||||
}
|
@@ -1,6 +1,5 @@
|
||||
package com.gitee.sop.gateway.controller;
|
||||
|
||||
import com.gitee.sop.gateway.common.SopConstants;
|
||||
import com.gitee.sop.gateway.request.ApiRequest;
|
||||
import com.gitee.sop.gateway.request.ApiRequestContext;
|
||||
import com.gitee.sop.gateway.response.Response;
|
||||
@@ -12,7 +11,6 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package com.gitee.sop.gateway.request;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.gitee.sop.support.context.WebContext;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
@@ -53,7 +53,7 @@ public class ApiRequestContext {
|
||||
private JSONObject rawParams;
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
* WEB Context
|
||||
*/
|
||||
private Map<String, String> headers;
|
||||
private WebContext webContext;
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@ package com.gitee.sop.gateway.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.gitee.sop.gateway.common.SopConstants;
|
||||
import com.gitee.sop.gateway.config.ApiConfig;
|
||||
import com.gitee.sop.gateway.request.ApiRequest;
|
||||
import com.gitee.sop.gateway.request.ApiRequestContext;
|
||||
@@ -14,6 +13,9 @@ import com.gitee.sop.gateway.service.ParamExecutor;
|
||||
import com.gitee.sop.gateway.service.Serde;
|
||||
import com.gitee.sop.gateway.util.RequestUtil;
|
||||
import com.gitee.sop.gateway.util.ResponseUtil;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -24,9 +26,11 @@ import org.springframework.http.MediaType;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 请求参数默认实现
|
||||
*
|
||||
@@ -93,10 +97,31 @@ public class ParamExecutorImpl implements ParamExecutor<HttpServletRequest, Http
|
||||
.uploadContext(uploadContext)
|
||||
.traceId(UUID.randomUUID().toString().replace("-", ""))
|
||||
.rawParams(params)
|
||||
.headers(RequestUtil.getHeaders(request))
|
||||
.webContext(buildWebContext(request))
|
||||
.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()));
|
||||
return defaultWebContext;
|
||||
}
|
||||
|
||||
|
||||
protected String getTag(HttpServletRequest request) {
|
||||
return request.getHeader(apiConfig.getHeaderKeyTag());
|
||||
|
@@ -4,7 +4,6 @@ import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.gitee.sop.gateway.common.ApiInfoDTO;
|
||||
import com.gitee.sop.gateway.common.ParamInfoDTO;
|
||||
import com.gitee.sop.gateway.common.SopConstants;
|
||||
import com.gitee.sop.gateway.exception.ApiException;
|
||||
import com.gitee.sop.gateway.exception.ExceptionExecutor;
|
||||
import com.gitee.sop.gateway.interceptor.RouteInterceptor;
|
||||
@@ -20,8 +19,10 @@ import com.gitee.sop.gateway.service.RouteService;
|
||||
import com.gitee.sop.gateway.service.Serde;
|
||||
import com.gitee.sop.gateway.service.validate.Validator;
|
||||
import com.gitee.sop.gateway.util.ClassUtil;
|
||||
import com.gitee.sop.support.constant.SopConstants;
|
||||
import com.gitee.sop.support.context.DefaultOpenContext;
|
||||
import com.gitee.sop.support.context.OpenContext;
|
||||
import com.gitee.sop.support.context.WebContext;
|
||||
import com.gitee.sop.support.dto.CommonFileData;
|
||||
import com.gitee.sop.support.dto.FileData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -108,7 +109,8 @@ public class RouteServiceImpl implements RouteService {
|
||||
String paramInfo = apiInfo.getParamInfo();
|
||||
List<ParamInfoDTO> paramInfoList = JSON.parseArray(paramInfo, ParamInfoDTO.class);
|
||||
OpenContext openRequest = buildOpenContext(apiRequestContext);
|
||||
clientAttachment.setAttachment(SopConstants.OPEN_CONTEXT, JSON.toJSONString(openRequest));
|
||||
clientAttachment.setObjectAttachment(SopConstants.OPEN_CONTEXT, openRequest);
|
||||
clientAttachment.setObjectAttachment(SopConstants.WEB_CONTEXT, apiRequestContext.getWebContext());
|
||||
return genericServiceInvoker.invoke(
|
||||
apiInfo.getInterfaceClassName(),
|
||||
apiInfo.getMethodName(),
|
||||
@@ -156,6 +158,8 @@ public class RouteServiceImpl implements RouteService {
|
||||
// 上下文
|
||||
if (Objects.equals(type, OpenContext.class.getName())) {
|
||||
params.add(openRequest);
|
||||
} else if (Objects.equals(type, WebContext.class.getName())) {
|
||||
params.add(apiRequestContext.getWebContext());
|
||||
} else if (Objects.equals(type, FileData.class.getName()) || Objects.equals(actualType, FileData.class.getName())) {
|
||||
// 处理文件上传
|
||||
Optional<Object> fileParam = buildFileParam(apiRequestContext, paramInfoDTO);
|
||||
@@ -203,8 +207,6 @@ 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;
|
||||
}
|
||||
|
@@ -2,10 +2,10 @@ package com.gitee.sop.gateway.service.manager.impl;
|
||||
|
||||
import com.gitee.sop.gateway.common.ApiInfoDTO;
|
||||
import com.gitee.sop.gateway.common.CacheKey;
|
||||
import com.gitee.sop.gateway.common.SopConstants;
|
||||
import com.gitee.sop.gateway.dao.entity.IsvInfo;
|
||||
import com.gitee.sop.gateway.dao.mapper.IsvInfoMapper;
|
||||
import com.gitee.sop.gateway.util.JsonUtil;
|
||||
import com.gitee.sop.support.constant.SopConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.BoundHashOperations;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package com.gitee.sop.gateway.service.manager.impl;
|
||||
|
||||
import com.gitee.sop.gateway.common.CacheKey;
|
||||
import com.gitee.sop.gateway.common.SopConstants;
|
||||
import com.gitee.sop.gateway.dao.entity.IsvInfo;
|
||||
import com.gitee.sop.gateway.service.manager.dto.IsvDTO;
|
||||
import com.gitee.sop.gateway.util.CopyUtil;
|
||||
import com.gitee.sop.gateway.util.JsonUtil;
|
||||
import com.gitee.sop.support.constant.SopConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package com.gitee.sop.gateway.service.manager.impl;
|
||||
|
||||
import com.gitee.sop.gateway.common.CacheKey;
|
||||
import com.gitee.sop.gateway.common.SopConstants;
|
||||
import com.gitee.sop.gateway.dao.entity.IsvKeys;
|
||||
import com.gitee.sop.support.constant.SopConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.gitee.sop.gateway.service.validate;
|
||||
|
||||
|
||||
import com.gitee.sop.gateway.common.SopConstants;
|
||||
|
||||
import com.gitee.sop.support.constant.SopConstants;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package com.gitee.sop.gateway.util;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.gitee.sop.gateway.common.SopConstants;
|
||||
import com.gitee.sop.gateway.request.ApiUploadContext;
|
||||
import com.gitee.sop.gateway.request.UploadContext;
|
||||
import com.gitee.sop.support.constant.SopConstants;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
|
Reference in New Issue
Block a user