Add logs for REST request/response in APEX 14/117014/1
authora.sreekumar <ajith.sreekumar@bell.ca>
Wed, 20 Jan 2021 14:35:18 +0000 (14:35 +0000)
committerRam Krishna Verma <ram_krishna.verma@bell.ca>
Tue, 26 Jan 2021 15:54:28 +0000 (15:54 +0000)
Change-Id: Ibf2cf19a1ec91473d8c655b87a712aa8738848c8
Issue-ID: POLICY-3003
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
(cherry picked from commit de9bb70b25d498e844c2c6205061aa9e5e9d8d7a)

plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/pom.xml
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/pom.xml
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java

index 5a2fef9..479d943 100644 (file)
@@ -2,6 +2,7 @@
   ============LICENSE_START=======================================================
    Copyright (C) 2018 Ericsson. All rights reserved.
    Modifications Copyright (C) 2019-2020 Nordix Foundation.
+   Modifications Copyright (C) 2021 Bell Canada. 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.
     <description>[${project.parent.artifactId}] Plugin for handling events being transported over REST where Apex acts as a REST client</description>
 
     <dependencies>
+        <dependency>
+            <groupId>org.onap.policy.common</groupId>
+            <artifactId>policy-endpoints</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.onap.policy.apex-pdp.services</groupId>
             <artifactId>services-engine</artifactId>
index d777d2c..565587f 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
  *  Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -33,6 +34,9 @@ import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
 import org.onap.policy.apex.service.engine.event.ApexPluginsEventProducer;
 import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
+import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -114,22 +118,18 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer {
             // @formatter:on
         }
 
+        NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, untaggedUrl, event.toString());
         // Send the event as a REST request
         final Response response = sendEventAsRestRequest(untaggedUrl, (String) event);
 
+        NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, untaggedUrl, response.readEntity(String.class));
+
         // Check that the request worked
         if (response.getStatus() != Response.Status.OK.getStatusCode()) {
             final String errorMessage = "send of event to URL \"" + untaggedUrl + "\" using HTTP \""
-                    + restProducerProperties.getHttpMethod() + "\" failed with status code " + response.getStatus()
-                    + " and message \"" + response.readEntity(String.class) + "\", event:\n" + event;
-            LOGGER.warn(errorMessage);
+                    + restProducerProperties.getHttpMethod() + "\" failed with status code " + response.getStatus();
             throw new ApexEventRuntimeException(errorMessage);
         }
-
-        if (LOGGER.isTraceEnabled()) {
-            LOGGER.trace("event sent from engine using {} to URL {} with HTTP {} : {} and response {} ", this.name,
-                    untaggedUrl, restProducerProperties.getHttpMethod(), event, response);
-        }
     }
 
     /**
index a4ef6e3..ac82713 100644 (file)
@@ -291,6 +291,6 @@ public class ApexRestClientProducerTest {
 
         assertThatThrownBy(() -> arcp.sendEvent(123, null, "EventName", "This is an Event"))
             .hasMessageContaining("send of event to URL \"http://some.place.that.does.not/exist\" using HTTP \"POST\" "
-                + "failed with status code 400 and message \"null\", event:\n" + "This is an Event");
+                + "failed with status code 400");
     }
 }
\ No newline at end of file
index 823759e..4043edd 100644 (file)
@@ -2,6 +2,7 @@
   ============LICENSE_START=======================================================
    Copyright (C) 2018 Ericsson. All rights reserved.
    Modifications Copyright (C) 2019-2020 Nordix Foundation.
+   Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -37,7 +38,6 @@
         <dependency>
             <groupId>org.onap.policy.common</groupId>
             <artifactId>policy-endpoints</artifactId>
-            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.onap.policy.apex-pdp.services</groupId>
index aa951b8..54dba7a 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
  *  Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -47,8 +48,12 @@ import org.onap.policy.apex.service.engine.event.ApexEventException;
 import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
 import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
 import org.onap.policy.apex.service.engine.event.ApexPluginsEventConsumer;
+import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters.HttpMethod;
 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
+import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -308,23 +313,26 @@ public class ApexRestRequestorConsumer extends ApexPluginsEventConsumer {
             restRequestThread = Thread.currentThread();
 
             try {
+                if (restConsumerProperties.getHttpMethod().equals(HttpMethod.PUT)
+                    || restConsumerProperties.getHttpMethod().equals(HttpMethod.POST)) {
+                    NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, untaggedUrl,
+                        request.getEvent().toString());
+                }
                 // Execute the REST request
                 final Response response = sendEventAsRestRequest(untaggedUrl);
-
+                // Get the event we received
+                final String eventJsonString = response.readEntity(String.class);
+                NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, untaggedUrl, eventJsonString);
                 // Match the return code
                 Matcher isPass = httpCodeFilterPattern.matcher(String.valueOf(response.getStatus()));
 
                 // Check that the request worked
                 if (!isPass.matches()) {
                     final String errorMessage = "reception of event from URL \"" + restConsumerProperties.getUrl()
-                        + "\" failed with status code " + response.getStatus() + " and message \""
-                        + response.readEntity(String.class) + "\"";
+                        + "\" failed with status code " + response.getStatus();
                     throw new ApexEventRuntimeException(errorMessage);
                 }
 
-                // Get the event we received
-                final String eventJsonString = response.readEntity(String.class);
-
                 // Check there is content
                 if (StringUtils.isBlank(eventJsonString)) {
                     final String errorMessage =