2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modification Copyright (C) 2019 IBM
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
28 package org.onap.appc.adapter.rest.impl;
30 import org.glassfish.grizzly.http.util.HttpStatus;
31 import com.att.cdp.zones.model.Server;
34 * This class is used to capture the exact cause and point of failure for the processing of a request. It is then used
35 * to encode the reason for the failure, status code, and anything else that needs to be captured and reported for
36 * diagnostic purposes.
38 public class RequestFailedException extends Exception {
43 private static final long serialVersionUID = 1L;
46 * The operation that was being requested or performed at the time of the failure.
48 private String operation;
51 * A message that details the reason for the failure
53 private String reason;
56 * The server that was being operated upon
58 private Server server;
61 * The id of the server being operated upon if the server object is not available (such as the server was not found)
63 private String serverId;
66 * The most appropriate Http Status code that reflects the error
68 private transient HttpStatus status;
73 public RequestFailedException() {
74 // intentionally empty
81 public RequestFailedException(String message) {
86 * Construct the request failed exception with the operation being performed, reason for the failure, http status
87 * code that is most appropriate, and the server we were processing.
90 * The operation being performed
92 * The reason that the operation was failed
94 * The http status code that is most appropriate
96 * The server that we were processing
98 @SuppressWarnings("nls")
99 public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
100 super(operation + ":" + reason);
101 this.operation = operation;
102 this.reason = reason;
103 this.status = status;
104 this.server = server;
105 if (server != null) {
106 this.serverId = server.getId();
111 * Construct the request failed exception with the operation being performed, reason for the failure, http status
112 * code that is most appropriate, and the server we were processing.
115 * The exception that we are wrapping
117 * The operation being performed
119 * The reason that the operation was failed
121 * The http status code that is most appropriate
123 * The server that we were processing
125 @SuppressWarnings("nls")
126 public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
127 super(operation + ":" + reason, ex);
128 this.operation = operation;
129 this.reason = reason;
130 this.status = status;
131 this.server = server;
132 if (server != null) {
133 this.serverId = server.getId();
143 public RequestFailedException(String message, Throwable cause) {
144 super(message, cause);
152 * @param enableSuppression
153 * whether or not suppression is enabled or disabled
154 * @param writableStackTrace
155 * whether or not the stack trace should be writable
157 public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
158 super(message, cause, enableSuppression, writableStackTrace);
163 * the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
164 * permitted, and indicates that the cause is nonexistent or unknown.)
166 public RequestFailedException(Throwable cause) {
171 * @return The operation being performed
173 public String getOperation() {
178 * @return The reason for the failure
180 public String getReason() {
185 * @return The server being operated upon
187 public Server getServer() {
192 * @return The id of the server being operated upon
194 public String getServerId() {
199 * @return The status code from the operation
201 public HttpStatus getStatus() {
207 * The operation being performed
209 public void setOperation(String operation) {
210 this.operation = operation;
215 * The reason for the failure
217 public void setReason(String reason) {
218 this.reason = reason;
223 * The server being operated upon
225 public void setServer(Server server) {
226 this.server = server;
227 if (server != null) {
228 setServerId(server.getId());
234 * The id of the server being operated upon
236 public void setServerId(String serverId) {
237 this.serverId = serverId;
242 * The status of the request
244 public void setStatus(HttpStatus status) {
245 this.status = status;