From 4407ea6948a060734a4f2836b11bd2d5c6ea6194 Mon Sep 17 00:00:00 2001 From: "adheli.tavares" Date: Fri, 11 Aug 2023 15:10:44 +0100 Subject: Upgrade Java 17 Issue-ID: POLICY-4673 Change-Id: I01fd3677687b5d2e065d0cc131b338ed841d7e99 Signed-off-by: adheli.tavares --- .../exception/AutomationCompositionException.java | 5 +- .../AutomationCompositionRuntimeException.java | 5 +- .../common/acm/rest/CoderHttpMesageConverter.java | 74 ----------- .../acm/rest/RequestResponseLoggingFilter.java | 20 +-- .../acm/startstop/CommonCommandLineArguments.java | 146 --------------------- 5 files changed, 18 insertions(+), 232 deletions(-) mode change 100644 => 100755 common/src/main/java/org/onap/policy/clamp/common/acm/exception/AutomationCompositionException.java mode change 100644 => 100755 common/src/main/java/org/onap/policy/clamp/common/acm/exception/AutomationCompositionRuntimeException.java delete mode 100644 common/src/main/java/org/onap/policy/clamp/common/acm/rest/CoderHttpMesageConverter.java mode change 100644 => 100755 common/src/main/java/org/onap/policy/clamp/common/acm/rest/RequestResponseLoggingFilter.java delete mode 100644 common/src/main/java/org/onap/policy/clamp/common/acm/startstop/CommonCommandLineArguments.java (limited to 'common/src/main/java/org') diff --git a/common/src/main/java/org/onap/policy/clamp/common/acm/exception/AutomationCompositionException.java b/common/src/main/java/org/onap/policy/clamp/common/acm/exception/AutomationCompositionException.java old mode 100644 new mode 100755 index c22aa920e..61247e1ed --- a/common/src/main/java/org/onap/policy/clamp/common/acm/exception/AutomationCompositionException.java +++ b/common/src/main/java/org/onap/policy/clamp/common/acm/exception/AutomationCompositionException.java @@ -20,7 +20,8 @@ package org.onap.policy.clamp.common.acm.exception; -import javax.ws.rs.core.Response; +import jakarta.ws.rs.core.Response; +import java.io.Serial; import lombok.Getter; import lombok.ToString; import org.onap.policy.models.errors.concepts.ErrorResponse; @@ -33,6 +34,8 @@ import org.onap.policy.models.errors.concepts.ErrorResponseUtils; @Getter @ToString public class AutomationCompositionException extends Exception implements ErrorResponseInfo { + + @Serial private static final long serialVersionUID = -8507246953751956974L; // The error response of the exception diff --git a/common/src/main/java/org/onap/policy/clamp/common/acm/exception/AutomationCompositionRuntimeException.java b/common/src/main/java/org/onap/policy/clamp/common/acm/exception/AutomationCompositionRuntimeException.java old mode 100644 new mode 100755 index 2fc427db8..d91ba2177 --- a/common/src/main/java/org/onap/policy/clamp/common/acm/exception/AutomationCompositionRuntimeException.java +++ b/common/src/main/java/org/onap/policy/clamp/common/acm/exception/AutomationCompositionRuntimeException.java @@ -20,7 +20,8 @@ package org.onap.policy.clamp.common.acm.exception; -import javax.ws.rs.core.Response; +import jakarta.ws.rs.core.Response; +import java.io.Serial; import lombok.Getter; import lombok.ToString; import org.onap.policy.models.errors.concepts.ErrorResponse; @@ -34,6 +35,8 @@ import org.onap.policy.models.errors.concepts.ErrorResponseUtils; @Getter @ToString public class AutomationCompositionRuntimeException extends RuntimeException implements ErrorResponseInfo { + + @Serial private static final long serialVersionUID = -8507246953751956974L; // The error response of the exception diff --git a/common/src/main/java/org/onap/policy/clamp/common/acm/rest/CoderHttpMesageConverter.java b/common/src/main/java/org/onap/policy/clamp/common/acm/rest/CoderHttpMesageConverter.java deleted file mode 100644 index f445364ad..000000000 --- a/common/src/main/java/org/onap/policy/clamp/common/acm/rest/CoderHttpMesageConverter.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * 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 - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.common.acm.rest; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.nio.charset.StandardCharsets; -import javax.ws.rs.core.Response; -import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.coder.StandardYamlCoder; -import org.springframework.http.HttpInputMessage; -import org.springframework.http.HttpOutputMessage; -import org.springframework.http.MediaType; -import org.springframework.http.converter.AbstractHttpMessageConverter; -import org.springframework.http.converter.HttpMessageNotReadableException; -import org.springframework.http.converter.HttpMessageNotWritableException; - -public class CoderHttpMesageConverter extends AbstractHttpMessageConverter { - - private Coder coder; - - public CoderHttpMesageConverter(String type) { - super(new MediaType("application", type, StandardCharsets.UTF_8)); - this.coder = "json".equals(type) ? new StandardCoder() : new StandardYamlCoder(); - } - - @Override - protected boolean supports(Class clazz) { - return true; - } - - @Override - protected T readInternal(Class clazz, HttpInputMessage inputMessage) - throws IOException, HttpMessageNotReadableException { - try (var is = new InputStreamReader(inputMessage.getBody(), StandardCharsets.UTF_8)) { - return coder.decode(is, clazz); - } catch (CoderException e) { - throw new AutomationCompositionRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e); - } - } - - @Override - protected void writeInternal(T t, HttpOutputMessage outputMessage) - throws IOException, HttpMessageNotWritableException { - try (var writer = new OutputStreamWriter(outputMessage.getBody(), StandardCharsets.UTF_8)) { - coder.encode(writer, t); - } catch (CoderException e) { - throw new AutomationCompositionRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e); - } - } - -} diff --git a/common/src/main/java/org/onap/policy/clamp/common/acm/rest/RequestResponseLoggingFilter.java b/common/src/main/java/org/onap/policy/clamp/common/acm/rest/RequestResponseLoggingFilter.java old mode 100644 new mode 100755 index 4b6dce46d..18851081c --- a/common/src/main/java/org/onap/policy/clamp/common/acm/rest/RequestResponseLoggingFilter.java +++ b/common/src/main/java/org/onap/policy/clamp/common/acm/rest/RequestResponseLoggingFilter.java @@ -22,15 +22,15 @@ package org.onap.policy.clamp.common.acm.rest; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.UUID; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @@ -49,14 +49,14 @@ public class RequestResponseLoggingFilter implements Filter { throws IOException, ServletException { - HttpServletResponse res = (HttpServletResponse) response; - HttpServletRequest req = (HttpServletRequest) request; + var res = (HttpServletResponse) response; + var req = (HttpServletRequest) request; /* * Disabling sonar because of ONAP requires the request ID to be copied from the request * to the response. */ - String requestId = req.getHeader(REQUEST_ID_NAME); + var requestId = req.getHeader(REQUEST_ID_NAME); res.addHeader(REQUEST_ID_NAME, requestId != null ? requestId : UUID.randomUUID().toString()); // NOSONAR res.addHeader(VERSION_MINOR_NAME, "0"); diff --git a/common/src/main/java/org/onap/policy/clamp/common/acm/startstop/CommonCommandLineArguments.java b/common/src/main/java/org/onap/policy/clamp/common/acm/startstop/CommonCommandLineArguments.java deleted file mode 100644 index 6f6fb6a4b..000000000 --- a/common/src/main/java/org/onap/policy/clamp/common/acm/startstop/CommonCommandLineArguments.java +++ /dev/null @@ -1,146 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * 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 - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.common.acm.startstop; - -import java.io.File; -import java.io.PrintWriter; -import java.io.StringWriter; -import javax.ws.rs.core.Response; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.lang3.StringUtils; -import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException; -import org.onap.policy.common.utils.resources.ResourceUtils; - -/** - * This class reads and handles command line parameters. - * - */ -public class CommonCommandLineArguments { - private static final String FILE_MESSAGE_PREAMBLE = " file \""; - private static final int HELP_LINE_LENGTH = 120; - - /** - * Construct the options for the policy participant. - * - * @param options the options for the command line - */ - public CommonCommandLineArguments(final Options options) { - //@formatter:off - options.addOption(Option.builder("h") - .longOpt("help") - .desc("outputs the usage of this command") - .required(false) - .type(Boolean.class) - .build()); - options.addOption(Option.builder("v") - .longOpt("version") - .desc("outputs the version of policy participant") - .required(false) - .type(Boolean.class) - .build()); - options.addOption(Option.builder("c") - .longOpt("config-file") - .desc("the full path to the configuration file to use, " - + "the configuration file must be a Json file containing the " - + "policy participant parameters") - .hasArg() - .argName("CONFIG_FILE") - .required(false) - .type(String.class) - .build()); - //@formatter:on - } - - /** - * Validate the command line options. - * - * @param configurationFilePath the path to the configuration file - * @throws AutomationCompositionException on command argument validation errors - */ - public void validate(final String configurationFilePath) throws AutomationCompositionException { - validateReadableFile("policy participant configuration", configurationFilePath); - } - - /** - * Print version information for policy participant. - * - * @return the version string - */ - public String version() { - return ResourceUtils.getResourceAsString("version.txt"); - } - - /** - * Print help information for policy participant. - * - * @param mainClassName the main class name - * @param options the options for the command - * @return the help string - */ - public String help(final String mainClassName, final Options options) { - final var helpFormatter = new HelpFormatter(); - final var stringWriter = new StringWriter(); - final var printWriter = new PrintWriter(stringWriter); - - helpFormatter.printHelp(printWriter, HELP_LINE_LENGTH, mainClassName + " [options...]", "options", options, 0, - 0, ""); - - return stringWriter.toString(); - } - - /** - * Validate readable file. - * - * @param fileTag the file tag - * @param fileName the file name - * @throws AutomationCompositionException on the file name passed as a parameter - */ - private void validateReadableFile(final String fileTag, final String fileName) - throws AutomationCompositionException { - if (StringUtils.isEmpty(fileName)) { - throw new AutomationCompositionException(Response.Status.NOT_ACCEPTABLE, - fileTag + " file was not specified as an argument"); - } - - // The file name refers to a resource on the local file system - final var fileUrl = ResourceUtils.getUrl4Resource(fileName); - if (fileUrl == null) { - throw new AutomationCompositionException(Response.Status.NOT_ACCEPTABLE, - fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" does not exist"); - } - - final var theFile = new File(fileUrl.getPath()); - if (!theFile.exists()) { - throw new AutomationCompositionException(Response.Status.NOT_ACCEPTABLE, - fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" does not exist"); - } - if (!theFile.isFile()) { - throw new AutomationCompositionException(Response.Status.NOT_ACCEPTABLE, - fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is not a normal file"); - } - if (!theFile.canRead()) { - throw new AutomationCompositionException(Response.Status.NOT_ACCEPTABLE, - fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is unreadable"); - } - } -} -- cgit 1.2.3-korg