* ================================================================================\r
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.\r
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.\r
+ * Modifications Copyright (C) 2022 Nordix Foundation.\r
* ================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
package org.onap.policy.api.main.rest;\r
\r
import java.util.UUID;\r
+import org.onap.policy.api.main.exception.PolicyApiRuntimeException;\r
import org.onap.policy.common.utils.coder.Coder;\r
import org.onap.policy.common.utils.coder.CoderException;\r
import org.onap.policy.common.utils.coder.StandardCoder;\r
import org.slf4j.LoggerFactory;\r
import org.springframework.http.HttpHeaders;\r
import org.springframework.http.ResponseEntity;\r
+import org.springframework.web.bind.annotation.ExceptionHandler;\r
\r
/**\r
* Super class from which REST controllers are derived.\r
\r
private static final Logger LOGGER = LoggerFactory.getLogger(CommonRestController.class);\r
\r
- private final Coder coder = new StandardCoder();\r
+ protected static final String EXTENSION_NAME = "interface info";\r
+\r
+ protected static final String API_VERSION_NAME = "api-version";\r
+ protected static final String API_VERSION = "1.0.0";\r
+\r
+ protected static final String LAST_MOD_NAME = "last-mod-release";\r
+\r
+ protected static final String AUTHORIZATION_TYPE = "basicAuth";\r
+\r
+ protected static final String VERSION_MINOR_NAME = "X-MinorVersion";\r
+ protected static final String VERSION_MINOR_DESCRIPTION =\r
+ "Used to request or communicate a MINOR version back from the client"\r
+ + " to the server, and from the server back to the client";\r
+\r
+ protected static final String VERSION_PATCH_NAME = "X-PatchVersion";\r
+ protected static final String VERSION_PATCH_DESCRIPTION = "Used only to communicate a PATCH version in a "\r
+ + "response for troubleshooting purposes only, and will not be provided by" + " the client on request";\r
+\r
+ protected static final String VERSION_LATEST_NAME = "X-LatestVersion";\r
+ protected static final String VERSION_LATEST_DESCRIPTION = "Used only to communicate an API's latest version";\r
+\r
+ protected static final String REQUEST_ID_NAME = "X-ONAP-RequestID";\r
+ protected static final String REQUEST_ID_HDR_DESCRIPTION = "Used to track REST transactions for logging purpose";\r
+ protected static final String REQUEST_ID_PARAM_DESCRIPTION = "RequestID for http transaction";\r
+\r
+ protected static final String AUTHENTICATION_ERROR_MESSAGE = "Authentication Error";\r
+ protected static final String AUTHORIZATION_ERROR_MESSAGE = "Authorization Error";\r
+ protected static final String SERVER_ERROR_MESSAGE = "Internal Server Error";\r
+ protected static final String NOT_FOUND_MESSAGE = "Resource Not Found";\r
+ protected static final String INVALID_BODY_MESSAGE = "Invalid Body";\r
+ protected static final String INVALID_PAYLOAD_MESSAGE = "Not Acceptable Payload";\r
+ protected static final String HTTP_CONFLICT_MESSAGE = "Delete Conflict, Rule Violation";\r
+ protected static final String ERROR_MESSAGE_NO_POLICIES_FOUND = "No policies found";\r
+\r
+ protected final Coder coder = new StandardCoder();\r
\r
protected <T> ResponseEntity<T> makeOkResponse(UUID requestId, T respEntity) {\r
HttpHeaders headers = new HttpHeaders();\r
return null;\r
}\r
}\r
+\r
+ @ExceptionHandler(value = {PolicyApiRuntimeException.class})\r
+ protected ResponseEntity<Object> handleException(PolicyApiRuntimeException ex) {\r
+ LOGGER.warn(ex.getMessage(), ex.getCause());\r
+ return makeErrorResponse(ex.getRequestId(), ex.getErrorResponse(),\r
+ ex.getErrorResponse().getResponseCode().getStatusCode());\r
+ }\r
}
\ No newline at end of file