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