diff --git a/src/main/java/com/nis/util/ConfigServiceUtil.java b/src/main/java/com/nis/util/ConfigServiceUtil.java index a3930c4ff..3fdf469e3 100644 --- a/src/main/java/com/nis/util/ConfigServiceUtil.java +++ b/src/main/java/com/nis/util/ConfigServiceUtil.java @@ -134,14 +134,26 @@ public class ConfigServiceUtil { if(!StringUtil.isEmpty(bean.getData())){ list = bean.getData().getPzIdList(); }else{ + if (response != null) { + response.close(); + } throw new MaatConvertException(":"+response.readEntity(String.class)); } }else{ + if (response != null) { + response.close(); + } throw new MaatConvertException(":"+response.readEntity(String.class)); } }else{ + if (response != null) { + response.close(); + } throw new MaatConvertException(":"+response.readEntity(String.class)); } + if (response != null) { + response.close(); + } long end=System.currentTimeMillis(); logger.warn("get ids finish,cost:"+(end-start)); return list; @@ -170,8 +182,14 @@ public class ConfigServiceUtil { JSONObject resObject = JSONObject.fromObject(result,config); bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ + if (response != null) { + response.close(); + } throw new MaatConvertException(":"+response.readEntity(String.class)); } + if (response != null) { + response.close(); + } return bean; } /** @@ -195,8 +213,14 @@ public class ConfigServiceUtil { JSONObject resObject = JSONObject.fromObject(result); bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ + if (response != null) { + response.close(); + } throw new MaatConvertException(":"+response.readEntity(String.class)); } + if (response != null) { + response.close(); + } return bean; } @@ -221,6 +245,9 @@ public class ConfigServiceUtil { try { response= header.post(Entity.entity(formDataMultiPart, formDataMultiPart.getMediaType())); } catch (Exception e) { + if (response != null) { + response.close(); + } throw new MaatConvertException(""); } if(response != null && response.getStatus() == 200){ @@ -228,8 +255,14 @@ public class ConfigServiceUtil { JSONObject resObject = JSONObject.fromObject(result); bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ + if (response != null) { + response.close(); + } throw new MaatConvertException(""); } + if (response != null) { + response.close(); + } return bean; } @@ -257,6 +290,9 @@ public class ConfigServiceUtil { try { response= header.delete(); } catch (Exception e) { + if (response != null) { + response.close(); + } throw new MaatConvertException(""); } if(response != null && response.getStatus() == 200){ @@ -264,8 +300,14 @@ public class ConfigServiceUtil { JSONObject resObject = JSONObject.fromObject(result); bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ + if (response != null) { + response.close(); + } throw new MaatConvertException(":"+response.readEntity(String.class)); } + if (response != null) { + response.close(); + } return bean; } @@ -295,6 +337,9 @@ public class ConfigServiceUtil { try { response= header.put(Entity.entity(params, MediaType.APPLICATION_JSON)); } catch (Exception e) { + if (response != null) { + response.close(); + } throw new MaatConvertException(""); } if(response !=null && response.getStatus() == 200){ @@ -302,8 +347,14 @@ public class ConfigServiceUtil { JSONObject resObject = JSONObject.fromObject(result); bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ + if (response != null) { + response.close(); + } throw new MaatConvertException(":"+response.readEntity(String.class)); } + if (response != null) { + response.close(); + } return bean; } /** @@ -360,6 +411,9 @@ public class ConfigServiceUtil { try { response= header.post(Entity.entity(formDataMultiPart, formDataMultiPart.getMediaType())); } catch (Exception e) { + if (response != null) { + response.close(); + } throw new MaatConvertException(""); } if(response !=null && response.getStatus() == 200){ @@ -368,8 +422,14 @@ public class ConfigServiceUtil { JSONObject resObject = JSONObject.fromObject(result); bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ + if (response != null) { + response.close(); + } throw new MaatConvertException(":"+response.readEntity(String.class)); } + if (response != null) { + response.close(); + } return bean; } /** @@ -393,6 +453,9 @@ public class ConfigServiceUtil { try { response= header.post(Entity.entity(params, MediaType.APPLICATION_JSON)); } catch (Exception e) { + if (response != null) { + response.close(); + } throw new MaatConvertException(""); } if(response !=null && response.getStatus() == 200){ @@ -402,8 +465,14 @@ public class ConfigServiceUtil { JSONObject resObject = JSONObject.fromObject(result,config); bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ + if (response != null) { + response.close(); + } throw new MaatConvertException(":"+response.readEntity(String.class)); } + if (response != null) { + response.close(); + } long end=System.currentTimeMillis(); logger.warn("postGroupReuseSources end,cost:"+(end-start)); return bean; @@ -449,13 +518,22 @@ public class ConfigServiceUtil { try { response= header.get(); } catch (Exception e) { + if (response != null) { + response.close(); + } throw new MaatConvertException(""); } if(response !=null && response.getStatus() == 200){ result= response.readEntity(String.class); }else{ + if (response != null) { + response.close(); + } throw new MaatConvertException(":"+response.readEntity(String.class)); } + if (response != null) { + response.close(); + } return result; } public static String getReport(String reportUrl, SearchReport searchCondition) throws MaatConvertException, UnsupportedEncodingException{ @@ -503,13 +581,22 @@ public class ConfigServiceUtil { try { response= header.get(); } catch (Exception e) { + if (response != null) { + response.close(); + } throw new MaatConvertException(""); } if(response !=null && response.getStatus() == 200){ result= response.readEntity(String.class); }else{ + if (response != null) { + response.close(); + } throw new MaatConvertException(":"+response.readEntity(String.class)); } + if (response != null) { + response.close(); + } return result; } public static void main(String[] args) { diff --git a/src/main/java/com/nis/util/httpclient/HttpClientUtil.java b/src/main/java/com/nis/util/httpclient/HttpClientUtil.java index 79e6d4ed6..4d704e425 100644 --- a/src/main/java/com/nis/util/httpclient/HttpClientUtil.java +++ b/src/main/java/com/nis/util/httpclient/HttpClientUtil.java @@ -247,7 +247,7 @@ public class HttpClientUtil { * @param params 参数列表 * @return 查询结果数据json */ - public static String getMsg(String destUrl, Map params, HttpServletRequest req) { + public static String getMsg(String destUrl, Map params, HttpServletRequest req) throws IOException { // RequestContext requestContext = new RequestContext(req); // CloseableHttpResponse response = null; @@ -296,7 +296,11 @@ public class HttpClientUtil { logger.error("获取消息失败,相应内容如下: " + result); logger.error("获取消息失败 ", e); throw new MaatConvertException(":"); - } + }finally { + if (response != null) { + response.close(); + } + } return result; } diff --git a/src/main/java/com/nis/web/controller/configuration/ntc/BgpCfgController.java b/src/main/java/com/nis/web/controller/configuration/ntc/BgpCfgController.java index c06815d58..9d67d9fd7 100644 --- a/src/main/java/com/nis/web/controller/configuration/ntc/BgpCfgController.java +++ b/src/main/java/com/nis/web/controller/configuration/ntc/BgpCfgController.java @@ -24,7 +24,7 @@ import com.nis.domain.configuration.ComplexkeywordCfg; import com.nis.domain.configuration.IpPortCfg; import com.nis.domain.configuration.NtcBgpAsCfg; import com.nis.domain.configuration.NtcSubscribeIdCfg; -import com.nis.exception.MaatConvertException; +import com.nis.exceptions.MaatConvertException; import com.nis.util.Constants; import com.nis.util.StringUtils; import com.nis.web.controller.BaseController;