2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
27 package org.onap.appc.adapter.rest.impl;
29 import org.glassfish.grizzly.http.util.HttpStatus;
30 import com.att.cdp.zones.model.Server;
33 * This class is used to capture the exact cause and point of failure for the processing of a request. It is then used
34 * to encode the reason for the failure, status code, and anything else that needs to be captured and reported for
35 * diagnostic purposes.
37 public class RequestFailedException extends Exception {
42 private static final long serialVersionUID = 1L;
45 * The operation that was being requested or performed at the time of the failure.
47 private String operation;
50 * A message that details the reason for the failure
52 private String reason;
55 * The server that was being operated upon
57 private Server server;
60 * The id of the server being operated upon if the server object is not available (such as the server was not found)
62 private String serverId;
65 * The most appropriate Http Status code that reflects the error
67 private HttpStatus status;
72 public RequestFailedException() {
73 // intentionally empty
80 public RequestFailedException(String message) {
85 * Construct the request failed exception with the operation being performed, reason for the failure, http status
86 * code that is most appropriate, and the server we were processing.
89 * The operation being performed
91 * The reason that the operation was failed
93 * The http status code that is most appropriate
95 * The server that we were processing
97 @SuppressWarnings("nls")
98 public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
99 super(operation + ":" + reason);
100 this.operation = operation;
101 this.reason = reason;
102 this.status = status;
103 this.server = server;
104 if (server != null) {
105 this.serverId = server.getId();
110 * Construct the request failed exception with the operation being performed, reason for the failure, http status
111 * code that is most appropriate, and the server we were processing.
114 * The exception that we are wrapping
116 * The operation being performed
118 * The reason that the operation was failed
120 * The http status code that is most appropriate
122 * The server that we were processing
124 @SuppressWarnings("nls")
125 public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
126 super(operation + ":" + reason, ex);
127 this.operation = operation;
128 this.reason = reason;
129 this.status = status;
130 this.server = server;
131 if (server != null) {
132 this.serverId = server.getId();
142 public RequestFailedException(String message, Throwable cause) {
143 super(message, cause);
151 * @param enableSuppression
152 * whether or not suppression is enabled or disabled
153 * @param writableStackTrace
154 * whether or not the stack trace should be writable
156 public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
157 super(message, cause, enableSuppression, writableStackTrace);
162 * the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
163 * permitted, and indicates that the cause is nonexistent or unknown.)
165 public RequestFailedException(Throwable cause) {
170 * @return The operation being performed
172 public String getOperation() {
177 * @return The reason for the failure
179 public String getReason() {
184 * @return The server being operated upon
186 public Server getServer() {
191 * @return The id of the server being operated upon
193 public String getServerId() {
198 * @return The status code from the operation
200 public HttpStatus getStatus() {
206 * The operation being performed
208 public void setOperation(String operation) {
209 this.operation = operation;
214 * The reason for the failure
216 public void setReason(String reason) {
217 this.reason = reason;
222 * The server being operated upon
224 public void setServer(Server server) {
225 this.server = server;
226 if (server != null) {
227 setServerId(server.getId());
233 * The id of the server being operated upon
235 public void setServerId(String serverId) {
236 this.serverId = serverId;
241 * The status of the request
243 public void setStatus(HttpStatus status) {
244 this.status = status;