From d9742adbfee81f25fb83a517353fd2810ce41c91 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Thu, 7 Mar 2019 21:49:34 +0530 Subject: Add context to multipart http profile Issue-ID: CLI-129 Change-Id: I0ae68064e776607cacc1985bd02df04c918e0d08 Signed-off-by: Kanagaraj Manickam k00365106 --- .../cli/fw/http/utils/OnapCommandHttpUtils.java | 31 +++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'profiles/http/src/main') diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java index 3afb1961..f4a6cee5 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java @@ -66,25 +66,20 @@ public class OnapCommandHttpUtils { */ public static HttpInput populateParameters(Map params, HttpInput input) throws OnapCommandException { + HttpInput inp = new HttpInput(); + for (OnapCommandParameter param : params.values()) { if (OnapCommandParameterType.BINARY.equals(param.getParameterType())) { inp.setBinaryData(true); break; } } - inp.setMultipartEntityName(input.getMultipartEntityName()); - inp.setBody(OnapCommandUtils.replaceLineFromInputParameters(input.getBody(), params)); - - if (input.getMultiparts().size() > 0) { - for (HttpInput.Part part: input.getMultiparts()) { - part.setContent(OnapCommandUtils.replaceLineFromInputParameters(part.getContent(), params)); - } - } - inp.setMultiparts(input.getMultiparts()); inp.setUri(OnapCommandUtils.replaceLineFromInputParameters(input.getUri(), params)); + inp.setMethod(input.getMethod().toLowerCase()); + for (String h : input.getReqHeaders().keySet()) { String value = input.getReqHeaders().get(h); inp.getReqHeaders().put(h, OnapCommandUtils.replaceLineFromInputParameters(value, params)); @@ -97,10 +92,22 @@ public class OnapCommandHttpUtils { boolean isRemoveEmptyNodes = Boolean.parseBoolean(input.getContext().getOrDefault(OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES, "false")); - if (isRemoveEmptyNodes) { - inp.setBody(OnapCommandHttpUtils.normalizeJson(inp.getBody())); - } + if (input.getMultiparts().size() > 0) { + for (HttpInput.Part part: input.getMultiparts()) { + part.setContent(OnapCommandUtils.replaceLineFromInputParameters(part.getContent(), params)); + if (isRemoveEmptyNodes) { + part.setContent(OnapCommandHttpUtils.normalizeJson(part.getContent())); + } + } + inp.setMultiparts(input.getMultiparts()); + } else { + inp.setMultipartEntityName(input.getMultipartEntityName()); + inp.setBody(OnapCommandUtils.replaceLineFromInputParameters(input.getBody(), params)); + if (isRemoveEmptyNodes) { + inp.setBody(OnapCommandHttpUtils.normalizeJson(inp.getBody())); + } + } return inp; } -- cgit 1.2.3-korg