修改请求日志输出所有相应数据导致日志太大的问题
parent
88d6b40fb5
commit
e99562c417
|
@ -27,6 +27,8 @@ public class ResponeVo implements HttpResponse {
|
|||
* 相应内容
|
||||
*/
|
||||
private String entityString;
|
||||
|
||||
private Map<String, Object> entityMap;
|
||||
/**
|
||||
* 相应头信息
|
||||
*/
|
||||
|
@ -39,7 +41,6 @@ public class ResponeVo implements HttpResponse {
|
|||
|
||||
private Map<String, Object> requestData;
|
||||
|
||||
|
||||
private HttpResponse response;
|
||||
|
||||
public int getCode() {
|
||||
|
@ -68,11 +69,15 @@ public class ResponeVo implements HttpResponse {
|
|||
* @return 资源皇后的map集合
|
||||
* @throws JsonProcessingException JSON转换异常
|
||||
*/
|
||||
@Deprecated
|
||||
public Map<String, Object> getEntityMap() throws JsonProcessingException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.readValue(this.getEntityString(), Map.class);
|
||||
}
|
||||
|
||||
public Map<String, Object> getResponseMap(){
|
||||
return this.entityMap;
|
||||
}
|
||||
/**
|
||||
* 根据相应结果,转化为实体类
|
||||
*
|
||||
|
@ -81,11 +86,21 @@ public class ResponeVo implements HttpResponse {
|
|||
* @return 转换后的实体类
|
||||
* @throws JsonProcessingException JSON转换异常
|
||||
*/
|
||||
@Deprecated
|
||||
public <T> T getEntity(Class<T> clazz) throws JsonProcessingException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.readValue(this.getEntityString(), clazz);
|
||||
}
|
||||
|
||||
public <T> T getResponseEntity(Class<T> clazz) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
return mapper.readValue(this.getEntityString(), clazz);
|
||||
} catch (JsonProcessingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据相应结果,转化为实体类
|
||||
*
|
||||
|
@ -98,6 +113,45 @@ public class ResponeVo implements HttpResponse {
|
|||
return mapper.readValue(this.getEntityString(), typeReference);
|
||||
}
|
||||
|
||||
public String getEntityString() {
|
||||
return entityString;
|
||||
}
|
||||
|
||||
public void setEntityString(String entityString) {
|
||||
this.entityString = entityString;
|
||||
try{
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
this.entityMap = mapper.readValue(this.getEntityString(), Map.class);
|
||||
}catch (Exception ignore){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(InputStream content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public byte[] getContentByteArr() {
|
||||
return contentByteArr;
|
||||
}
|
||||
|
||||
public void setContentByteArr(byte[] contentByteArr) {
|
||||
this.contentByteArr = contentByteArr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResponeVo{" +
|
||||
"code=" + code +
|
||||
", entityString='" + entityString + '\'' +
|
||||
", otherParam=" + requestData +
|
||||
'}';
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据相应结果转化为实体集合
|
||||
*
|
||||
|
@ -243,37 +297,6 @@ public class ResponeVo implements HttpResponse {
|
|||
}
|
||||
|
||||
|
||||
public String getEntityString() {
|
||||
return entityString;
|
||||
}
|
||||
|
||||
public void setEntityString(String entityString) {
|
||||
this.entityString = entityString;
|
||||
}
|
||||
|
||||
public InputStream getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(InputStream content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public byte[] getContentByteArr() {
|
||||
return contentByteArr;
|
||||
}
|
||||
|
||||
public void setContentByteArr(byte[] contentByteArr) {
|
||||
this.contentByteArr = contentByteArr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResponeVo{" +
|
||||
"code=" + code +
|
||||
", entityString='" + entityString + '\'' +
|
||||
", otherParam=" + requestData +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson.annotation.JSONField;
|
|||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>http请求信息</h1>
|
||||
|
@ -27,5 +28,7 @@ public class HttpUtilParamInfo {
|
|||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date responseDate;
|
||||
|
||||
private Map<String,Object> responseMap;
|
||||
private String responseString;
|
||||
private ResponeVo response;
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ import aiyh.utils.zwl.common.ToolUtil;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.support.spring.PropertyPreFilters;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
|
@ -57,6 +57,8 @@ public class HttpUtils {
|
|||
* basic 认证
|
||||
*/
|
||||
private CredentialsProvider credentialsProvider = null;
|
||||
private final PropertyPreFilters filters = new PropertyPreFilters();
|
||||
private final PropertyPreFilters.MySimplePropertyPreFilter excludefilter = filters.addFilter();
|
||||
|
||||
{
|
||||
// private final ExecutorService executorService = Executors.newFixedThreadPool(3);
|
||||
|
@ -67,6 +69,8 @@ public class HttpUtils {
|
|||
new LinkedBlockingQueue<>(1024),
|
||||
threadFactory,
|
||||
new ThreadPoolExecutor.AbortPolicy());
|
||||
String[] excludeProperties = {"locale","contentByteArr","response"};
|
||||
excludefilter.addExcludes(excludeProperties);
|
||||
}
|
||||
|
||||
public HttpUtils() {
|
||||
|
@ -638,10 +642,16 @@ public class HttpUtils {
|
|||
httpUtilParamInfo = new HttpUtilParamInfo();
|
||||
}
|
||||
httpUtilParamInfo.setResponse(apply);
|
||||
if(apply.getResponseMap() == null){
|
||||
httpUtilParamInfo.setResponseString(apply.getEntityString());
|
||||
}else {
|
||||
httpUtilParamInfo.setResponseMap(apply.getResponseMap());
|
||||
}
|
||||
httpUtilParamInfo.setResponseDate(new Date());
|
||||
try {
|
||||
log.info(Util.logStr("url [{}] request info : [\n{}\n];", httpUtilParamInfo.getUrl(),
|
||||
JSONObject.toJSONString(httpUtilParamInfo,
|
||||
excludefilter,
|
||||
SerializerFeature.PrettyFormat,
|
||||
SerializerFeature.WriteDateUseDateFormat)));
|
||||
} catch (Exception ignore) {
|
||||
|
@ -669,11 +679,17 @@ public class HttpUtils {
|
|||
httpUtilParamInfo = new HttpUtilParamInfo();
|
||||
}
|
||||
httpUtilParamInfo.setResponse(apply);
|
||||
if(apply.getResponseMap() == null){
|
||||
httpUtilParamInfo.setResponseString(apply.getEntityString());
|
||||
}else {
|
||||
httpUtilParamInfo.setResponseMap(apply.getResponseMap());
|
||||
}
|
||||
httpUtilParamInfo.setResponseDate(new Date());
|
||||
HTTP_UTIL_PARAM_INFO_THREAD_LOCAL.remove();
|
||||
try {
|
||||
log.info(Util.logStr("url [{}] request info : [\n{}\n];", httpUtilParamInfo.getUrl(),
|
||||
JSONObject.toJSONString(httpUtilParamInfo,
|
||||
excludefilter,
|
||||
SerializerFeature.PrettyFormat,
|
||||
SerializerFeature.WriteDateUseDateFormat)));
|
||||
} catch (Exception ignore) {
|
||||
|
@ -696,17 +712,22 @@ public class HttpUtils {
|
|||
try {
|
||||
response = httpClient.execute(request);
|
||||
HttpEntity entity = response.getEntity();
|
||||
Header[] allHeaders = response.getAllHeaders();
|
||||
Locale locale = response.getLocale();
|
||||
responeVo.setLocale(locale);
|
||||
responeVo.setEntityString(EntityUtils.toString(entity, DEFAULT_ENCODING));
|
||||
responeVo.setCode(response.getStatusLine().getStatusCode());
|
||||
responeVo.setResponse(response);
|
||||
httpUtilParamInfo.setResponse(responeVo);
|
||||
if(responeVo.getResponseMap() == null){
|
||||
httpUtilParamInfo.setResponseString(responeVo.getEntityString());
|
||||
}else {
|
||||
httpUtilParamInfo.setResponseMap(responeVo.getResponseMap());
|
||||
}
|
||||
httpUtilParamInfo.setResponseDate(new Date());
|
||||
try {
|
||||
log.info(Util.logStr("url [{}] request info : [\n{}\n];", httpUtilParamInfo.getUrl(),
|
||||
JSONObject.toJSONString(httpUtilParamInfo,
|
||||
excludefilter,
|
||||
SerializerFeature.PrettyFormat,
|
||||
SerializerFeature.WriteDateUseDateFormat)));
|
||||
} catch (Exception ignore) {
|
||||
|
@ -718,6 +739,7 @@ public class HttpUtils {
|
|||
httpUtilParamInfo.setResponseDate(new Date());
|
||||
log.info(Util.logStr("url [{}] request info : [\n{}\n];", httpUtilParamInfo.getUrl(),
|
||||
JSONObject.toJSONString(httpUtilParamInfo,
|
||||
excludefilter,
|
||||
SerializerFeature.PrettyFormat,
|
||||
SerializerFeature.WriteDateUseDateFormat)));
|
||||
} catch (Exception ignore) {
|
||||
|
@ -1021,9 +1043,11 @@ public class HttpUtils {
|
|||
private HttpPost uploadFileByInputStream(String url, List<HttpMultipartFile> multipartFileList,
|
||||
Map<String, Object> params, Map<String, String> headers) {
|
||||
log.info(Util.logStr("start request : url is [{}],other param [\n{}\n],heard [\n{}\n]", url, JSONObject.toJSONString(params,
|
||||
excludefilter,
|
||||
SerializerFeature.PrettyFormat,
|
||||
SerializerFeature.WriteDateUseDateFormat),
|
||||
JSONObject.toJSONString(headers,
|
||||
excludefilter,
|
||||
SerializerFeature.PrettyFormat,
|
||||
SerializerFeature.WriteDateUseDateFormat)));
|
||||
HttpUtilParamInfo httpUtilParamInfo = new HttpUtilParamInfo();
|
||||
|
@ -1074,9 +1098,11 @@ public class HttpUtils {
|
|||
private HttpPut uploadFileByInputStreamPut(String url, List<HttpMultipartFile> multipartFileList,
|
||||
Map<String, Object> params, Map<String, String> headers) {
|
||||
log.info(Util.logStr("start request : url is [{}],other param [\n{}\n],heard [\n{}\n]", url, JSONObject.toJSONString(params,
|
||||
excludefilter,
|
||||
SerializerFeature.PrettyFormat,
|
||||
SerializerFeature.WriteDateUseDateFormat),
|
||||
JSONObject.toJSONString(headers,
|
||||
excludefilter,
|
||||
SerializerFeature.PrettyFormat,
|
||||
SerializerFeature.WriteDateUseDateFormat)));
|
||||
HttpUtilParamInfo httpUtilParamInfo = new HttpUtilParamInfo();
|
||||
|
|
Loading…
Reference in New Issue