2 * Copyright 2016 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.resmanagement.common.util.restclient;
19 import java.text.MessageFormat;
22 * The base class for all common exception.<br/>
27 * @version 28-May-2016
29 public class ServiceException extends Exception {
32 * default exception id.
34 public static final String DEFAULT_ID = "framwork.remote.SystemError";
39 private static final long serialVersionUID = 5703294364555144738L;
44 private String id = DEFAULT_ID;
46 private Object[] args = null;
48 private int httpCode = 500;
50 private ExceptionArgs exceptionArgs = null;
53 * The default constructor<br/>
55 * This method is only used as deserialized, in other cases, use parameterized constructor.
60 public ServiceException() {
71 * @param cause: reason.
73 public ServiceException(final String id, final Throwable cause) {
84 * @param message: details.
86 public ServiceException(final String message) {
96 * @param id: exception id.
97 * @param message: details.
99 public ServiceException(final String id, final String message) {
110 * @param id: exception id.
111 * @param httpCode: http status code.
113 public ServiceException(final String id, final int httpCode) {
116 this.setHttpCode(httpCode);
122 * the exception include the httpcode and message.
126 * @param httpCode http code.
127 * @param message details.
129 public ServiceException(final int httpCode, final String message) {
131 this.setHttpCode(httpCode);
140 * @param id: exception id.
141 * @param httpCode: http code.
142 * @param exceptionArgs: Exception handling frame parameters.
144 public ServiceException(final String id, final int httpCode, final ExceptionArgs exceptionArgs) {
147 this.setHttpCode(httpCode);
148 this.setExceptionArgs(exceptionArgs);
154 * Have a placeholder exception, use args formatted message.
158 * @param id: exception id.
159 * @param message: details.
160 * @param args: Placeholders for parameters
162 public ServiceException(final String id, final String message, final Object... args) {
163 super(MessageFormat.format(message, args));
171 * Have a placeholder exception, use args formatted message
175 * @param id: exception id.
176 * @param message: details.
177 * @param cause: reason.
178 * @param args: placeholder for parameters
180 public ServiceException(final String id, final String message, final Throwable cause, final Object... args) {
181 super(MessageFormat.format(message, args), cause);
192 * @param id: exception id.
193 * @param message: details.
194 * @param cause: reason.
196 public ServiceException(final String id, final String message, final Throwable cause) {
197 super(message, cause);
207 * @param cause: reason.
209 public ServiceException(final Throwable cause) {
214 * Get exceptoin id.<br/>
219 public String getId() {
220 if(id == null || id.isEmpty()) {
226 public void setId(final String id) {
230 public int getHttpCode() {
231 return this.httpCode;
234 public void setHttpCode(final int httpCode) {
235 this.httpCode = httpCode;
239 * Obtain the ROA exception handling framework parameters<br/>
241 * @return exception args.
244 public ExceptionArgs getExceptionArgs() {
245 return exceptionArgs;
248 public void setExceptionArgs(final ExceptionArgs exceptionArgs) {
249 this.exceptionArgs = exceptionArgs;
253 * Gets the parameter information<br/>
255 * @return parameter list.
258 protected Object[] getArgs() {
259 if(args == null || args.length == 0 || DEFAULT_ID.equals(getId())) {
260 return new Object[] {};
266 public String toString() {
267 return "exception.id: " + getId() + "; " + super.toString();