d2e5d637e9fcdb597df4b8962cdf278cbaca073b
[vid.git] / vid-app-common / src / main / java / org / onap / vid / model / ExceptionResponse.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
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 package org.onap.vid.model;
22
23 import org.slf4j.MDC;
24
25 import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
26
27 /**
28  * The Class ExceptionResponse.
29  */
30 public class ExceptionResponse {
31
32         public ExceptionResponse() {
33         }
34
35         /** The exception. */
36         private String exception;
37         
38         /** The message. */
39         private String message;
40
41         public ExceptionResponse(String exception, String message) {
42                 this.exception = exception;
43                 this.message = message;
44         }
45
46         public ExceptionResponse(Exception exception) {
47                 setException(exception);
48         }
49
50         /**
51          * Gets the exception.
52          *
53          * @return the exception
54          */
55         public String getException() {
56                 return exception;
57         }
58
59         /**
60          * Sets the exception.
61          *
62          * @param exception the new exception
63          */
64         public void setException(String exception) {
65                 this.exception = exception;
66         }
67
68         public void setException(Exception exception) {
69                 setException(exception.getClass().toString().replaceFirst("^.*[\\.$]", ""));
70                 setMessage(exception.getMessage() + " (Request id: " + MDC.get(MDC_KEY_REQUEST_ID) + ")");
71         }
72
73         /**
74          * Gets the message.
75          *
76          * @return the message
77          */
78         public String getMessage() {
79                 return message;
80         }
81
82         /**
83          * Sets the message.
84          *
85          * @param message the new message
86          */
87         public void setMessage(String message) {
88                 this.message = message;
89         }
90
91 }