added generic fabric support to SO
[so.git] / cxf-logging / src / main / java / org / onap / so / logging / cxf / interceptor / SOAPLoggingOutInterceptor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 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.so.logging.cxf.interceptor;
22
23
24 import org.apache.cxf.binding.soap.SoapMessage;
25 import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
26 import org.apache.cxf.interceptor.Fault;
27 import org.apache.cxf.message.Message;
28 import org.apache.cxf.phase.Phase;
29 import org.onap.logging.ref.slf4j.ONAPLogConstants;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.slf4j.MDC;
33
34
35
36 public class SOAPLoggingOutInterceptor extends AbstractSoapInterceptor{
37
38     private static final String _500 = "500";
39
40     protected static Logger logger = LoggerFactory.getLogger(SOAPLoggingOutInterceptor.class);
41     
42
43     
44     public SOAPLoggingOutInterceptor() {
45         super(Phase.WRITE);
46     }
47
48     @Override
49     public void handleMessage(SoapMessage message) throws Fault {
50         try {
51             Exception ex = message.getContent(Exception.class);
52             if (ex == null) {
53                 MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.COMPLETED.toString());
54             }else{
55                 int responseCode = 0;
56                 responseCode = (int) message.get(Message.RESPONSE_CODE);
57                 if(responseCode != 0 )
58                     MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, String.valueOf(responseCode));
59                 else
60                     MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, _500);
61                 
62                 MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.ERROR.toString());
63             }
64             logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
65         } catch (Exception e) {
66             logger.warn("Error in incoming SOAP Message Inteceptor", e);
67         }
68     }
69 }