metric log updates and util fix
[logging-analytics.git] / reference / logging-filter / logging-filter-base / src / main / java / org / onap / logging / filter / base / SoapMetricLogHandler.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - Logging
4  * ================================================================================
5  * Copyright (C) 2020 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.logging.filter.base;
22
23 import java.util.Set;
24
25 import javax.xml.namespace.QName;
26 import javax.xml.ws.handler.MessageContext;
27 import javax.xml.ws.handler.soap.SOAPHandler;
28 import javax.xml.ws.handler.soap.SOAPMessageContext;
29
30 public class SoapMetricLogHandler extends AbstractBaseMetricLogFilter<SOAPMessageContext, SOAPMessageContext>
31         implements SOAPHandler<SOAPMessageContext> {
32
33     @Override
34     protected int getHttpStatusCode(SOAPMessageContext ctx) {
35         return (Integer) ctx.get(MessageContext.HTTP_RESPONSE_CODE);
36     }
37
38     @Override
39     protected String getResponseCode(SOAPMessageContext ctx) {
40         Integer responseCode = (Integer) ctx.get(MessageContext.HTTP_RESPONSE_CODE);
41         return String.valueOf(responseCode);
42     }
43
44     @Override
45     protected String getTargetEntity(SOAPMessageContext ctx) {
46         return Constants.DefaultValues.UNKNOWN_TARGET_ENTITY;
47     }
48
49     @Override
50     protected String getTargetServiceName(SOAPMessageContext ctx) {
51         QName svc = (QName) ctx.get(SOAPMessageContext.WSDL_SERVICE);
52         QName op = (QName) ctx.get(SOAPMessageContext.WSDL_OPERATION);
53         return svc.getLocalPart() + ":" + op.getLocalPart();
54     }
55
56     @Override
57     public void close(MessageContext context) {
58         // pass
59     }
60
61     @Override
62     public boolean handleFault(SOAPMessageContext context) {
63         logMessage(context);
64         return true;
65     }
66
67     @Override
68     public boolean handleMessage(SOAPMessageContext context) {
69         logMessage(context);
70         return true;
71     }
72
73     @Override
74     public Set<QName> getHeaders() {
75         return null;
76     }
77
78     private void logMessage(SOAPMessageContext context) {
79         boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
80         if (outbound) {
81             this.pre(context);
82         } else {
83             this.post(context, context);
84         }
85     }
86
87 }