aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-requests-db-adapter/src
diff options
context:
space:
mode:
authorSmokowski, Steve (ss835w) <ss835w@us.att.com>2018-09-01 06:58:20 -0400
committerSmokowski, Steve (ss835w) <ss835w@us.att.com>2018-09-01 06:58:20 -0400
commitb1c2cbe73420cbb62f643488422f174fe3311b1c (patch)
treea373b61c81b6550f44a0580df7d0471479224e0c /adapters/mso-requests-db-adapter/src
parent00da3f4b4087e78d56f09dfe8ab01616d6ad68b0 (diff)
Logging Improvement
Add Spring interceptor to log all the SpringDataRest calls Issue-ID: SO-947 Change-Id: Ia1a574cedd90e79bb2fd30a094831dc5cd269ff0 Signed-off-by: Smokowski, Steve (ss835w) <ss835w@us.att.com>
Diffstat (limited to 'adapters/mso-requests-db-adapter/src')
-rw-r--r--adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/WebMvcConfig.java22
-rw-r--r--adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml4
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java30
3 files changed, 50 insertions, 6 deletions
diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/WebMvcConfig.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/WebMvcConfig.java
new file mode 100644
index 0000000000..69cf6ccb3d
--- /dev/null
+++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/WebMvcConfig.java
@@ -0,0 +1,22 @@
+package org.onap.so.adapters.requestsdb.application;
+
+
+import org.onap.so.logging.spring.interceptor.LoggingInterceptor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.handler.MappedInterceptor;
+
+@Configuration
+public class WebMvcConfig extends WebMvcConfigurerAdapter {
+
+ @Autowired
+ LoggingInterceptor loggingInterceptor;
+
+ @Bean
+ public MappedInterceptor mappedLoggingInterceptor() {
+ return new MappedInterceptor(new String[]{"/**"}, loggingInterceptor);
+ }
+
+} \ No newline at end of file
diff --git a/adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml b/adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml
index 102b52985c..ade3daada3 100644
--- a/adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml
+++ b/adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml
@@ -15,8 +15,8 @@ mso:
spring:
datasource:
url: jdbc:mariadb://localhost:3306/requestdb
- username: mso
- password: mso123
+ username: catalog
+ password: catalog123
driver-class-name: org.mariadb.jdbc.Driver
initialize: true
initialization-mode: never
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java
index 005eba0ec2..159eb015de 100644
--- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java
+++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java
@@ -21,16 +21,16 @@
package org.onap.so.adapters.requestsdb.adapters;
import static org.junit.Assert.*;
-
-
-
+import java.util.Map;
import javax.ws.rs.core.Response;
import org.json.JSONException;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication;
-
+import org.onap.so.adapters.requestsdb.application.TestAppender;
+import org.onap.so.logger.MsoLogger;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
@@ -40,6 +40,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
+import ch.qos.logback.classic.spi.ILoggingEvent;
@RunWith(SpringRunner.class)
@@ -65,6 +66,27 @@ public class HealthCheckHandlerTest {
HttpMethod.GET, entity, String.class);
assertEquals(Response.Status.OK.getStatusCode(),response.getStatusCode().value());
+ for(ILoggingEvent logEvent : TestAppender.events)
+ if(logEvent.getLoggerName().equals("org.onap.so.logging.spring.interceptor.LoggingInterceptor") &&
+ logEvent.getMarker().getName().equals("ENTRY")
+ ){
+ Map<String,String> mdc = logEvent.getMDCPropertyMap();
+ assertNotNull(mdc.get(ONAPLogConstants.MDCs.INSTANCE_UUID));
+ assertNotNull(mdc.get(MsoLogger.REQUEST_ID));
+ assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
+ assertEquals("",mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
+ assertEquals("/manage/health",mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME));
+ assertEquals("INPROGRESS",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
+ }else if(logEvent.getLoggerName().equals("org.onap.so.logging.spring.interceptor.LoggingInterceptor") &&
+ logEvent.getMarker()!= null && logEvent.getMarker().getName().equals("EXIT")){
+ Map<String,String> mdc = logEvent.getMDCPropertyMap();
+ assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
+ assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
+ assertEquals("200",mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE));
+ assertEquals("",mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
+ assertEquals("/manage/health",mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME));
+ assertEquals("COMPLETED",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
+ }
}
private String createURLWithPort(String uri) {