2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
25 package org.openecomp.appc.adapter.rest.impl;
27 import org.glassfish.grizzly.http.util.HttpStatus;
28 import com.att.cdp.zones.model.Server;
31 * This class is used to capture the exact cause and point of failure for the processing of a request. It is then used
32 * to encode the reason for the failure, status code, and anything else that needs to be captured and reported for
33 * diagnostic purposes.
35 public class RequestFailedException extends Exception {
40 private static final long serialVersionUID = 1L;
43 * The operation that was being requested or performed at the time of the failure.
45 private String operation;
48 * A message that details the reason for the failure
50 private String reason;
53 * The server that was being operated upon
55 private Server server;
58 * The id of the server being operated upon if the server object is not available (such as the server was not found)
60 private String serverId;
63 * The most appropriate Http Status code that reflects the error
65 private HttpStatus status;
70 public RequestFailedException() {
71 // intentionally empty
78 public RequestFailedException(String message) {
83 * Construct the request failed exception with the operation being performed, reason for the failure, http status
84 * code that is most appropriate, and the server we were processing.
87 * The operation being performed
89 * The reason that the operation was failed
91 * The http status code that is most appropriate
93 * The server that we were processing
95 @SuppressWarnings("nls")
96 public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
97 super(operation + ":" + reason);
98 this.operation = operation;
100 this.status = status;
101 this.server = server;
102 if (server != null) {
103 this.serverId = server.getId();
108 * Construct the request failed exception with the operation being performed, reason for the failure, http status
109 * code that is most appropriate, and the server we were processing.
112 * The exception that we are wrapping
114 * The operation being performed
116 * The reason that the operation was failed
118 * The http status code that is most appropriate
120 * The server that we were processing
122 @SuppressWarnings("nls")
123 public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
124 super(operation + ":" + reason, ex);
125 this.operation = operation;
126 this.reason = reason;
127 this.status = status;
128 this.server = server;
129 if (server != null) {
130 this.serverId = server.getId();
140 public RequestFailedException(String message, Throwable cause) {
141 super(message, cause);
149 * @param enableSuppression
150 * whether or not suppression is enabled or disabled
151 * @param writableStackTrace
152 * whether or not the stack trace should be writable
154 public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
155 super(message, cause, enableSuppression, writableStackTrace);
160 * the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
161 * permitted, and indicates that the cause is nonexistent or unknown.)
163 public RequestFailedException(Throwable cause) {
168 * @return The operation being performed
170 public String getOperation() {
175 * @return The reason for the failure
177 public String getReason() {
182 * @return The server being operated upon
184 public Server getServer() {
189 * @return The id of the server being operated upon
191 public String getServerId() {
196 * @return The status code from the operation
198 public HttpStatus getStatus() {
204 * The operation being performed
206 public void setOperation(String operation) {
207 this.operation = operation;
212 * The reason for the failure
214 public void setReason(String reason) {
215 this.reason = reason;
220 * The server being operated upon
222 public void setServer(Server server) {
223 this.server = server;
224 if (server != null) {
225 setServerId(server.getId());
231 * The id of the server being operated upon
233 public void setServerId(String serverId) {
234 this.serverId = serverId;
239 * The status of the request
241 public void setStatus(HttpStatus status) {
242 this.status = status;