summaryrefslogtreecommitdiffstats
path: root/nokia
diff options
context:
space:
mode:
authorajay priyadarshi <ajay.priyadarshi@ril.com>2018-03-14 14:59:37 +0530
committerajay priyadarshi <ajay.priyadarshi@ril.com>2018-03-14 15:00:24 +0530
commit5bd53a3565387aeadabd4514d5350c46292a31b2 (patch)
treee925b90004c6f7dc01ef5fdfaadaa2968fb28697 /nokia
parent5c76dfc8933c0c1b51c4c72865b4b05628130178 (diff)
sonar fix:Method handling in HttpClientProcessor
Iteration, resource & Exception handling file name: HttpClientProcessorImpl.java Change-Id: I3802c75a82ac6979382b26be338d94d6e53bd404 Issue-ID: VFC-815 Signed-off-by: ajay priyadarshi <ajay.priyadarshi@ril.com>
Diffstat (limited to 'nokia')
-rw-r--r--nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java38
-rw-r--r--nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java2
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);
}