diff options
author | Yan Yang <yangyanyj@chinamobile.com> | 2018-03-14 10:13:12 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-14 10:13:12 +0000 |
commit | 7be67ce15344a4693eeace4127ca6b155dbbc333 (patch) | |
tree | de7000dfe7dc2bc5d332af51b60d213dfe31d5e4 /nokia/vnfmdriver | |
parent | d5870cc26dcebe612728fa7730f82d54704cc38a (diff) | |
parent | 5bd53a3565387aeadabd4514d5350c46292a31b2 (diff) |
Merge "sonar fix:Method handling in HttpClientProcessor"
Diffstat (limited to 'nokia/vnfmdriver')
2 files changed, 24 insertions, 16 deletions
diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java index 489ab927..7878a00c 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java @@ -40,17 +40,22 @@ public class HttpClientProcessorImpl implements HttpClientProcessorInf{ @Autowired private HttpClientBuilder httpClientBuilder; - public HttpResult process(String url, RequestMethod methodType, HashMap<String, String> headerMap, String bodyString) throws ClientProtocolException, IOException + public HttpResult process(String url, RequestMethod methodType, HashMap<String, String> headerMap, String bodyString) throws IOException { HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, methodType); + //Map<String, String> headerMap = new HashMap<String, String>(); if(headerMap != null && !headerMap.isEmpty()) { - for(String key : headerMap.keySet()) + /*for(String key : headerMap.keySet()) { processor.addHdeader(key, headerMap.get(key)); + }*/ + + for (HashMap.Entry<String, String> entry : headerMap.entrySet()) { + processor.addHeader(entry.getKey(), entry.getValue()); } - if(null != bodyString && bodyString.length() > 0 && !bodyString.equalsIgnoreCase("null")) + if(bodyString.length() > 0 && !"null".equalsIgnoreCase(bodyString)) { processor.addPostEntity(bodyString); } @@ -59,15 +64,19 @@ public class HttpClientProcessorImpl implements HttpClientProcessorInf{ return processor.process(url); } - public HttpResult processBytes(String url, RequestMethod methodType, HashMap<String, String> headerMap, byte[] byteArray) throws ClientProtocolException, IOException + public HttpResult processBytes(String url, RequestMethod methodType, HashMap<String, String> headerMap, byte[] byteArray) throws IOException { HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, methodType); if(headerMap != null && !headerMap.isEmpty()) { - for(String key : headerMap.keySet()) + for (HashMap.Entry<String, String> entry : headerMap.entrySet()) { + processor.addHeader(entry.getKey(), entry.getValue()); + } //Iterate over the "entrySet" instead of the "keySet" + + /*for(String key : headerMap.keySet()) { - processor.addHdeader(key, headerMap.get(key)); - } + processor.addHeader(key, headerMap.get(key)); + }*/ if(null != byteArray && byteArray.length > 0) { @@ -96,12 +105,11 @@ public class HttpClientProcessorImpl implements HttpClientProcessorInf{ if(!saveDir.exists()){ saveDir.mkdir(); } - File file = new File(saveDir+File.separator+fileName); - FileOutputStream fos = new FileOutputStream(file); - fos.write(getData); - if(fos!=null){ - fos.close(); - } + File file = new File(saveDir+File.separator+fileName); + try(FileOutputStream fos = new FileOutputStream(file)){ + fos.write(getData); + } + if(inputStream!=null){ inputStream.close(); } @@ -119,11 +127,11 @@ public class HttpClientProcessorImpl implements HttpClientProcessorInf{ public static byte[] readInputStream(InputStream inputStream) throws IOException { byte[] buffer = new byte[1024]; int len = 0; - ByteArrayOutputStream bos = new ByteArrayOutputStream(); + try(ByteArrayOutputStream bos = new ByteArrayOutputStream()){ while((len = inputStream.read(buffer)) != -1) { bos.write(buffer, 0, len); } - bos.close(); return bos.toByteArray(); + } } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java index 0d472fcb..6c6f27fa 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java @@ -75,7 +75,7 @@ public class HttpRequestProcessor { return httpResult; } - public void addHdeader(String key, String value) { + public void addHeader(String key, String value) { httpRequest.setHeader(key, value); } |