From f7f2d5ad1bb4bd40a9bcf80b0b5e8c496e98f1a6 Mon Sep 17 00:00:00 2001 From: wangxin Date: Mon, 29 Apr 2019 17:39:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96galaxyMessageFormat=E4=B8=AD?= =?UTF-8?q?=E7=9A=84json=E8=A7=A3=E6=9E=90=E9=80=9F=E5=BA=A6=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8fastjson=E6=9B=BF=E6=8D=A2JSONObject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +++++- .../nis/util/httpclient/HttpClientUtil.java | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 7f213c5cf..cc68c6049 100644 --- a/pom.xml +++ b/pom.xml @@ -727,6 +727,10 @@ druid 1.1.10 - + + com.alibaba + fastjson + 1.2.57 + diff --git a/src/main/java/com/nis/util/httpclient/HttpClientUtil.java b/src/main/java/com/nis/util/httpclient/HttpClientUtil.java index b6cf30085..809f1b65d 100644 --- a/src/main/java/com/nis/util/httpclient/HttpClientUtil.java +++ b/src/main/java/com/nis/util/httpclient/HttpClientUtil.java @@ -23,6 +23,7 @@ import javax.ws.rs.client.Invocation.Builder; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.apache.commons.collections.CollectionUtils; import org.apache.http.HttpStatus; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.config.RequestConfig; @@ -37,6 +38,7 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.util.EntityUtils; import org.apache.log4j.Logger; +import com.alibaba.fastjson.JSON; import com.nis.exceptions.MaatConvertException; import com.nis.util.Constants; import com.nis.util.Encodes; @@ -236,6 +238,7 @@ public class HttpClientUtil { * @return 查询结果数据json */ public static String getMsg(String destUrl, Map params, HttpServletRequest req) throws IOException { + long start=System.currentTimeMillis(), end=System.currentTimeMillis(); // RequestContext requestContext = new RequestContext(req); // CloseableHttpResponse response = null; @@ -283,6 +286,7 @@ public class HttpClientUtil { logger.error("获取消息失败,相应内容如下: " + result); throw new MaatConvertException(status+""); } + } catch (Exception e) { e.printStackTrace(); logger.error("获取消息失败,相应内容如下: " + result); @@ -292,6 +296,8 @@ public class HttpClientUtil { if (response != null) { response.close(); } + end=System.currentTimeMillis(); + logger.warn("getMsg cost:"+(end-start)+"ms"); } return result; } @@ -302,12 +308,14 @@ public class HttpClientUtil { * @return */ public static String galaxyMessageFormat(String recv){ - JSONObject jobj = JSONObject.fromObject(recv); + long start=System.currentTimeMillis(),end=System.currentTimeMillis(); + //JSONObject jobj = JSONObject.fromObject(recv); + com.alibaba.fastjson.JSONObject jobj = JSON.parseObject(recv); Map parse = (Map)jobj; Map map = (Map) parse.get("data"); List reslist=new ArrayList(); List> list= (List)map.get("list"); - if(list!=null&&list.size()>0){ + if(CollectionUtils.isNotEmpty(list)){ for (Map m : list) { Map recvMap = new HashMap(); Iterator> iterator = m.entrySet().iterator(); @@ -316,12 +324,12 @@ public class HttpClientUtil { String key = next.getKey().toString(); Object value = next.getValue(); //处理字段为“null”情况 - if(value!=null&&"null".equals(value)){ + if("null".equals(value)){ value=""; } //处理时间字段为“0”情况 if("foundTime".equals(key)||"recvTime".equals(key)){ - if(null!=value&&"0".equals(value)){ + if("0".equals(value)){ value=""; } } @@ -337,6 +345,8 @@ public class HttpClientUtil { parse.put("data", map); recv = parse.toString(); } + end=System.currentTimeMillis(); + logger.info("galaxyMessageFormat cost:"+(end-start)); return recv; }