From 0b849bfaed856f90f04e13305fdf288339cfbb11 Mon Sep 17 00:00:00 2001 From: DuanDongmei Date: Thu, 22 Nov 2018 09:23:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=8B=E5=8F=91=E7=B1=BB?= =?UTF-8?q?=E6=BC=8F=E6=8E=89=E4=B8=A4=E4=B8=AA=E6=96=B9=E6=B3=95=E7=9A=84?= =?UTF-8?q?response=E5=BC=82=E5=B8=B8=E5=88=A4=E6=96=AD=20=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=E5=BC=BA=E5=BA=A6=E5=8F=AA=E6=9C=89=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E7=9B=91=E6=B5=8B=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/nis/util/ConfigServiceUtil.java | 125 +++++++++++++++++- .../views/cfg/intercept/interceptList.jsp | 14 +- .../WEB-INF/views/cfg/ipaddr/ipList.jsp | 2 +- 3 files changed, 127 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/nis/util/ConfigServiceUtil.java b/src/main/java/com/nis/util/ConfigServiceUtil.java index a3930c4ff..ec3fff916 100644 --- a/src/main/java/com/nis/util/ConfigServiceUtil.java +++ b/src/main/java/com/nis/util/ConfigServiceUtil.java @@ -121,8 +121,16 @@ public class ConfigServiceUtil { logger.info("getId url:"+url); //获取响应结果 Builder header = wt.request(MediaType.APPLICATION_JSON).header("Content-Type", MediaType.APPLICATION_JSON); - Response response= header.get(); - if( response.getStatus() == 200){ + Response response=null; + try { + response= header.get(); + } catch (Exception e) { + if (response != null) { + response.close(); + } + throw new MaatConvertException(""); + } + if(response != null && response.getStatus() == 200){ logger.info("get result success"); result= response.readEntity(String.class); // result = "{\"status\":200,\"businessCode\":2000,\"reason\":\"数据获取操作成功\"," @@ -134,14 +142,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; @@ -161,17 +181,31 @@ public class ConfigServiceUtil { logger.info("postMaatCfg url:"+url); //获取响应结果 Builder header = wt.request(MediaType.APPLICATION_JSON).header("Content-Type", MediaType.APPLICATION_JSON); - Response response= header.post(Entity.entity(params, MediaType.APPLICATION_JSON)); - if( response.getStatus() == 200){ - logger.info("get result success"); + Response response=null; + 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){ + logger.info("get result success"); result= response.readEntity(String.class); JsonConfig config=new JsonConfig(); config.setExcludes(new String[]{"configCompileList"}); 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; } /** @@ -189,14 +223,28 @@ public class ConfigServiceUtil { logger.info("postCallbackCfg url:"+url); //获取响应结果 Builder header = wt.request(MediaType.APPLICATION_JSON).header("Content-Type", MediaType.APPLICATION_JSON); - Response response= header.post(Entity.entity(params, MediaType.APPLICATION_JSON)); - if( response.getStatus() == 200){ + Response response=null; + 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){ result= response.readEntity(String.class); 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 +269,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 +279,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 +314,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 +324,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 +361,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 +371,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 +435,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 +446,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 +477,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 +489,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 +542,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 +605,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/webapp/WEB-INF/views/cfg/intercept/interceptList.jsp b/src/main/webapp/WEB-INF/views/cfg/intercept/interceptList.jsp index 0c4363538..d2e0b282e 100644 --- a/src/main/webapp/WEB-INF/views/cfg/intercept/interceptList.jsp +++ b/src/main/webapp/WEB-INF/views/cfg/intercept/interceptList.jsp @@ -213,7 +213,7 @@ - +
@@ -485,11 +485,13 @@ - - - - - + + + + + + + diff --git a/src/main/webapp/WEB-INF/views/cfg/ipaddr/ipList.jsp b/src/main/webapp/WEB-INF/views/cfg/ipaddr/ipList.jsp index 21d3d9fe0..82cd6eb38 100644 --- a/src/main/webapp/WEB-INF/views/cfg/ipaddr/ipList.jsp +++ b/src/main/webapp/WEB-INF/views/cfg/ipaddr/ipList.jsp @@ -197,7 +197,7 @@ - +