|
|
@@ -1,5 +1,8 @@
|
|
|
package cn.tr.plugin.web.wrapper;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import cn.tr.core.utils.JsonUtils;
|
|
|
import org.springframework.util.StreamUtils;
|
|
|
|
|
|
import javax.servlet.ReadListener;
|
|
|
@@ -24,17 +27,21 @@ public class CacheHttpServletRequestWrapper extends HttpServletRequestWrapper {
|
|
|
|
|
|
private final byte[] body;
|
|
|
private String bodyString;
|
|
|
- private Map<String, String> bodyParams=new HashMap<>();
|
|
|
+ private Map<String, Object> bodyParams=new HashMap<>();
|
|
|
|
|
|
public CacheHttpServletRequestWrapper(HttpServletRequest request) throws IOException {
|
|
|
super(request);
|
|
|
this.bodyString = StreamUtils.copyToString(request.getInputStream(), Charset.defaultCharset());
|
|
|
body = bodyString.getBytes(Charset.defaultCharset());
|
|
|
- String[] split = bodyString.split("&");
|
|
|
- for (String param : split) {
|
|
|
- String[] spl = param.split("=");
|
|
|
- if(spl.length>1){
|
|
|
- bodyParams.put(spl[0],spl[1]);
|
|
|
+ if(JSONUtil.isTypeJSON(bodyString)){
|
|
|
+ bodyParams= JsonUtils.parseMap(bodyString);
|
|
|
+ }else {
|
|
|
+ String[] split = bodyString.split("&");
|
|
|
+ for (String param : split) {
|
|
|
+ String[] spl = param.split("=");
|
|
|
+ if(spl.length>1){
|
|
|
+ bodyParams.put(spl[0],spl[1]);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -46,7 +53,8 @@ public class CacheHttpServletRequestWrapper extends HttpServletRequestWrapper {
|
|
|
@Override
|
|
|
public String getParameter(String name) {
|
|
|
String parameter = super.getParameter(name);
|
|
|
- return parameter==null?this.bodyParams.get(name):parameter;
|
|
|
+ Object o = this.bodyParams.get(name);
|
|
|
+ return parameter==null?(ObjectUtil.isNull(o)?null:String.valueOf(o)):parameter;
|
|
|
}
|
|
|
|
|
|
|