|
|
@ -56,6 +56,8 @@ public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver { |
|
|
|
|
|
|
|
|
|
|
|
private final Map<MethodParameter, HandlerMethodArgumentResolver> argumentResolverCache = new ConcurrentHashMap<>(256); |
|
|
|
private final Map<MethodParameter, HandlerMethodArgumentResolver> argumentResolverCache = new ConcurrentHashMap<>(256); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<MethodParameter> NEED_INIT_OPEN_CONTEXT = new ArrayList<>(16); |
|
|
|
|
|
|
|
|
|
|
|
private ParamValidator paramValidator = new ServiceParamValidator(); |
|
|
|
private ParamValidator paramValidator = new ServiceParamValidator(); |
|
|
|
|
|
|
|
|
|
|
|
private static Class<?> pushBuilder; |
|
|
|
private static Class<?> pushBuilder; |
|
|
@ -89,8 +91,8 @@ public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
Class<?> paramType = methodParameter.getParameterType(); |
|
|
|
Class<?> paramType = methodParameter.getParameterType(); |
|
|
|
// 排除的
|
|
|
|
// 特殊参数
|
|
|
|
boolean exclude = ( |
|
|
|
boolean special = ( |
|
|
|
WebRequest.class.isAssignableFrom(paramType) || |
|
|
|
WebRequest.class.isAssignableFrom(paramType) || |
|
|
|
ServletRequest.class.isAssignableFrom(paramType) || |
|
|
|
ServletRequest.class.isAssignableFrom(paramType) || |
|
|
|
MultipartRequest.class.isAssignableFrom(paramType) || |
|
|
|
MultipartRequest.class.isAssignableFrom(paramType) || |
|
|
@ -107,12 +109,17 @@ public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver { |
|
|
|
OutputStream.class.isAssignableFrom(paramType) || |
|
|
|
OutputStream.class.isAssignableFrom(paramType) || |
|
|
|
Writer.class.isAssignableFrom(paramType) |
|
|
|
Writer.class.isAssignableFrom(paramType) |
|
|
|
); |
|
|
|
); |
|
|
|
// 除此之外都匹配
|
|
|
|
// 特殊参数只需要初始化OpenContext
|
|
|
|
boolean support = !exclude; |
|
|
|
if (special) { |
|
|
|
if (support) { |
|
|
|
NEED_INIT_OPEN_CONTEXT.add(methodParameter); |
|
|
|
|
|
|
|
} |
|
|
|
this.wrapSingleParam(methodParameter, open); |
|
|
|
this.wrapSingleParam(methodParameter, open); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return support; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isOnlyInitOpenContext(MethodParameter methodParameter) { |
|
|
|
|
|
|
|
return NEED_INIT_OPEN_CONTEXT.contains(methodParameter); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -136,6 +143,20 @@ public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver { |
|
|
|
, NativeWebRequest nativeWebRequest |
|
|
|
, NativeWebRequest nativeWebRequest |
|
|
|
, WebDataBinderFactory webDataBinderFactory |
|
|
|
, WebDataBinderFactory webDataBinderFactory |
|
|
|
) throws Exception { |
|
|
|
) throws Exception { |
|
|
|
|
|
|
|
// 特殊参数只需要初始化OpenContext
|
|
|
|
|
|
|
|
if (isOnlyInitOpenContext(methodParameter)) { |
|
|
|
|
|
|
|
this.initOpenContextImpl(nativeWebRequest); |
|
|
|
|
|
|
|
HandlerMethodArgumentResolver resolver = getOtherArgumentResolver(methodParameter); |
|
|
|
|
|
|
|
if (resolver != null) { |
|
|
|
|
|
|
|
return resolver.resolveArgument( |
|
|
|
|
|
|
|
methodParameter |
|
|
|
|
|
|
|
, modelAndViewContainer |
|
|
|
|
|
|
|
, nativeWebRequest |
|
|
|
|
|
|
|
, webDataBinderFactory |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
nativeWebRequest = new SopServletWebRequest( |
|
|
|
nativeWebRequest = new SopServletWebRequest( |
|
|
|
(HttpServletRequest) nativeWebRequest.getNativeRequest(), |
|
|
|
(HttpServletRequest) nativeWebRequest.getNativeRequest(), |
|
|
|
(HttpServletResponse) nativeWebRequest.getNativeResponse() |
|
|
|
(HttpServletResponse) nativeWebRequest.getNativeResponse() |
|
|
@ -170,6 +191,14 @@ public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private OpenContextImpl initOpenContextImpl(NativeWebRequest nativeWebRequest) { |
|
|
|
|
|
|
|
HttpServletRequest request = (HttpServletRequest) nativeWebRequest.getNativeRequest(); |
|
|
|
|
|
|
|
ServiceContext currentContext = ServiceContext.getCurrentContext(); |
|
|
|
|
|
|
|
JSONObject requestParams = OpenUtil.getRequestParams(request); |
|
|
|
|
|
|
|
OpenContextImpl openContext = new OpenContextImpl(requestParams); |
|
|
|
|
|
|
|
currentContext.setOpenContext(openContext); |
|
|
|
|
|
|
|
return openContext; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取参数对象,将request中的参数绑定到实体对象中去 |
|
|
|
* 获取参数对象,将request中的参数绑定到实体对象中去 |
|
|
@ -180,11 +209,10 @@ public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected Object getParamObject(MethodParameter methodParameter, NativeWebRequest nativeWebRequest) { |
|
|
|
protected Object getParamObject(MethodParameter methodParameter, NativeWebRequest nativeWebRequest) { |
|
|
|
HttpServletRequest request = (HttpServletRequest) nativeWebRequest.getNativeRequest(); |
|
|
|
HttpServletRequest request = (HttpServletRequest) nativeWebRequest.getNativeRequest(); |
|
|
|
ServiceContext currentContext = ServiceContext.getCurrentContext(); |
|
|
|
OpenContextImpl openContext = initOpenContextImpl(nativeWebRequest); |
|
|
|
JSONObject requestParams = OpenUtil.getRequestParams(request); |
|
|
|
Map<String, Object> requestParams = openContext.getParameterMap(); |
|
|
|
OpenContextImpl openContext = new OpenContextImpl(requestParams); |
|
|
|
Object bizObj = requestParams.get(ParamNames.BIZ_CONTENT_NAME); |
|
|
|
currentContext.setOpenContext(openContext); |
|
|
|
String bizContent = bizObj == null ? null : bizObj.toString(); |
|
|
|
String bizContent = requestParams.getString(ParamNames.BIZ_CONTENT_NAME); |
|
|
|
|
|
|
|
if (bizContent == null) { |
|
|
|
if (bizContent == null) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|