2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
26 package org.onap.appc.adapter.rest.impl;
28 import org.glassfish.grizzly.http.util.HttpStatus;
29 import com.att.cdp.zones.model.Server;
32 * This class is used to capture the exact cause and point of failure for the processing of a request. It is then used
33 * to encode the reason for the failure, status code, and anything else that needs to be captured and reported for
34 * diagnostic purposes.
36 public class RequestFailedException extends Exception {
41 private static final long serialVersionUID = 1L;
44 * The operation that was being requested or performed at the time of the failure.
46 private String operation;
49 * A message that details the reason for the failure
51 private String reason;
54 * The server that was being operated upon
56 private Server server;
59 * The id of the server being operated upon if the server object is not available (such as the server was not found)
61 private String serverId;
64 * The most appropriate Http Status code that reflects the error
66 private HttpStatus status;
71 public RequestFailedException() {
72 // intentionally empty
79 public RequestFailedException(String message) {
84 * Construct the request failed exception with the operation being performed, reason for the failure, http status
85 * code that is most appropriate, and the server we were processing.
88 * The operation being performed
90 * The reason that the operation was failed
92 * The http status code that is most appropriate
94 * The server that we were processing
96 @SuppressWarnings("nls")
97 public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
98 super(operation + ":" + reason);
99 this.operation = operation;
100 this.reason = reason;
101 this.status = status;
102 this.server = server;
103 if (server != null) {
104 this.serverId = server.getId();
109 * Construct the request failed exception with the operation being performed, reason for the failure, http status
110 * code that is most appropriate, and the server we were processing.
113 * The exception that we are wrapping
115 * The operation being performed
117 * The reason that the operation was failed
119 * The http status code that is most appropriate
121 * The server that we were processing
123 @SuppressWarnings("nls")
124 public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
125 super(operation + ":" + reason, ex);
126 this.operation = operation;
127 this.reason = reason;
128 this.status = status;
129 this.server = server;
130 if (server != null) {
131 this.serverId = server.getId();
141 public RequestFailedException(String message, Throwable cause) {
142 super(message, cause);
150 * @param enableSuppression
151 * whether or not suppression is enabled or disabled
152 * @param writableStackTrace
153 * whether or not the stack trace should be writable
155 public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
156 super(message, cause, enableSuppression, writableStackTrace);
161 * the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
162 * permitted, and indicates that the cause is nonexistent or unknown.)
164 public RequestFailedException(Throwable cause) {
169 * @return The operation being performed
171 public String getOperation() {
176 * @return The reason for the failure
178 public String getReason() {
183 * @return The server being operated upon
185 public Server getServer() {
190 * @return The id of the server being operated upon
192 public String getServerId() {
197 * @return The status code from the operation
199 public HttpStatus getStatus() {
205 * The operation being performed
207 public void setOperation(String operation) {
208 this.operation = operation;
213 * The reason for the failure
215 public void setReason(String reason) {
216 this.reason = reason;
221 * The server being operated upon
223 public void setServer(Server server) {
224 this.server = server;
225 if (server != null) {
226 setServerId(server.getId());
232 * The id of the server being operated upon
234 public void setServerId(String serverId) {
235 this.serverId = serverId;
240 * The status of the request
242 public void setStatus(HttpStatus status) {
243 this.status = status;