Fix some Sonar Blocker issues in apihandler/common 33/30333/3
authorShashank Kumar Shankar <shashank.kumar.shankar@intel.com>
Mon, 5 Feb 2018 19:41:43 +0000 (11:41 -0800)
committerShashank Kumar Shankar <shashank.kumar.shankar@intel.com>
Thu, 8 Feb 2018 19:32:43 +0000 (11:32 -0800)
Some sonar code fixes are done in this patch.

https://sonar.onap.org/issues/search#issues=AV3BntKO5bp_wwmIVCLv
https://sonar.onap.org/issues/search#issues=AV5mhwQk32hFUzlqebFJ
https://sonar.onap.org/issues/search#issues=AV3BntKc5bp_wwmIVCMJ
https://sonar.onap.org/issues/search#issues=AV3BntKi5bp_wwmIVCMK
https://sonar.onap.org/issues/search#issues=AV3BntKu5bp_wwmIVCMQ
https://sonar.onap.org/issues/search#issues=AV3BntK35bp_wwmIVCMX
https://sonar.onap.org/issues/search#issues=AV5mhwRN32hFUzlqebFQ
https://sonar.onap.org/issues/search#issues=AV3BntLG5bp_wwmIVCMc
https://sonar.onap.org/issues/search#issues=AV3BntLR5bp_wwmIVCMh

Change-Id: I3ba77adec1951fb7153ed640eb1ea0a4a3ed3e6b
Issue-ID: SO-165
Signed-off-by: Shashank Kumar Shankar <shashank.kumar.shankar@intel.com>
mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/CamundaClient.java
mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/CamundaTaskClient.java
mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/ErrorNumbers.java
mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/LSInputImpl.java
mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/RequestClient.java
mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/RequestClientFactory.java
mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/ResponseHandler.java
mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/ValidationException.java
mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/XMLValidator.java

index c8889be..b9c0725 100644 (file)
@@ -36,6 +36,7 @@ import java.io.IOException;
 
 public class CamundaClient extends RequestClient{
        private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);
+       private static final String CAMUNDA_URL_MESAGE = "Camunda url is: ";
 
        public CamundaClient() {
                super(CommonConstants.CAMUNDA);
@@ -47,13 +48,13 @@ public class CamundaClient extends RequestClient{
                        String requestTimeout, String schemaVersion, String serviceInstanceId, String action)
                                        throws ClientProtocolException, IOException{
                HttpPost post = new HttpPost(url);
-               msoLogger.debug("Camunda url is: "+ url);
+               msoLogger.debug(CAMUNDA_URL_MESAGE + url);
                String jsonReq = wrapRequest(camundaReqXML, requestId, serviceInstanceId, requestTimeout,  schemaVersion);
 
                StringEntity input = new StringEntity(jsonReq);
                input.setContentType(CommonConstants.CONTENT_TYPE_JSON);
 
-               String encryptedCredentials = null;
+               String encryptedCredentials;
                if(props!=null){
                        encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);
                        if(encryptedCredentials != null){
@@ -65,22 +66,18 @@ public class CamundaClient extends RequestClient{
                }
 
                post.setEntity(input);
-               HttpResponse response = client.execute(post);
-
-               return response;
+        return client.execute(post);
        }
 
        @Override
-       public HttpResponse post(String jsonReq)
-                                       throws ClientProtocolException, IOException{
+       public HttpResponse post(String jsonReq) throws ClientProtocolException, IOException{
                HttpPost post = new HttpPost(url);
-               msoLogger.debug("Camunda url is: "+ url);
-               //String jsonReq = wrapRequest(camundaReqXML, requestId, serviceInstanceId, requestTimeout,  schemaVersion);
+               msoLogger.debug(CAMUNDA_URL_MESAGE + url);
 
                StringEntity input = new StringEntity(jsonReq);
                input.setContentType(CommonConstants.CONTENT_TYPE_JSON);
 
-               String encryptedCredentials = null;
+               String encryptedCredentials;
                if(props!=null){
                        encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);
                        if(encryptedCredentials != null){
@@ -92,9 +89,8 @@ public class CamundaClient extends RequestClient{
                }
 
                post.setEntity(input);
-               HttpResponse response = client.execute(post);
 
-               return response;
+        return client.execute(post);
        }
 
        @Override
@@ -105,7 +101,7 @@ public class CamundaClient extends RequestClient{
                        String requestDetails)
                                        throws ClientProtocolException, IOException{
                HttpPost post = new HttpPost(url);
-               msoLogger.debug("Camunda url is: "+ url);
+               msoLogger.debug(CAMUNDA_URL_MESAGE + url);
                String jsonReq = wrapVIDRequest(requestId, isBaseVfModule, recipeTimeout, requestAction,
                                serviceInstanceId, vnfId, vfModuleId, volumeGroupId, networkId,
                                serviceType, vnfType, vfModuleType, networkType, requestDetails);
@@ -113,7 +109,7 @@ public class CamundaClient extends RequestClient{
                StringEntity input = new StringEntity(jsonReq);
                input.setContentType(CommonConstants.CONTENT_TYPE_JSON);
 
-               String encryptedCredentials = null;
+               String encryptedCredentials;
                if(props!=null){
                        encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);
                        if(encryptedCredentials != null){
@@ -125,9 +121,8 @@ public class CamundaClient extends RequestClient{
                }
 
                post.setEntity(input);
-               HttpResponse response = client.execute(post);
 
-               return response;
+        return client.execute(post);
        }
        
        @Override
index b4e7b7e..64193cf 100644 (file)
 \r
 package org.openecomp.mso.apihandler.common;\r
 \r
-import org.openecomp.mso.logger.MessageEnum;\r
 import org.openecomp.mso.logger.MsoLogger;\r
 import org.apache.http.HttpResponse;\r
 import org.apache.http.client.ClientProtocolException;\r
 import org.apache.http.client.methods.HttpGet;\r
 import org.apache.http.client.methods.HttpPost;\r
 import org.apache.http.entity.StringEntity;\r
-import org.codehaus.jackson.map.ObjectMapper;\r
-import org.codehaus.jackson.map.SerializationConfig;\r
 \r
 import javax.xml.bind.DatatypeConverter;\r
-import java.io.BufferedReader;\r
-import java.io.InputStreamReader;\r
 import java.io.IOException;\r
 \r
 public class CamundaTaskClient extends RequestClient{\r
@@ -63,9 +58,7 @@ public class CamundaTaskClient extends RequestClient{
                }\r
 \r
                post.setEntity(input);\r
-               HttpResponse response = client.execute(post);\r
-\r
-               return response;\r
+               return client.execute(post);\r
        }\r
        \r
        @Override\r
@@ -88,8 +81,7 @@ public class CamundaTaskClient extends RequestClient{
        }\r
        \r
        @Override\r
-       public HttpResponse get()\r
-                       throws ClientProtocolException, IOException{\r
+       public HttpResponse get() throws ClientProtocolException, IOException{\r
                HttpGet get = new HttpGet(url);\r
                msoLogger.debug("Camunda Task url is: "+ url);  \r
                String encryptedCredentials;\r
@@ -103,12 +95,7 @@ public class CamundaTaskClient extends RequestClient{
                        }\r
                }\r
                \r
-               HttpResponse getResponse = client.execute(get); \r
-\r
-               return getResponse;\r
-}\r
-       \r
-       \r
-\r
+               return client.execute(get);\r
+       }\r
 \r
 }\r
index 72f72c2..2cafef3 100644 (file)
@@ -22,6 +22,9 @@ package org.openecomp.mso.apihandler.common;
  
 public final class ErrorNumbers {
 
+    private ErrorNumbers() {
+    }
+
     public static final String REQUEST_FAILED_SCHEMA_VALIDATION = "1000";
     public static final String RECIPE_DOES_NOT_EXIST = "1010";
     public static final String VFMODULE_TYPE_DOES_NOT_EXIST = "1011";
index 42d77f5..b39b534 100644 (file)
@@ -37,9 +37,6 @@ public class LSInputImpl implements LSInput {
     protected String fEncoding;
     protected boolean fCertifiedText;
 
-    public LSInputImpl () {
-    }
-
     @Override
     public InputStream getByteStream () {
         return fByteStream;
index 1324e12..addf4e1 100644 (file)
@@ -22,7 +22,6 @@ package org.openecomp.mso.apihandler.common;
 
 import java.io.IOException;
 import java.security.GeneralSecurityException;
-import java.util.Properties;
 
 import org.apache.http.HttpResponse;
 import org.apache.http.client.ClientProtocolException;
@@ -83,16 +82,11 @@ public abstract class RequestClient {
        
        protected String getEncryptedPropValue (String prop, String defaultValue, String encryptionKey) {
                 try {
-                        String result = CryptoUtils.decrypt(prop, encryptionKey);
-                        return result;
+                        return CryptoUtils.decrypt(prop, encryptionKey);
                 }      
                 catch (GeneralSecurityException e) {
                         msoLogger.debug("Security exception", e);
                 }
                 return defaultValue;
         }
-
-       
-
-
 }
index 773c5b0..8f91986 100644 (file)
 package org.openecomp.mso.apihandler.common;
 
 
-import java.util.Properties;
-
 import org.apache.http.impl.client.DefaultHttpClient;
 
 import org.openecomp.mso.properties.MsoJavaProperties;
 
 public class RequestClientFactory {
-       
+
+    private RequestClientFactory() {
+    }
+
        //based on URI, returns BPEL, CamundaTask or Camunda client
        public static RequestClient getRequestClient(String orchestrationURI, MsoJavaProperties props) throws IllegalStateException{
                RequestClient retClient;
index 6722a93..4e7cf4c 100644 (file)
@@ -41,6 +41,7 @@ public class ResponseHandler {
        private HttpResponse httpResponse;
        private int type;
        private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);
+    private static final String RESPONSE_BODY_MSG = "response body is: ";
 
        public ResponseHandler(HttpResponse httpResponse, int type) {
                this.httpResponse = httpResponse;
@@ -84,7 +85,7 @@ public class ResponseHandler {
                        if(response!=null){
                                responseBody = response.getResponse();
                        }
-                       msoLogger.debug("response body is: " + responseBody);
+                       msoLogger.debug(RESPONSE_BODY_MSG + responseBody);
                        
                
                if(status!=HttpStatus.SC_ACCEPTED){
@@ -99,7 +100,7 @@ public class ResponseHandler {
                try {
                        if (bpelEntity!=null) {
                                responseBody = EntityUtils.toString(bpelEntity);
-                               msoLogger.debug("response body is: " + responseBody);
+                               msoLogger.debug(RESPONSE_BODY_MSG + responseBody);
 
                        }
                        if(status!=HttpStatus.SC_ACCEPTED){
@@ -118,7 +119,7 @@ public class ResponseHandler {
                try {
                        if (camundataskEntity!=null) {
                                responseBody = EntityUtils.toString(camundataskEntity);
-                               msoLogger.debug("response body is: " + responseBody);
+                               msoLogger.debug(RESPONSE_BODY_MSG + responseBody);
 
                        }
                        if(status!=HttpStatus.SC_NO_CONTENT && status != HttpStatus.SC_ACCEPTED){
index bf2088e..73bf020 100644 (file)
@@ -31,17 +31,18 @@ public class ValidationException extends Exception {
      **/
 
     private static final long serialVersionUID = 1L;
-    private static final String validationFailMessage = "No valid $ELEMENT is specified";
-    private static final String invalidElementMessage = "$ELEMENT is not valid in the $VERSION version";
+    private static final String VALIDATION_FAIL_MESSAGE = "No valid $ELEMENT is specified";
+    private static final String INVALID_ELEMENT_MESSAGE = "$ELEMENT is not valid in the $VERSION version";
+    private static final String ELEMENT_MESSAGE = "\\$ELEMENT";
 
     public ValidationException (String msg) {
-        super (validationFailMessage.replaceAll ("\\$ELEMENT", msg));
+        super (VALIDATION_FAIL_MESSAGE.replaceAll (ELEMENT_MESSAGE, msg));
     }
 
     public ValidationException (String msg, Exception cause) {
-        super (validationFailMessage.replaceAll ("\\$ELEMENT", msg), cause);
+        super (VALIDATION_FAIL_MESSAGE.replaceAll (ELEMENT_MESSAGE, msg), cause);
     }
     public ValidationException(String msg, String version) {
-        super(invalidElementMessage.replaceAll("\\$ELEMENT", msg).replaceAll("\\$VERSION", version));
+        super(INVALID_ELEMENT_MESSAGE.replaceAll(ELEMENT_MESSAGE, msg).replaceAll("\\$VERSION", version));
     }
 }
index b498259..ebb1dd2 100644 (file)
@@ -40,14 +40,14 @@ import org.openecomp.mso.logger.MsoLogger;
 
 public class XMLValidator {
 
-    private static String XSDS_PATH;
+    private static String xsdsPath;
 
     static {
         String prefixMsoPropertiesPath = System.getProperty ("mso.config.path");
         if (prefixMsoPropertiesPath == null) {
             prefixMsoPropertiesPath = "";
         }
-        XSDS_PATH = prefixMsoPropertiesPath + "xsds/";
+        xsdsPath = prefixMsoPropertiesPath + "xsds/";
     }
 
     private String stringXsd;
@@ -60,12 +60,12 @@ public class XMLValidator {
 
     public XMLValidator (String xsdFile) {
 
-        try (FileInputStream xsdStream = new FileInputStream (XSDS_PATH + xsdFile)) {
+        try (FileInputStream xsdStream = new FileInputStream (xsdsPath + xsdFile)) {
 
             stringXsd = IOUtils.toString (xsdStream);
 
             factory = SchemaFactory.newInstance (XMLConstants.W3C_XML_SCHEMA_NS_URI);
-            factory.setResourceResolver (new PathResourceResolver (XSDS_PATH));
+            factory.setResourceResolver (new PathResourceResolver (xsdsPath));
             factory.setFeature (XMLConstants.FEATURE_SECURE_PROCESSING, true);
 
             String quotedXsd = stringXsd.replaceAll ("&#34;", "\"");
@@ -73,7 +73,7 @@ public class XMLValidator {
             schema = factory.newSchema (src);
 
         } catch (IOException | SAXException e) {
-            msoLogger.debug ("Cannot open file " + XSDS_PATH + xsdFile, e);
+            msoLogger.debug ("Cannot open file " + xsdsPath + xsdFile, e);
             errorMsg = "ErrorDetails: xsd file " + xsdFile + "could not be opened - " + e.getMessage ();
         }
     }