|
|
@@ -1,5 +1,6 @@
|
|
|
package com.nb.common.config;
|
|
|
|
|
|
+import lombok.SneakyThrows;
|
|
|
import org.springframework.util.StreamUtils;
|
|
|
|
|
|
import javax.servlet.ReadListener;
|
|
|
@@ -11,30 +12,43 @@ import javax.servlet.http.Part;
|
|
|
import java.io.*;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Properties;
|
|
|
|
|
|
public class CacheHttpServletRequestWrapper extends HttpServletRequestWrapper {
|
|
|
|
|
|
private final byte[] body;
|
|
|
private String bodyString;
|
|
|
+ private Map<String,String> 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]);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public String getBodyString() {
|
|
|
return this.bodyString;
|
|
|
}
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
@Override
|
|
|
public String getParameter(String name) {
|
|
|
- return super.getParameter(name);
|
|
|
+ String parameter = super.getParameter(name);
|
|
|
+ return parameter==null?this.bodyParams.get(name):parameter;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public BufferedReader getReader() throws IOException {
|
|
|
return new BufferedReader(new InputStreamReader(getInputStream(),Charset.defaultCharset()));
|