summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actorServiceProvider
diff options
context:
space:
mode:
Diffstat (limited to 'models-interactions/model-actors/actorServiceProvider')
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java3
-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/OperationOutcomeTest.java6
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java17
6 files changed, 40 insertions, 42 deletions
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java
index 0fd2c0bfd..0c4350c63 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java
@@ -25,7 +25,6 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.onap.policy.controlloop.ControlLoopOperation;
-import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.policy.PolicyResult;
/**
@@ -44,7 +43,6 @@ public class OperationOutcome {
private String message;
private boolean finalOutcome;
private Object response;
- private ControlLoopResponse controlLoopResponse;
/**
* Copy constructor.
@@ -62,7 +60,6 @@ public class OperationOutcome {
this.message = source.message;
this.finalOutcome = source.finalOutcome;
this.response = source.response;
- this.controlLoopResponse = source.controlLoopResponse;
}
/**
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/OperationOutcomeTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java
index c60a0f00c..5820becc5 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java
@@ -30,7 +30,6 @@ import java.time.Instant;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.controlloop.ControlLoopOperation;
-import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.policy.PolicyResult;
public class OperationOutcomeTest {
@@ -44,7 +43,6 @@ public class OperationOutcomeTest {
private static final String MESSAGE = "my-message";
private static final String RESPONSE = "my-response";
- private ControlLoopResponse response;
private OperationOutcome outcome;
/**
@@ -52,8 +50,6 @@ public class OperationOutcomeTest {
*/
@Before
public void setUp() {
- response = new ControlLoopResponse();
-
outcome = new OperationOutcome();
}
@@ -72,7 +68,6 @@ public class OperationOutcomeTest {
assertEquals(RESULT, outcome2.getResult());
assertEquals(MESSAGE, outcome2.getMessage());
assertSame(RESPONSE, outcome2.getResponse());
- assertSame(response, outcome2.getControlLoopResponse());
}
@Test
@@ -145,6 +140,5 @@ public class OperationOutcomeTest {
outcome.setSubRequestId(SUB_REQ_ID);
outcome.setTarget(TARGET);
outcome.setResponse(RESPONSE);
- outcome.setControlLoopResponse(response);
}
}
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..291811a6e 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
@@ -150,8 +150,7 @@ public class HttpOperationTest {
/*
* Start the clients, one to the server, and one to a non-existent server.
*/
- TopicParamsBuilder builder = BusTopicParams.builder().managed(true).hostname("localhost").basePath(BASE_URI)
- .serializationProvider(GsonMessageBodyHandler.class.getName());
+ TopicParamsBuilder builder = BusTopicParams.builder().managed(true).hostname("localhost").basePath(BASE_URI);
HttpClientFactoryInstance.getClientFactory().build(builder.clientName(HTTP_CLIENT).port(port).build());
@@ -532,14 +531,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 +558,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,