增加日志查询错误提示

This commit is contained in:
chenjinsong
2018-06-20 11:13:13 +08:00
parent c4e4928f31
commit e21380a7f1
12 changed files with 146 additions and 67 deletions

View File

@@ -9,12 +9,15 @@
package com.nis.util.httpclient;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
@@ -24,6 +27,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClients;
@@ -31,6 +35,9 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.support.RequestContext;
import com.nis.exceptions.MaatConvertException;
/**
* @ClassName: HttpClientBean.java
@@ -118,7 +125,9 @@ public class HttpClientUtil {
* @param params 参数列表
* @return 查询结果数据json
*/
public static String getMsg(String destUrl, Map<String, Object> params) {
public static String getMsg(String destUrl, Map<String, Object> params, HttpServletRequest req) {
RequestContext requestContext = new RequestContext(req);
CloseableHttpResponse response = null;
String result = null;
try {
@@ -134,10 +143,20 @@ public class HttpClientUtil {
if (status == HttpStatus.SC_OK) {
result = EntityUtils.toString(response.getEntity());
logger.debug("获取消息成功,相应内容如下: " + result);
}
} else {
throw new MaatConvertException(requestContext.getMessage("request_service_failed") + ":" + status);
}
} catch (SocketTimeoutException e) {
logger.error("获取消息失败 ", e);
throw new MaatConvertException(requestContext.getMessage("request_service_failed") + ":timeout");
} catch (MaatConvertException e) {
throw e;
} catch (ConnectTimeoutException e) {
logger.error("获取消息失败 ", e);
throw new MaatConvertException(requestContext.getMessage("request_service_failed") + ":timeout");
} catch (Exception e) {
e.printStackTrace();
logger.debug("获取消息失败,相应内容如下: " + e);
logger.error("获取消息失败 ", e);
throw new MaatConvertException(requestContext.getMessage("request_service_failed"));
} finally {
try {
if (response != null) {