【fix sonar】HttpUtils文件
This commit is contained in:
+15
-13
@@ -1,8 +1,8 @@
|
|||||||
package com.jero.config.sign.util;
|
package com.jero.config.sign.util;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSON;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import com.jero.common.util.oConvertUtils;
|
import com.jero.common.util.oConvertUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -11,10 +11,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.SortedMap;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http 工具类 获取请求中的参数
|
* http 工具类 获取请求中的参数
|
||||||
@@ -25,6 +22,10 @@ import java.util.TreeMap;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class HttpUtils {
|
public class HttpUtils {
|
||||||
|
|
||||||
|
private HttpUtils(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将URL的参数和body参数合并
|
* 将URL的参数和body参数合并
|
||||||
*
|
*
|
||||||
@@ -41,7 +42,7 @@ public class HttpUtils {
|
|||||||
log.info(" pathVariable: {}",pathVariable);
|
log.info(" pathVariable: {}",pathVariable);
|
||||||
String deString = URLDecoder.decode(pathVariable, "UTF-8");
|
String deString = URLDecoder.decode(pathVariable, "UTF-8");
|
||||||
log.info(" pathVariable decode: {}",deString);
|
log.info(" pathVariable decode: {}",deString);
|
||||||
result.put(SignUtil.xPathVariable, deString);
|
result.put(SignUtil.X_PATH_VARIABLE, deString);
|
||||||
}
|
}
|
||||||
// 获取URL上的参数
|
// 获取URL上的参数
|
||||||
Map<String, String> urlParams = getUrlParams(request);
|
Map<String, String> urlParams = getUrlParams(request);
|
||||||
@@ -79,7 +80,7 @@ public class HttpUtils {
|
|||||||
log.info(" pathVariable: {}",pathVariable);
|
log.info(" pathVariable: {}",pathVariable);
|
||||||
String deString = URLDecoder.decode(pathVariable, "UTF-8");
|
String deString = URLDecoder.decode(pathVariable, "UTF-8");
|
||||||
log.info(" pathVariable decode: {}",deString);
|
log.info(" pathVariable decode: {}",deString);
|
||||||
result.put(SignUtil.xPathVariable, deString);
|
result.put(SignUtil.X_PATH_VARIABLE, deString);
|
||||||
}
|
}
|
||||||
// 获取URL上的参数
|
// 获取URL上的参数
|
||||||
Map<String, String> urlParams = getUrlParams(queryString);
|
Map<String, String> urlParams = getUrlParams(queryString);
|
||||||
@@ -105,8 +106,9 @@ public class HttpUtils {
|
|||||||
*
|
*
|
||||||
* @date 15:04 20210621
|
* @date 15:04 20210621
|
||||||
* @param request
|
* @param request
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Map<String, String> getAllRequestParam(final HttpServletRequest request) throws IOException {
|
public static Map getAllRequestParam(final HttpServletRequest request) throws IOException {
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
|
||||||
String str = "";
|
String str = "";
|
||||||
@@ -116,7 +118,7 @@ public class HttpUtils {
|
|||||||
wholeStr.append(str);
|
wholeStr.append(str);
|
||||||
}
|
}
|
||||||
// 转化成json对象
|
// 转化成json对象
|
||||||
return JSONObject.parseObject(wholeStr.toString(), Map.class);
|
return JSON.parseObject(wholeStr.toString(), Map.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,13 +127,13 @@ public class HttpUtils {
|
|||||||
* @date 15:04 20210621
|
* @date 15:04 20210621
|
||||||
* @param body
|
* @param body
|
||||||
*/
|
*/
|
||||||
public static Map<String, String> getAllRequestParam(final byte[] body) throws IOException {
|
public static Map<String, String> getAllRequestParam(final byte[] body){
|
||||||
if(body==null){
|
if(body==null){
|
||||||
return null;
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
String wholeStr = new String(body);
|
String wholeStr = new String(body);
|
||||||
// 转化成json对象
|
// 转化成json对象
|
||||||
return JSONObject.parseObject(wholeStr.toString(), Map.class);
|
return JSON.parseObject(wholeStr, Map.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user