X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=main%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fapi%2Fmain%2Frest%2FCommonRestController.java;h=5e4c3ee51f81e4ea194f5f4163e3d9a60b2a9886;hb=a4b28fed45ecdceade0c7a3dc105694e26fe4b3e;hp=0389e0f614698f4c9a2122c24cda01f6ffc35778;hpb=5f919673b13d8fd40a6a90b97f4e662ade068304;p=policy%2Fapi.git diff --git a/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java index 0389e0f6..5e4c3ee5 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +25,7 @@ package org.onap.policy.api.main.rest; import java.util.UUID; +import org.onap.policy.api.main.exception.PolicyApiRuntimeException; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -31,6 +33,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; /** * Super class from which REST controllers are derived. @@ -39,7 +42,41 @@ public class CommonRestController { private static final Logger LOGGER = LoggerFactory.getLogger(CommonRestController.class); - private final Coder coder = new StandardCoder(); + protected static final String EXTENSION_NAME = "interface info"; + + protected static final String API_VERSION_NAME = "api-version"; + protected static final String API_VERSION = "1.0.0"; + + protected static final String LAST_MOD_NAME = "last-mod-release"; + + protected static final String AUTHORIZATION_TYPE = "basicAuth"; + + protected static final String VERSION_MINOR_NAME = "X-MinorVersion"; + protected static final String VERSION_MINOR_DESCRIPTION = + "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client"; + + protected static final String VERSION_PATCH_NAME = "X-PatchVersion"; + protected static final String VERSION_PATCH_DESCRIPTION = "Used only to communicate a PATCH version in a " + + "response for troubleshooting purposes only, and will not be provided by" + " the client on request"; + + protected static final String VERSION_LATEST_NAME = "X-LatestVersion"; + protected static final String VERSION_LATEST_DESCRIPTION = "Used only to communicate an API's latest version"; + + protected static final String REQUEST_ID_NAME = "X-ONAP-RequestID"; + protected static final String REQUEST_ID_HDR_DESCRIPTION = "Used to track REST transactions for logging purpose"; + protected static final String REQUEST_ID_PARAM_DESCRIPTION = "RequestID for http transaction"; + + protected static final String AUTHENTICATION_ERROR_MESSAGE = "Authentication Error"; + protected static final String AUTHORIZATION_ERROR_MESSAGE = "Authorization Error"; + protected static final String SERVER_ERROR_MESSAGE = "Internal Server Error"; + protected static final String NOT_FOUND_MESSAGE = "Resource Not Found"; + protected static final String INVALID_BODY_MESSAGE = "Invalid Body"; + protected static final String INVALID_PAYLOAD_MESSAGE = "Not Acceptable Payload"; + protected static final String HTTP_CONFLICT_MESSAGE = "Delete Conflict, Rule Violation"; + protected static final String ERROR_MESSAGE_NO_POLICIES_FOUND = "No policies found"; + + protected final Coder coder = new StandardCoder(); protected ResponseEntity makeOkResponse(UUID requestId, T respEntity) { HttpHeaders headers = new HttpHeaders(); @@ -89,4 +126,11 @@ public class CommonRestController { return null; } } + + @ExceptionHandler(value = {PolicyApiRuntimeException.class}) + protected ResponseEntity handleException(PolicyApiRuntimeException ex) { + LOGGER.warn(ex.getMessage(), ex.getCause()); + return makeErrorResponse(ex.getRequestId(), ex.getErrorResponse(), + ex.getErrorResponse().getResponseCode().getStatusCode()); + } } \ No newline at end of file