aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors
diff options
context:
space:
mode:
Diffstat (limited to 'models-interactions/model-actors')
-rw-r--r--models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java5
-rw-r--r--models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java13
-rw-r--r--models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java6
-rw-r--r--models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java6
-rw-r--r--models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java7
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java6
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java33
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java37
-rw-r--r--models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java2
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java14
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java2
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java40
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java14
13 files changed, 76 insertions, 109 deletions
diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java
index 2cc2a69f4..718047cfc 100644
--- a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java
+++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java
@@ -117,9 +117,10 @@ public class AaiCustomQueryOperation extends HttpOperation<String> {
String url = str.toString();
- logMessage(EventType.OUT, CommInfrastructure.REST, url, request);
+ String strRequest = prettyPrint(request);
+ logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
- Entity<Map<String, String>> entity = Entity.entity(request, MediaType.APPLICATION_JSON);
+ Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
return handleResponse(outcome, url, callback -> webldr.async().put(entity, callback));
}
diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java
index ca6cfb2f8..386eb219a 100644
--- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java
+++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java
@@ -38,14 +38,11 @@ import java.util.TreeMap;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
-import javax.ws.rs.client.Entity;
import javax.ws.rs.client.InvocationCallback;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
import org.mockito.Mock;
import org.onap.policy.aai.AaiConstants;
import org.onap.policy.aai.AaiCqResponse;
@@ -70,9 +67,6 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S
private static final String MY_VSERVER = "my-vserver-name";
private static final String SIM_VSERVER = "OzVServer";
- @Captor
- private ArgumentCaptor<Entity<Map<String, String>>> entityCaptor;
-
@Mock
private Actor tenantActor;
@@ -215,10 +209,13 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S
oper.start();
executor.runAll(100);
- verify(webAsync).put(entityCaptor.capture(), any(InvocationCallback.class));
+ verify(webAsync).put(requestCaptor.capture(), any(InvocationCallback.class));
+
+ String reqText = requestCaptor.getValue().getEntity();
+ Map<String,String> reqMap = coder.decode(reqText, Map.class);
// sort the request fields so they match the order in cq.json
- Map<String, String> request = new TreeMap<>(entityCaptor.getValue().getEntity());
+ Map<String, String> request = new TreeMap<>(reqMap);
verifyRequest("cq.json", request);
}
diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java
index da1f95603..a21886bf2 100644
--- a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java
+++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java
@@ -106,14 +106,16 @@ public class GuardOperation extends HttpOperation<DecisionResponse> {
@Override
protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
DecisionRequest request = makeRequest();
- Entity<DecisionRequest> entity = Entity.entity(request, MediaType.APPLICATION_JSON);
Map<String, Object> headers = makeHeaders();
headers.put("Accept", MediaType.APPLICATION_JSON);
String url = getUrl();
- logMessage(EventType.OUT, CommInfrastructure.REST, url, request);
+ String strRequest = prettyPrint(request);
+ logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
+
+ Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
// @formatter:off
return handleResponse(outcome, url,
diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java
index ca6d07b16..9b6394315 100644
--- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java
+++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java
@@ -61,7 +61,6 @@ public abstract class SdncOperation extends HttpOperation<SdncResponse> {
protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
SdncRequest request = makeRequest(attempt);
- Entity<SdncRequest> entity = Entity.entity(request, MediaType.APPLICATION_JSON);
Map<String, Object> headers = makeHeaders();
@@ -69,7 +68,10 @@ public abstract class SdncOperation extends HttpOperation<SdncResponse> {
String path = getPath();
String url = getClient().getBaseUrl() + path;
- logMessage(EventType.OUT, CommInfrastructure.REST, url, request);
+ String strRequest = prettyPrint(request);
+ logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
+
+ Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
// @formatter:off
return handleResponse(outcome, url,
diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java
index 921694269..5cc09560f 100644
--- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java
+++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java
@@ -36,6 +36,7 @@ import java.util.concurrent.TimeoutException;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
@@ -114,7 +115,7 @@ public abstract class BasicSdncOperation extends BasicHttpOperation<SdncRequest>
* @return the request that was posted
*/
protected SdncRequest verifyOperation(SdncOperation operation)
- throws InterruptedException, ExecutionException, TimeoutException {
+ throws InterruptedException, ExecutionException, TimeoutException, CoderException {
CompletableFuture<OperationOutcome> future2 = operation.start();
executor.runAll(100);
@@ -132,7 +133,9 @@ public abstract class BasicSdncOperation extends BasicHttpOperation<SdncRequest>
assertNotNull(outcome.getSubRequestId());
- return requestCaptor.getValue().getEntity();
+ String reqText = requestCaptor.getValue().getEntity();
+
+ return coder.decode(reqText, SdncRequest.class);
}
/**
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java
index 077c8578b..6a6c79279 100644
--- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java
@@ -107,10 +107,12 @@ public class VfModuleCreate extends SoOperation {
String path = getPath() + pair.getLeft();
SoRequest request = pair.getRight();
- Entity<SoRequest> entity = Entity.entity(request, MediaType.APPLICATION_JSON);
String url = getClient().getBaseUrl() + path;
- logMessage(EventType.OUT, CommInfrastructure.REST, url, request);
+ String strRequest = prettyPrint(request);
+ logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
+
+ Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
Map<String, Object> headers = createSimpleHeaders();
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java
index 5134d58da..04f0287b7 100644
--- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java
@@ -45,7 +45,6 @@ import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
-import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
@@ -118,13 +117,14 @@ public class VfModuleDelete extends SoOperation {
SoRequest request = pair.getRight();
String url = getPath() + pair.getLeft();
- logMessage(EventType.OUT, CommInfrastructure.REST, url, request);
+ String strRequest = prettyPrint(request);
+ logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
Map<String, Object> headers = createSimpleHeaders();
// @formatter:off
return handleResponse(outcome, url,
- callback -> delete(url, headers, MediaType.APPLICATION_JSON, request, callback));
+ callback -> delete(url, headers, MediaType.APPLICATION_JSON, strRequest, callback));
// @formatter:on
}
@@ -143,12 +143,9 @@ public class VfModuleDelete extends SoOperation {
* future will actually cancel the underlying HTTP request
*/
protected <Q> CompletableFuture<Response> delete(String uri, Map<String, Object> headers, String contentType,
- Q request, InvocationCallback<Response> callback) {
+ String request, InvocationCallback<Response> callback) {
// TODO move to HttpOperation
- // make sure we can encode it before going any further
- final String body = encodeRequest(request);
-
final String url = getClient().getBaseUrl() + uri;
Builder builder = HttpRequest.newBuilder(URI.create(url));
@@ -161,7 +158,7 @@ public class VfModuleDelete extends SoOperation {
PipelineControllerFuture<Response> controller = new PipelineControllerFuture<>();
- HttpRequest req = builder.method("DELETE", BodyPublishers.ofString(body)).build();
+ HttpRequest req = builder.method("DELETE", BodyPublishers.ofString(request)).build();
CompletableFuture<HttpResponse<String>> future = makeHttpClient().sendAsync(req, BodyHandlers.ofString());
@@ -183,26 +180,6 @@ public class VfModuleDelete extends SoOperation {
}
/**
- * Encodes a request.
- *
- * @param <Q> request type
- * @param request request to be encoded
- * @return the encoded request
- */
- protected <Q> String encodeRequest(Q request) {
- // TODO move to HttpOperation
- try {
- if (request instanceof String) {
- return request.toString();
- } else {
- return makeCoder().encode(request);
- }
- } catch (CoderException e) {
- throw new IllegalArgumentException("cannot encode request", e);
- }
- }
-
- /**
* Adds the authorization header to the HTTP request, if configured.
*
* @param builder request builder to which the header should be added
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java
index 86242f042..f5d05a0e8 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java
@@ -61,9 +61,7 @@ import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.aai.domain.yang.Tenant;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
-import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
@@ -271,8 +269,10 @@ public class VfModuleDeleteTest extends BasicSoOperation {
Map<String, Object> headers = Map.of("key-A", "value-A");
+ String reqText = oper.prettyPrint(req);
+
final CompletableFuture<Response> delFuture =
- oper.delete("my-uri", headers, MediaType.APPLICATION_JSON, req, callback);
+ oper.delete("my-uri", headers, MediaType.APPLICATION_JSON, reqText, callback);
ArgumentCaptor<HttpRequest> reqCaptor = ArgumentCaptor.forClass(HttpRequest.class);
verify(javaClient).sendAsync(reqCaptor.capture(), any());
@@ -311,8 +311,10 @@ public class VfModuleDeleteTest extends BasicSoOperation {
SoRequest req = new SoRequest();
req.setRequestId(REQ_ID);
+ String reqText = oper.prettyPrint(req);
+
CompletableFuture<Response> delFuture =
- oper.delete("/my-uri", Map.of(), MediaType.APPLICATION_JSON, req, callback);
+ oper.delete("/my-uri", Map.of(), MediaType.APPLICATION_JSON, reqText, callback);
assertTrue(delFuture.isCompletedExceptionally());
@@ -321,33 +323,6 @@ public class VfModuleDeleteTest extends BasicSoOperation {
assertSame(thrown, thrownCaptor.getValue().getCause());
}
- @Test
- public void testEncodeBody() {
- // try when request is already a string
- assertEquals("hello", oper.encodeRequest("hello"));
-
- // try with a real request
- SoRequest req = new SoRequest();
- req.setRequestId(REQ_ID);
- assertEquals("{\"requestId\":\"" + REQ_ID.toString() + "\"}", oper.encodeRequest(req));
-
- // coder throws an exception
- oper = new MyOperation(params, config) {
- @Override
- protected Coder makeCoder() {
- return new StandardCoder() {
- @Override
- public String encode(Object object) throws CoderException {
- throw new CoderException(EXPECTED_EXCEPTION);
- }
- };
- }
- };
-
- assertThatIllegalArgumentException().isThrownBy(() -> oper.encodeRequest(req))
- .withMessage("cannot encode request");
- }
-
/**
* Tests addAuthHeader() when there is a username, but no password.
*/
diff --git a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java
index 6786b7da9..4331edb04 100644
--- a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java
+++ b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java
@@ -53,7 +53,7 @@ public class BasicHttpOperation<Q> extends BasicOperation {
@Captor
protected ArgumentCaptor<InvocationCallback<Response>> callbackCaptor;
@Captor
- protected ArgumentCaptor<Entity<Q>> requestCaptor;
+ protected ArgumentCaptor<Entity<String>> requestCaptor;
@Captor
protected ArgumentCaptor<Map<String, Object>> headerCaptor;
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java
index 8285a5635..2a460667a 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java
@@ -166,18 +166,8 @@ public abstract class BidirectionalTopicOperation<Q, S> extends OperationPartial
* @param request request to be published
*/
protected void publishRequest(Q request) {
- String json;
- try {
- if (request instanceof String) {
- json = request.toString();
- } else {
- json = makeCoder().encode(request);
- }
- } catch (CoderException e) {
- throw new IllegalArgumentException("cannot encode request", e);
- }
-
- logMessage(EventType.OUT, topicHandler.getSinkTopicCommInfrastructure(), topicHandler.getSinkTopic(), request);
+ String json = prettyPrint(request);
+ logMessage(EventType.OUT, topicHandler.getSinkTopicCommInfrastructure(), topicHandler.getSinkTopic(), json);
if (!topicHandler.send(json)) {
throw new IllegalStateException("nothing published");
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java
index 1acc1ff65..766468c07 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java
@@ -177,7 +177,7 @@ public abstract class HttpOperation<T> extends OperationPartial {
logger.info("{}.{}: response received for {}", params.getActor(), params.getOperation(), params.getRequestId());
- String strResponse = HttpClient.getBody(rawResponse, String.class);
+ String strResponse = rawResponse.readEntity(String.class);
logMessage(EventType.IN, CommInfrastructure.REST, url, strResponse);
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java
index 4aa723614..1df318799 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java
@@ -989,30 +989,24 @@ public abstract class OperationPartial implements Operation {
}
/**
- * Logs a response. If the response is not of type, String, then it attempts to
+ * Logs a message. If the message is not of type, String, then it attempts to
* pretty-print it into JSON before logging.
*
* @param direction IN or OUT
* @param infra communication infrastructure on which it was published
* @param source source name (e.g., the URL or Topic name)
- * @param response response to be logged
+ * @param message message to be logged
* @return the JSON text that was logged
*/
- public <T> String logMessage(EventType direction, CommInfrastructure infra, String source, T response) {
+ public <T> String logMessage(EventType direction, CommInfrastructure infra, String source, T message) {
String json;
try {
- if (response == null) {
- json = null;
- } else if (response instanceof String) {
- json = response.toString();
- } else {
- json = makeCoder().encode(response, true);
- }
+ json = prettyPrint(message);
- } catch (CoderException e) {
+ } catch (IllegalArgumentException e) {
String type = (direction == EventType.IN ? "response" : "request");
logger.warn("cannot pretty-print {}", type, e);
- json = response.toString();
+ json = message.toString();
}
logger.info("[{}|{}|{}|]{}{}", direction, infra, source, NetLoggerUtil.SYSTEM_LS, json);
@@ -1020,6 +1014,28 @@ public abstract class OperationPartial implements Operation {
return json;
}
+ /**
+ * Converts a message to a "pretty-printed" String using the operation's normal
+ * serialization provider (i.e., it's <i>coder</i>).
+ *
+ * @param message response to be logged
+ * @return the JSON text that was logged
+ * @throws IllegalArgumentException if the message cannot be converted
+ */
+ public <T> String prettyPrint(T message) {
+ if (message == null) {
+ return null;
+ } else if (message instanceof String) {
+ return message.toString();
+ } else {
+ try {
+ return makeCoder().encode(message, true);
+ } catch (CoderException e) {
+ throw new IllegalArgumentException("cannot encode message", e);
+ }
+ }
+ }
+
// these may be overridden by subclasses or junit tests
/**
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java
index eb1aa880f..9ac88f488 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java
@@ -532,14 +532,15 @@ public class HttpOperationTest {
MyRequest request = new MyRequest();
- Entity<MyRequest> entity = Entity.entity(request, MediaType.APPLICATION_JSON);
-
Map<String, Object> headers = makeHeaders();
headers.put("Accept", MediaType.APPLICATION_JSON);
String url = getUrl();
- logMessage(EventType.OUT, CommInfrastructure.REST, url, request);
+ String strRequest = prettyPrint(request);
+ logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
+
+ Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
// @formatter:off
return handleResponse(outcome, url,
@@ -558,14 +559,15 @@ public class HttpOperationTest {
MyRequest request = new MyRequest();
- Entity<MyRequest> entity = Entity.entity(request, MediaType.APPLICATION_JSON);
-
Map<String, Object> headers = makeHeaders();
headers.put("Accept", MediaType.APPLICATION_JSON);
String url = getUrl();
- logMessage(EventType.OUT, CommInfrastructure.REST, url, request);
+ String strRequest = prettyPrint(request);
+ logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
+
+ Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
// @formatter:off
return handleResponse(outcome, url,