blob: 7d7db2309255971ec91656f554b0a1af852acfa5 [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21
22
23package org.onap.osam.model;
24
25import org.slf4j.MDC;
26
27import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
28
29public class ExceptionResponse {
30
31 public ExceptionResponse() {
32 }
33
34 private String exception;
35
36 /** The message. */
37 private String message;
38
39 public ExceptionResponse(String exception, String message) {
40 this.exception = exception;
41 this.message = message;
42 }
43
44 public ExceptionResponse(Exception exception) {
45 setException(exception);
46 }
47
48 /**
49 * Gets the exception.
50 *
51 * @return the exception
52 */
53 public String getException() {
54 return exception;
55 }
56
57 /**
58 * Sets the exception.
59 *
60 * @param exception the new exception
61 */
62 public void setException(String exception) {
63 this.exception = exception;
64 }
65
66 public void setException(Exception exception) {
67 setException(exception.getClass().toString().replaceFirst("^.*[\\.$]", ""));
68 setMessage(exception.getMessage() + " (Request id: " + MDC.get(MDC_KEY_REQUEST_ID) + ")");
69 }
70
71 /**
72 * Gets the message.
73 *
74 * @return the message
75 */
76 public String getMessage() {
77 return message;
78 }
79
80 /**
81 * Sets the message.
82 *
83 * @param message the new message
84 */
85 public void setMessage(String message) {
86 this.message = message;
87 }
88
89}