aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.so/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-05-29 16:32:57 -0400
committerJim Hahn <jrh3@att.com>2020-05-29 16:51:29 -0400
commit45e3d3ae1cc5a4c29526da4f4cb6096e1b6d7d4f (patch)
tree02b5f1fa7f150ef86846d37143b008e292ce9eaa /models-interactions/model-actors/actor.so/src/main
parent6d5459569af6a9c70abf5a8bbb54917decd37b38 (diff)
Use "coder" to serialize Actor requests
Modified the Actors to use the "coder" to serialize requests instead of defaulting to the HttpClient serialization provider. Decided to just pretty-print the requests since that can be used for both logging and transmission, which avoids serializing the request twice. Issue-ID: POLICY-2601 Change-Id: I190ed19dd852a1aa66156b358cbc97c3b121af1f Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.so/src/main')
-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
2 files changed, 9 insertions, 30 deletions
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