aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main/java/org
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2023-08-11 15:10:44 +0100
committeradheli.tavares <adheli.tavares@est.tech>2023-09-25 13:40:52 +0100
commit4407ea6948a060734a4f2836b11bd2d5c6ea6194 (patch)
tree6a6e482126ec3d8e830faf80a392b2161ced6de0 /common/src/main/java/org
parentc4b3c527882610afc3f08c0efd73e2f7841e9fe5 (diff)
Upgrade Java 17
Issue-ID: POLICY-4673 Change-Id: I01fd3677687b5d2e065d0cc131b338ed841d7e99 Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'common/src/main/java/org')
-rwxr-xr-x[-rw-r--r--]common/src/main/java/org/onap/policy/clamp/common/acm/exception/AutomationCompositionException.java5
-rwxr-xr-x[-rw-r--r--]common/src/main/java/org/onap/policy/clamp/common/acm/exception/AutomationCompositionRuntimeException.java5
-rw-r--r--common/src/main/java/org/onap/policy/clamp/common/acm/rest/CoderHttpMesageConverter.java74
-rwxr-xr-x[-rw-r--r--]common/src/main/java/org/onap/policy/clamp/common/acm/rest/RequestResponseLoggingFilter.java20
-rw-r--r--common/src/main/java/org/onap/policy/clamp/common/acm/startstop/CommonCommandLineArguments.java146
5 files changed, 18 insertions, 232 deletions
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
index c22aa920e..61247e1ed 100644..100755
--- 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
index 2fc427db8..d91ba2177 100644..100755
--- 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<T> extends AbstractHttpMessageConverter<T> {
-
- 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<? extends T> 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
index 4b6dce46d..18851081c 100644..100755
--- 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");
- }
- }
-}