summaryrefslogtreecommitdiffstats
path: root/cxf-logging
diff options
context:
space:
mode:
Diffstat (limited to 'cxf-logging')
-rw-r--r--cxf-logging/.gitignore2
-rw-r--r--cxf-logging/pom.xml66
-rw-r--r--cxf-logging/src/main/java/org/onap/so/logging/cxf/interceptor/SOAPLoggingInInterceptor.java84
-rw-r--r--cxf-logging/src/main/java/org/onap/so/logging/cxf/interceptor/SOAPLoggingOutInterceptor.java49
-rw-r--r--cxf-logging/src/main/java/org/onap/so/logging/cxf/interceptor/SOAPMDCSetup.java53
-rw-r--r--cxf-logging/src/test/resources/logback-test.xml75
6 files changed, 329 insertions, 0 deletions
diff --git a/cxf-logging/.gitignore b/cxf-logging/.gitignore
new file mode 100644
index 0000000000..c2a96233ca
--- /dev/null
+++ b/cxf-logging/.gitignore
@@ -0,0 +1,2 @@
+/tattletale-jar/
+/bin/
diff --git a/cxf-logging/pom.xml b/cxf-logging/pom.xml
new file mode 100644
index 0000000000..378d169175
--- /dev/null
+++ b/cxf-logging/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.so</groupId>
+ <artifactId>so</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ </parent>
+ <name>CXFLogging</name>
+ <description>Common CXF Logging Classes</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-client</artifactId>
+ <version>${cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-bindings-soap</artifactId>
+ <version>${cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http</artifactId>
+ <version>${cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-ext</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-slf4j</artifactId>
+ <version>1.2.2-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.att.eelf</groupId>
+ <artifactId>eelf-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ <resource>
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
+ <artifactId>cxf-logging</artifactId>
+</project>
diff --git a/cxf-logging/src/main/java/org/onap/so/logging/cxf/interceptor/SOAPLoggingInInterceptor.java b/cxf-logging/src/main/java/org/onap/so/logging/cxf/interceptor/SOAPLoggingInInterceptor.java
new file mode 100644
index 0000000000..52d26fb09a
--- /dev/null
+++ b/cxf-logging/src/main/java/org/onap/so/logging/cxf/interceptor/SOAPLoggingInInterceptor.java
@@ -0,0 +1,84 @@
+package org.onap.so.logging.cxf.interceptor;
+
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+
+
+public class SOAPLoggingInInterceptor extends AbstractSoapInterceptor{
+
+ protected static Logger logger = LoggerFactory.getLogger(SOAPLoggingInInterceptor.class);
+
+ public SOAPLoggingInInterceptor() {
+ super(Phase.READ);
+ }
+
+ @Override
+ public void handleMessage(SoapMessage message) throws Fault {
+ try {
+ SOAPMDCSetup mdcSetup = new SOAPMDCSetup();
+ Map<String, List<String>> headers = (Map<String,List<String>>) message.get(Message.PROTOCOL_HEADERS);
+ HttpServletRequest request = (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
+ request.getRemoteAddr();
+
+ setRequestId(headers);
+ setInvocationId(headers);
+ setServiceName(message);
+ setMDCPartnerName(headers);
+ mdcSetup.setServerFQDN();
+ mdcSetup.setClientIPAddress(request);
+ mdcSetup.setInstanceUUID();
+ mdcSetup.setEntryTimeStamp();
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, "INPROGRESS");
+ logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
+ } catch (Exception e) {
+ logger.warn("Error in incoming SOAP Message Inteceptor", e);
+ }
+ }
+
+ private void setServiceName(SoapMessage message) {
+ String requestURI = (String) message.get(Message.REQUEST_URI);
+ MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, requestURI);
+ }
+
+ //CXF Appears to flatten headers to lower case
+ private void setMDCPartnerName(Map<String, List<String>> headers){
+ String partnerName=getValueOrDefault(headers, ONAPLogConstants.Headers.PARTNER_NAME.toLowerCase(),"");
+ MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME,partnerName);
+ }
+
+ private void setInvocationId(Map<String, List<String>> headers) {
+ String invocationId=getValueOrDefault(headers, ONAPLogConstants.Headers.INVOCATION_ID.toLowerCase(),UUID.randomUUID().toString());
+ MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
+ }
+
+ private void setRequestId(Map<String, List<String>> headers) {
+ String requestId=getValueOrDefault(headers, ONAPLogConstants.Headers.REQUEST_ID.toLowerCase(),UUID.randomUUID().toString());
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID,requestId);
+ }
+
+ private String getValueOrDefault(Map<String, List<String>> headers, String headerName, String defaultValue){
+ String headerValue;
+ List<String> headerList=headers.get(headerName);
+ if(headerList != null && !headerList.isEmpty()){
+ headerValue= headerList.get(0);
+ if(headerValue == null || headerValue.isEmpty())
+ headerValue = defaultValue;
+ }else
+ headerValue = defaultValue;
+ return headerValue;
+ }
+
+}
diff --git a/cxf-logging/src/main/java/org/onap/so/logging/cxf/interceptor/SOAPLoggingOutInterceptor.java b/cxf-logging/src/main/java/org/onap/so/logging/cxf/interceptor/SOAPLoggingOutInterceptor.java
new file mode 100644
index 0000000000..1ddf268ea8
--- /dev/null
+++ b/cxf-logging/src/main/java/org/onap/so/logging/cxf/interceptor/SOAPLoggingOutInterceptor.java
@@ -0,0 +1,49 @@
+package org.onap.so.logging.cxf.interceptor;
+
+
+import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+
+
+
+public class SOAPLoggingOutInterceptor extends AbstractSoapInterceptor{
+
+ private static final String _500 = "500";
+
+ protected static Logger logger = LoggerFactory.getLogger(SOAPLoggingOutInterceptor.class);
+
+
+
+ public SOAPLoggingOutInterceptor() {
+ super(Phase.WRITE);
+ }
+
+ @Override
+ public void handleMessage(SoapMessage message) throws Fault {
+ try {
+ Exception ex = message.getContent(Exception.class);
+ if (ex == null) {
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.COMPLETED.toString());
+ }else{
+ int responseCode = 0;
+ responseCode = (int) message.get(Message.RESPONSE_CODE);
+ if(responseCode != 0 )
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, String.valueOf(responseCode));
+ else
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, _500);
+
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.ERROR.toString());
+ }
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
+ } catch (Exception e) {
+ logger.warn("Error in incoming SOAP Message Inteceptor", e);
+ }
+ }
+}
diff --git a/cxf-logging/src/main/java/org/onap/so/logging/cxf/interceptor/SOAPMDCSetup.java b/cxf-logging/src/main/java/org/onap/so/logging/cxf/interceptor/SOAPMDCSetup.java
new file mode 100644
index 0000000000..6991949dd0
--- /dev/null
+++ b/cxf-logging/src/main/java/org/onap/so/logging/cxf/interceptor/SOAPMDCSetup.java
@@ -0,0 +1,53 @@
+package org.onap.so.logging.cxf.interceptor;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.UUID;
+import javax.servlet.http.HttpServletRequest;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+
+
+
+public class SOAPMDCSetup {
+
+ protected static Logger logger = LoggerFactory.getLogger(SOAPMDCSetup.class);
+
+ private static final String INSTANCE_UUID = UUID.randomUUID().toString();
+
+ public void setInstanceUUID(){
+ MDC.put(ONAPLogConstants.MDCs.INSTANCE_UUID, INSTANCE_UUID);
+ }
+
+ public void setServerFQDN(){
+ String serverFQDN = "";
+ InetAddress addr= null;
+ try {
+ addr = InetAddress.getLocalHost();
+ serverFQDN = addr.toString();
+ } catch (UnknownHostException e) {
+ logger.warn("Cannot Resolve Host Name");
+ serverFQDN = "";
+ }
+ MDC.put(ONAPLogConstants.MDCs.SERVER_FQDN, serverFQDN);
+ }
+
+ public void setClientIPAddress(HttpServletRequest httpServletRequest){
+ String remoteIpAddress = "";
+ if (httpServletRequest != null) {
+ remoteIpAddress = httpServletRequest.getRemoteAddr();
+ }
+ MDC.put(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS, remoteIpAddress);
+ }
+
+ public void setEntryTimeStamp() {
+ MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP,ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
+ }
+
+
+} \ No newline at end of file
diff --git a/cxf-logging/src/test/resources/logback-test.xml b/cxf-logging/src/test/resources/logback-test.xml
new file mode 100644
index 0000000000..772eeabeb6
--- /dev/null
+++ b/cxf-logging/src/test/resources/logback-test.xml
@@ -0,0 +1,75 @@
+<!--
+ ============LICENSE_START=======================================================
+ ONAP SO
+ ================================================================================
+ Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ ================================================================================
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ============LICENSE_END=========================================================
+ -->
+
+<configuration>
+ <property name="p_tim" value="%d{&quot;yyyy-MM-dd'T'HH:mm:ss.SSSXXX&quot;, UTC}"/>
+ <property name="p_lvl" value="%level"/>
+ <property name="p_log" value="%logger"/>
+ <property name="p_mdc" value="%replace(%replace(%mdc){'\t','\\\\t'}){'\n', '\\\\n'}"/>
+ <property name="p_msg" value="%replace(%replace(%msg){'\t', '\\\\t'}){'\n','\\\\n'}"/>
+ <property name="p_exc" value="%replace(%replace(%rootException){'\t', '\\\\t'}){'\n','\\\\n'}"/>
+ <property name="p_mak" value="%replace(%replace(%marker){'\t', '\\\\t'}){'\n','\\\\n'}"/>
+ <property name="p_thr" value="%thread"/>
+ <property name="pattern" value="%nopexception${p_tim}\t${p_thr}\t${p_lvl}\t${p_log}\t${p_mdc}\t${p_msg}\t${p_exc}\t${p_mak}\t%n"/>
+
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>${pattern}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="test"
+ class="org.onap.so.utils.TestAppender" />
+
+ <logger name="com.att.ecomp.audit" level="info" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="com.att.eelf.metrics" level="info" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="com.att.eelf.error" level="WARN" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.onap" level="${so.log.level:-DEBUG}" additivity="false">
+ <appender-ref ref="STDOUT" />
+ <appender-ref ref="test" />
+ </logger>
+
+ <logger name="org.flywaydb" level="DEBUG" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+
+ <logger name="ch.vorburger" level="WARN" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+
+ <root level="WARN">
+ <appender-ref ref="STDOUT" />
+ <appender-ref ref="test" />
+ </root>
+
+
+</configuration> \ No newline at end of file