Some bug fixes and Minor Chages.
[music.git] / src / main / java / org / onap / music / eelf / logging / MusicContainerFilter.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
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  * 
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22 package org.onap.music.eelf.logging;
23
24 import java.io.IOException;
25
26 import javax.ws.rs.container.ContainerRequestContext;
27 import javax.ws.rs.container.ContainerResponseContext;
28 import javax.ws.rs.container.ContainerResponseFilter;
29
30 import org.springframework.stereotype.Component;
31
32
33 /**
34  * This filter filter/modifies outbound http responses just before sending back to client. 
35  * 
36  * @author sp931a
37  *
38  */
39 @Component
40 public class MusicContainerFilter implements  ContainerResponseFilter {
41
42     private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicContainerFilter.class);
43     
44     public MusicContainerFilter() {
45         
46     }
47     
48     @Override
49     public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
50             throws IOException {
51         if (null != EELFLoggerDelegate.mdcGet("transactionId")) {
52             EELFLoggerDelegate.mdcRemove("transactionId");
53         } 
54         
55         if (null != EELFLoggerDelegate.mdcGet("conversationId")) {
56             EELFLoggerDelegate.mdcRemove("conversationId");
57         } 
58         
59         if (null != EELFLoggerDelegate.mdcGet("clientId")) {
60             EELFLoggerDelegate.mdcRemove("clientId");
61         } 
62             
63         if (null != EELFLoggerDelegate.mdcGet("messageId")) {
64             EELFLoggerDelegate.mdcRemove("messageId");
65         }
66     }
67     
68 }