CADI and a few small updates.
[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                 logger.info(EELFLoggerDelegate.applicationLogger, "In MusicContainerFilter response filter ::::::::::::::::::::::::");
52                 
53                 if (null != EELFLoggerDelegate.mdcGet("transactionId")) {
54                     EELFLoggerDelegate.mdcRemove("transactionId");
55                 } 
56                 
57                 if (null != EELFLoggerDelegate.mdcGet("conversationId")) {
58                     EELFLoggerDelegate.mdcRemove("conversationId");
59                 } 
60                 
61                 if (null != EELFLoggerDelegate.mdcGet("clientId")) {
62                     EELFLoggerDelegate.mdcRemove("clientId");
63                 } 
64                         
65                 if (null != EELFLoggerDelegate.mdcGet("messageId")) {
66                     EELFLoggerDelegate.mdcRemove("messageId");
67                 }
68         }
69         
70 }