diff options
author | sebdet <sebastien.determe@intl.att.com> | 2019-03-12 14:58:24 +0100 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2019-03-12 15:23:19 +0100 |
commit | e3d4f773fd3c3078384aef77ff1f45612ff53356 (patch) | |
tree | 4220c15429fa04ddc006bbc36a44f67f3b455973 | |
parent | 43f0b01f68e145b74993e31adf7ef41379c72be1 (diff) |
Fix warning/sonar
Some small fixes reported by sonar or deprecated code fixed
Issue-ID: CLAMP-252
Change-Id: I82c6c01ec023f3e5749589ecf519ec2050ec5ecf
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
5 files changed, 38 insertions, 45 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java b/src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java index 059cc2b20..8781fc344 100644 --- a/src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java +++ b/src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java @@ -19,7 +19,7 @@ * ============LICENSE_END============================================ * Modifications copyright (c) 2018 Nokia * =================================================================== - * + * */ package org.onap.clamp.clds.client; @@ -42,20 +42,17 @@ import org.onap.clamp.clds.util.LoggingUtils; import org.springframework.stereotype.Component; /** - * + * * This class manages the HTTP and HTTPS connections to DCAE. * */ @Component public class DcaeHttpConnectionManager { - protected static final EELFLogger logger = EELFManager.getInstance() - .getLogger(DcaeHttpConnectionManager.class); - protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); - private static final String DCAE_REQUEST_FAILED_LOG = "Request Failed - response payload="; - + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(DcaeHttpConnectionManager.class); + protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); + private static final String DCAE_REQUEST_FAILED_LOG = "Request Failed - response payload="; - private String doHttpsQuery(URL url, String requestMethod, String payload, String contentType) - throws IOException { + private String doHttpsQuery(URL url, String requestMethod, String payload, String contentType) throws IOException { logger.info("Using HTTPS URL to contact DCAE:" + url.toString()); HttpsURLConnection secureConnection = (HttpsURLConnection) url.openConnection(); secureConnection.setRequestMethod(requestMethod); @@ -87,12 +84,11 @@ public class DcaeHttpConnectionManager { } } - private String doHttpQuery(URL url, String requestMethod, String payload, String contentType) - throws IOException { - LoggingUtils utils = new LoggingUtils (logger); + private String doHttpQuery(URL url, String requestMethod, String payload, String contentType) throws IOException { + LoggingUtils utils = new LoggingUtils(logger); logger.info("Using HTTP URL to contact DCAE:" + url); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection = utils.invoke(connection,"DCAE", requestMethod); + connection = utils.invoke(connection, "DCAE", requestMethod); connection.setRequestMethod(requestMethod); connection.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId()); if (payload != null && contentType != null) { @@ -126,21 +122,21 @@ public class DcaeHttpConnectionManager { /** * This method does a HTTP/HTTPS query to DCAE with parameters specified. - * + * * @param url - * The string HTTP or HTTPS that mustr be used to connect + * The string HTTP or HTTPS that mustr be used to connect * @param requestMethod - * The Request Method (PUT, POST, GET, DELETE, etc ...) + * The Request Method (PUT, POST, GET, DELETE, etc ...) * @param payload - * The payload if any, in that case an ouputstream is opened + * The payload if any, in that case an ouputstream is opened * @param contentType - * The "application/json or application/xml, or whatever" + * The "application/json or application/xml, or whatever" * @return The payload of the answer * @throws IOException - * In case of issue with the streams + * In case of issue with the streams */ public String doDcaeHttpQuery(String url, String requestMethod, String payload, String contentType) - throws IOException { + throws IOException { URL urlObj = new URL(url); if (url.contains("https://")) { // Support for HTTPS return doHttpsQuery(urlObj, requestMethod, payload, contentType); diff --git a/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java b/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java index d1beb956d..8af1286ca 100644 --- a/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java +++ b/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java @@ -5,32 +5,30 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights * reserved. * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * + * */ package org.onap.clamp.clds.config; import com.google.gson.JsonParseException; -import com.google.gson.reflect.TypeToken; + import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; -import java.util.List; import org.apache.commons.io.IOUtils; import org.onap.clamp.clds.exception.CldsUsersException; import org.onap.clamp.clds.service.CldsUser; @@ -39,13 +37,13 @@ import org.onap.clamp.clds.util.JsonUtils; public class CldsUserJsonDecoder { /** - * This method decodes the JSON file provided to a CldsUser Array. The - * stream is closed after this call, this is not possible to reuse it. - * + * This method decodes the JSON file provided to a CldsUser Array. The stream is + * closed after this call, this is not possible to reuse it. + * * @param cldsUsersFile - * The inputStream containing the users json file - * @return CldsUser[] Array containing a list of the user defined in the - * JSON file + * The inputStream containing the users json file + * @return CldsUser[] Array containing a list of the user defined in the JSON + * file */ public static CldsUser[] decodeJson(InputStream cldsUsersFile) { try { diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java index b60f07287..b65a994ac 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java @@ -29,6 +29,7 @@ import com.att.eelf.configuration.EELFManager; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -135,7 +136,7 @@ public class CsarHandler { blueprintArtifact .setBlueprintInvariantServiceUuid(this.getSdcNotification().getServiceInvariantUUID()); try (InputStream stream = zipFile.getInputStream(entry)) { - blueprintArtifact.setDcaeBlueprint(IOUtils.toString(stream)); + blueprintArtifact.setDcaeBlueprint(IOUtils.toString(stream, StandardCharsets.UTF_8)); } blueprintArtifact.setResourceAttached(searchForResourceByInstanceName(entry.getName().substring( entry.getName().indexOf(RESOURCE_INSTANCE_NAME_PREFIX) + RESOURCE_INSTANCE_NAME_PREFIX.length(), @@ -175,7 +176,7 @@ public class CsarHandler { try (ZipFile zipFile = new ZipFile(csarFilePath)) { ZipEntry entry = zipFile.getEntry(POLICY_DEFINITION_NAME_SUFFIX); if (entry != null) { - result = IOUtils.toString(zipFile.getInputStream(entry)); + result = IOUtils.toString(zipFile.getInputStream(entry), StandardCharsets.UTF_8); } else { logger.info("Policy model not found inside the CSAR file: " + csarFilePath); } diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java index a4ae14d00..6dc418340 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java @@ -28,6 +28,7 @@ import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.google.gson.JsonObject; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -269,8 +270,8 @@ public class CsarInstallerImpl implements CsarInstaller { CldsTemplate template = new CldsTemplate(); template.setBpmnId("Sdc-Generated"); - template - .setBpmnText(IOUtils.toString(appContext.getResource(configFiles.getBpmnXmlFilePath()).getInputStream())); + template.setBpmnText(IOUtils.toString(appContext.getResource(configFiles.getBpmnXmlFilePath()).getInputStream(), + StandardCharsets.UTF_8)); template.setPropText( "{\"global\":[{\"name\":\"service\",\"value\":[\"" + blueprintArtifact.getDcaeBlueprint() + "\"]}]}"); template diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java index 58b922e04..55657c974 100644 --- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java @@ -49,13 +49,10 @@ import org.springframework.test.context.junit4.SpringRunner; @ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller") public class SdcSingleControllerItCase { - private static final String SDC_FOLDER = "/tmp/csar-handler-tests"; private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar"; private static final String SERVICE_UUID = "serviceUUID"; private static final String RESOURCE1_UUID = "resource1UUID"; private static final String RESOURCE1_INSTANCE_NAME = "sim-1802 0"; - private static final String RESOURCE1_INSTANCE_NAME_IN_CSAR = "sim18020"; - private static final String BLUEPRINT1_NAME = "FOI.Simfoimap223S0112.event_proc_bp.yaml"; @Autowired private ClampProperties clampProp; |