update sliapi-springboot 38/103138/6
authorSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Thu, 5 Mar 2020 15:30:45 +0000 (15:30 +0000)
committerDan Timoney <dtimoney@att.com>
Thu, 5 Mar 2020 21:03:27 +0000 (21:03 +0000)
add sample log4j2 config for spring boot sli api

Issue-ID: CCSDK-2161
Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Change-Id: If24315ad6cad1061d1e65e080f4122605b05df47

sliapi/springboot/pom.xml
sliapi/springboot/src/main/java/org/onap/ccsdk/sli/core/sliapi/springboot/App.java
sliapi/springboot/src/main/java/org/onap/ccsdk/sli/core/sliapi/springboot/controllers/ExecuteGraphController.java
sliapi/springboot/src/main/java/org/onap/ccsdk/sli/core/sliapi/springboot/controllers/swagger/RestconfApiController.java
sliapi/springboot/src/main/java/org/onap/ccsdk/sli/core/sliapi/springboot/core/ServletFilters.java [new file with mode: 0644]
sliapi/springboot/src/main/java/org/onap/ccsdk/sli/core/sliapi/springboot/core/SvcLogicFactory.java
sliapi/springboot/src/main/java/org/onap/ccsdk/sli/core/sliapi/springboot/core/WebConfig.java [new file with mode: 0644]
sliapi/springboot/src/main/resources/log4j2.properties [new file with mode: 0644]
sliapi/springboot/src/test/java/org/onap/ccsdk/sli/core/sliapi/springboot/RestconfApiControllerTest.java

index dc2c16d..6bdb139 100644 (file)
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
-        </dependency>
+                       <exclusions>
+                               <exclusion>
+                                       <groupId>org.springframework.boot</groupId>
+                                       <artifactId>spring-boot-starter-logging</artifactId>
+                               </exclusion>
+                       </exclusions>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework.boot</groupId>
+                       <artifactId>spring-boot-starter-log4j2</artifactId>
+               </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
+        </dependency>
+               <dependency>
+                       <groupId>org.onap.logging-analytics</groupId>
+                       <artifactId>logging-filter-spring</artifactId>
+                       <version>1.6.4</version>
+               </dependency>
+        <dependency>
+            <groupId>javax.ws.rs</groupId>
+            <artifactId>javax.ws.rs-api</artifactId>
         </dependency>
     </dependencies>
 
index 941c1d5..67f5491 100644 (file)
@@ -1,3 +1,23 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - CCSDK\r
+ * ================================================================================\r
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
 package org.onap.ccsdk.sli.core.sliapi.springboot;\r
 \r
 import org.springframework.boot.SpringApplication;\r
index efdefbd..809cfe5 100644 (file)
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2020 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=========================================================
+ */
+
 package org.onap.ccsdk.sli.core.sliapi.springboot.controllers;
 
 import java.util.HashMap;
@@ -25,14 +45,10 @@ import com.google.gson.JsonParser;
 public class ExecuteGraphController {
   @Autowired
   protected SvcLogicServiceBase svc;
-       private static final Logger LOGGER = LoggerFactory.getLogger(ExecuteGraphController.class);
 
        @RequestMapping(value = "/executeGraph", method = RequestMethod.POST)
        @ResponseBody
        public HashMap<String, String> executeGraph(@RequestBody String input) {
-               LOGGER.error("In request");
-               LOGGER.error(input);
-
                HashMap<String, String> hash = new HashMap<String, String>();
                Properties parms = new Properties();
 
index 10442d4..2972cd7 100644 (file)
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2020 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=========================================================
+ */
+
 package org.onap.ccsdk.sli.core.sliapi.springboot.controllers.swagger;
 
 import java.util.Map;
diff --git a/sliapi/springboot/src/main/java/org/onap/ccsdk/sli/core/sliapi/springboot/core/ServletFilters.java b/sliapi/springboot/src/main/java/org/onap/ccsdk/sli/core/sliapi/springboot/core/ServletFilters.java
new file mode 100644 (file)
index 0000000..c56cf3b
--- /dev/null
@@ -0,0 +1,42 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - CCSDK\r
+ * ================================================================================\r
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.ccsdk.sli.core.sliapi.springboot.core;\r
+\r
+import javax.servlet.ServletException;\r
+\r
+import org.onap.logging.filter.base.PayloadLoggingServletFilter;\r
+import org.springframework.boot.web.servlet.FilterRegistrationBean;\r
+import org.springframework.context.annotation.Bean;\r
+import org.springframework.context.annotation.Configuration;\r
+\r
+@Configuration\r
+public class ServletFilters {\r
+\r
+       @Bean\r
+       public FilterRegistrationBean<PayloadLoggingServletFilter> payloadFilterRegistration() throws ServletException {\r
+               FilterRegistrationBean<PayloadLoggingServletFilter> registration = new FilterRegistrationBean<PayloadLoggingServletFilter>();\r
+               registration.setFilter(new PayloadLoggingServletFilter());\r
+               registration.addUrlPatterns("/*");\r
+               registration.setName("payloadFilter");\r
+               registration.setOrder(0);\r
+               return registration;\r
+       }\r
+}
\ No newline at end of file
index f39fc22..a6bda81 100644 (file)
@@ -1,3 +1,23 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - CCSDK\r
+ * ================================================================================\r
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
 package org.onap.ccsdk.sli.core.sliapi.springboot.core;\r
 \r
 import java.io.FileInputStream;\r
diff --git a/sliapi/springboot/src/main/java/org/onap/ccsdk/sli/core/sliapi/springboot/core/WebConfig.java b/sliapi/springboot/src/main/java/org/onap/ccsdk/sli/core/sliapi/springboot/core/WebConfig.java
new file mode 100644 (file)
index 0000000..fb4fe08
--- /dev/null
@@ -0,0 +1,43 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - CCSDK\r
+ * ================================================================================\r
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.ccsdk.sli.core.sliapi.springboot.core;\r
+\r
+import org.onap.logging.filter.spring.LoggingInterceptor;\r
+import org.springframework.context.annotation.Bean;\r
+import org.springframework.context.annotation.Configuration;\r
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;\r
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;\r
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;\r
+\r
+@EnableWebMvc\r
+@Configuration\r
+public class WebConfig implements WebMvcConfigurer {\r
+\r
+       @Bean\r
+       LoggingInterceptor loggingInterceptor() {\r
+               return new LoggingInterceptor();\r
+       }\r
+\r
+       public void addInterceptors(InterceptorRegistry registry) {     \r
+               registry.addInterceptor(loggingInterceptor()); // handles audit log entries\r
+       }\r
+\r
+}
\ No newline at end of file
diff --git a/sliapi/springboot/src/main/resources/log4j2.properties b/sliapi/springboot/src/main/resources/log4j2.properties
new file mode 100644 (file)
index 0000000..40d18d1
--- /dev/null
@@ -0,0 +1,160 @@
+ #-
+ # ============LICENSE_START=======================================================
+ # ONAP - CCSDK
+ # ================================================================================
+ # Copyright (C) 2020 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=========================================================
+ #
+
+property.logDir = ${sys:LOG_PATH:-./target}
+
+property.pattern = %d{ISO8601} | %-5p | %-16t | %-32c{1} | %X{currentGraph} - %X{nodeId} | %m%n
+
+#default mdc values
+property.ServiceName = INTERNAL
+property.ErrorCode = 900
+property.ErrorDesc = UnknownError
+
+rootLogger.level = INFO
+rootLogger.appenderRef.AppFile.ref = AppFile
+rootLogger.appenderRef.Console.ref = Console
+rootLogger.appenderRef.DebugFile.ref = DebugFile
+rootLogger.appenderRef.ErrorFile.ref = ErrorFile
+rootLogger.appenderRef.Console.filter.threshold.type = ThresholdFilter
+rootLogger.appenderRef.Console.filter.threshold.level = DEBUG
+
+appender.console.type = Console
+appender.console.name = Console
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = ${pattern}
+
+appender.app.type = RollingRandomAccessFile
+appender.app.name = AppFile
+appender.app.fileName = ${logDir}/app.log
+appender.app.filePattern = ${logDir}/app.log.%i
+appender.app.immediateFlush = true
+appender.app.append = true
+appender.app.layout.type = PatternLayout
+appender.app.layout.pattern = ${pattern}
+appender.app.policies.type = Policies
+appender.app.policies.size.type = SizeBasedTriggeringPolicy
+appender.app.policies.size.size = 10MB
+appender.app.strategy.type = DefaultRolloverStrategy
+appender.app.strategy.max = 100
+appender.app.strategy.fileIndex = min
+
+appender.debug.type = RollingRandomAccessFile
+appender.debug.name = DebugFile
+appender.debug.fileName = ${logDir}/debug.log
+appender.debug.filePattern = ${logDir}/debug.log.%i
+appender.debug.immediateFlush = true
+appender.debug.append = true
+appender.debug.layout.type = PatternLayout
+appender.debug.layout.pattern = %d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{RequestID}|%-16.16t|%-5.5p|%-32.32c{1}|%X{currentGraph} - %X{nodeId}|%m%n
+appender.debug.policies.type = Policies
+appender.debug.policies.size.type = SizeBasedTriggeringPolicy
+appender.debug.policies.size.size = 10MB
+appender.debug.strategy.type = DefaultRolloverStrategy
+appender.debug.strategy.max = 200
+appender.debug.strategy.fileIndex = min
+
+appender.error.type = RollingRandomAccessFile
+appender.error.name = ErrorFile
+appender.error.fileName = ${logDir}/error.log
+appender.error.filePattern = ${logDir}/error.log.%i
+appender.error.immediateFlush = true
+appender.error.append = true
+appender.error.layout.type = PatternLayout
+appender.error.layout.pattern = %d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{RequestID}|%-16.16t|$${ctx:ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%p|$${ctx:ErrorCode}|$${ctx:ErrorDesc}|%m%n
+
+appender.error.policies.type = Policies
+appender.error.policies.size.type = SizeBasedTriggeringPolicy
+appender.error.policies.size.size = 10MB
+appender.error.strategy.type = DefaultRolloverStrategy
+appender.error.strategy.max = 100
+appender.error.strategy.fileIndex = min
+appender.error.filter.threshold.type = ThresholdFilter
+appender.error.filter.threshold.level = WARN
+
+appender.metric.type = RollingRandomAccessFile
+appender.metric.name = MetricFile
+appender.metric.fileName = ${logDir}/metric.log
+appender.metric.filePattern = ${logDir}/metric.log.%i
+appender.metric.immediateFlush = true
+appender.metric.append = true
+appender.metric.layout.type = PatternLayout
+appender.metric.layout.pattern=%X{InvokeTimestamp}|%X{LogTimestamp}|%X{RequestID}|%X{ServiceInstanceID}|%-16.16t|%X{ServerFQDN}|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDesc}|%X{InstanceID}|%p|%X{Severity}|192.168.23.111|%X{ElapsedTime}|${hostName}|%X{ClientIPAddress}|%C{1}|||%X{TargetElement}|%markerSimpleName|%X|%X{currentGraph} - %X{nodeId}||%m%n
+appender.metric.policies.type = Policies
+appender.metric.policies.size.type = SizeBasedTriggeringPolicy
+appender.metric.policies.size.size = 10MB
+appender.metric.strategy.type = DefaultRolloverStrategy
+appender.metric.strategy.max = 100
+appender.metric.strategy.fileIndex = min
+
+appender.audit.type = RollingRandomAccessFile
+appender.audit.name = AuditFile
+appender.audit.fileName = ${logDir}/audit.log
+appender.audit.filePattern = ${logDir}/audit.log.%i
+appender.audit.immediateFlush = true
+appender.audit.append = true
+appender.audit.layout.type = PatternLayout
+appender.audit.layout.pattern=%X{EntryTimestamp}|%X{LogTimestamp}|%X{RequestID}|%X{ServiceInstanceID}|%-16.16t|%X{ServerFQDN}|%X{ServiceName}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDesc}|%X{InstanceID}|INFO|%X{Severity}|192.168.23.111|%X{ElapsedTime}|${hostName}|%X{ClientIPAddress}|%C{1}|%X{AUDIT-Unused}|%X{AUDIT-ProcessKey}|%markerSimpleName|%X|||%m%n
+appender.audit.policies.type = Policies
+appender.audit.policies.size.type = SizeBasedTriggeringPolicy
+appender.audit.policies.size.size = 10MB
+appender.audit.strategy.type = DefaultRolloverStrategy
+appender.audit.strategy.max = 200
+appender.audit.strategy.fileIndex = min
+
+appender.rr.name = RequestResponseFile
+appender.rr.type = RollingRandomAccessFile
+appender.rr.fileName = ${logDir}/request-response.log
+appender.rr.filePattern = ${logDir}/request-response.log.%i
+appender.rr.immediateFlush = true
+appender.rr.append = true
+appender.rr.layout.type = PatternLayout
+appender.rr.layout.pattern = %d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{RequestID}|%X{PartnerName}|%m%n
+appender.rr.policies.type = Policies
+appender.rr.policies.size.type = SizeBasedTriggeringPolicy
+appender.rr.policies.size.size = 10MB
+appender.rr.strategy.type = DefaultRolloverStrategy
+appender.rr.strategy.max = 100
+appender.rr.strategy.fileIndex = min
+
+logger.metric.name = org.onap.ccsdk.sli.core.filters.metric
+logger.metric.level = INFO
+logger.metric.additivity = false
+logger.metric.appenderRef.MetricFile.ref = MetricFile
+
+logger.metric2.name = org.onap.logging.filter.base.AbstractMetricLogFilter
+logger.metric2.level = INFO
+logger.metric2.additivity = false
+logger.metric2.appenderRef.MetricFile.ref = MetricFile
+
+logger.audit.name = org.onap.logging.filter.base.AbstractAuditLogFilter
+logger.audit.level = INFO
+logger.audit.additivity = false
+logger.audit.appenderRef.AuditFile.ref = AuditFile
+
+logger.rr.name = org.onap.logging.filter.base.PayloadLoggingServletFilter
+logger.rr.level = INFO
+logger.rr.additivity = false
+logger.rr.appenderRef.RequestResponseFile.ref = RequestResponseFile
+
+logger.ccsdk.name = org.onap.ccsdk
+logger.ccsdk.level = DEBUG
+
+logger.onaplogging.name = org.onap.logging
+logger.onaplogging.level = DEBUG
\ No newline at end of file
index e34d118..a61a470 100644 (file)
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2020 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=========================================================
+ */
+
 package org.onap.ccsdk.sli.core.sliapi.springboot;
 
 import static org.junit.Assert.assertEquals;