aboutsummaryrefslogtreecommitdiffstats
path: root/profiles
diff options
context:
space:
mode:
Diffstat (limited to 'profiles')
-rw-r--r--profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java175
-rw-r--r--profiles/command/src/main/java/org/onap/cli/fw/cmd/conf/OnapCommandCmdConstants.java1
-rw-r--r--profiles/command/src/main/resources/open-cli-schema/cmd/default_input_parameters_cmd.yaml10
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java9
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java57
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java1
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java41
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java35
-rw-r--r--profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java17
9 files changed, 251 insertions, 95 deletions
diff --git a/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java b/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
index 8e94db85..884cde12 100644
--- a/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
+++ b/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
@@ -16,9 +16,13 @@
package org.onap.cli.fw.cmd.cmd;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -27,19 +31,26 @@ import org.onap.cli.fw.cmd.OnapCommand;
import org.onap.cli.fw.cmd.conf.OnapCommandCmdConstants;
import org.onap.cli.fw.cmd.error.OnapCommandCmdFailure;
import org.onap.cli.fw.cmd.schema.OnapCommandSchemaCmdLoader;
+import org.onap.cli.fw.conf.OnapCommandConfig;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandExecutionFailed;
import org.onap.cli.fw.error.OnapCommandResultEmpty;
import org.onap.cli.fw.error.OnapCommandResultMapProcessingFailed;
import org.onap.cli.fw.input.OnapCommandParameter;
+import org.onap.cli.fw.output.OnapCommandResultAttribute;
+import org.onap.cli.fw.output.OnapCommandResultType;
+import org.onap.cli.fw.registrar.OnapCommandRegistrar;
import org.onap.cli.fw.schema.OnapCommandSchema;
+import org.onap.cli.fw.store.OnapCommandExecutionStore;
import org.onap.cli.fw.utils.OnapCommandUtils;
import org.onap.cli.fw.utils.ProcessRunner;
+import com.google.gson.Gson;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import net.minidev.json.JSONArray;
+import net.minidev.json.JSONObject;
/**
* Hello world.
@@ -108,6 +119,25 @@ public class OpenCommandShellCmd extends OnapCommand {
this.resultMap = resultMap;
}
+ private String getStdoutPath() {
+ String storePath = this.getExecutionContext().getStorePath();
+ storePath = storePath + File.separator + "stdout";
+ return storePath;
+ }
+
+ private String getStderrPath() {
+ String storePath = this.getExecutionContext().getStorePath();
+ storePath = storePath + File.separator + "stderr";
+ return storePath;
+ }
+
+ private String getOutputAttributeFilePath(String attrName, boolean temp) {
+ String storePath = (!temp) ? this.getExecutionContext().getStorePath() : OnapCommandConfig.getPropertyValue("cli.tmp.dir");
+ String randomId = (this.getExecutionContext() != null) ? this.getExecutionContext().getExecutionId() : ("" + System.currentTimeMillis());
+ storePath = storePath + File.separator + randomId + "_" + attrName;
+ return storePath;
+ }
+
@Override
protected List<String> initializeProfileSchema(Map<String, ?> schemaMap, boolean validate) throws OnapCommandException {
return OnapCommandSchemaCmdLoader.parseCmdSchema(this, schemaMap, validate);
@@ -118,16 +148,40 @@ public class OpenCommandShellCmd extends OnapCommand {
//Read the input arguments
Map<String, OnapCommandParameter> paramMap = this.getParametersMap();
+ //process command section
+ Map<String, String> tmpFiles = new HashMap<>();
List<String> commandLine = new ArrayList<>();
for (String cmdTkn: this.getCommand()) {
- commandLine.add(OnapCommandUtils.replaceLineFromInputParameters(cmdTkn, paramMap));
+ tmpFiles.putAll(this.formTmpFiles(cmdTkn));
+ String commandLine1 = OnapCommandUtils.replaceLineForSpecialValues(
+ cmdTkn, tmpFiles);
+ commandLine1 = OnapCommandUtils.replaceLineFromInputParameters(commandLine1, paramMap);
+
+ commandLine.add(commandLine1);
}
+ long timeout = Long.parseLong(this.getParametersMap().get(OnapCommandCmdConstants.TIMEOUT).getValue().toString());
+
//Process command
String []cmd = commandLine.toArray(new String []{});
String cwd = this.getWd();
List <String> envs = new ArrayList<>();
+ //add current process environments to sub process
+ for (Map.Entry<String, String> env: System.getenv().entrySet()) {
+ envs.add(env.getKey() + "=" + env.getValue());
+ }
+
+ //add oclip specific environment variables
+ if (this.getExecutionContext() != null) {
+ envs.add("OPEN_CLI_REQUEST_ID=" + this.getExecutionContext().getRequestId());
+ if (OnapCommandRegistrar.getRegistrar().getHost() != null) {
+ envs.add("OPEN_CLI_RPC_HOST=" + OnapCommandRegistrar.getRegistrar().getHost());
+ envs.add("OPEN_CLI_RPC_PORT=" + OnapCommandRegistrar.getRegistrar().getPort());
+ }
+ //mrkanag set the profile OPEN_CLI_PROFILE
+ }
+
for (String env: this.getEnvs().keySet()) {
envs.add(env + "=" + this.getEnvs().get(env));
}
@@ -136,38 +190,102 @@ public class OpenCommandShellCmd extends OnapCommand {
cmd,
(envs.size() > 0) ? envs.toArray(new String []{}) : null,
cwd);
+ FileOutputStream stdoutStream = null;
+ FileOutputStream stderrStream = null;
+ String outputValue = "";
+
try {
+ pr.setTimeout(timeout);
+
+ if (this.getExecutionContext() != null) {
+
+ stdoutStream = new FileOutputStream(this.getStdoutPath());
+ stderrStream = new FileOutputStream(this.getStderrPath());
+
+ pr.setStdout(stdoutStream);
+ pr.setStderr(stderrStream);
+
+ OnapCommandExecutionStore.getStore().storeExectutionDebug(this.getExecutionContext(), pr.toString());
+ } else {
+ this.getResult().setDebugInfo(pr.toString());
+ }
+
pr.run();
} catch (Exception e) {
throw new OnapCommandExecutionFailed(this.getName(), e);
+ } finally {
+ if (stdoutStream != null) {
+ try {
+ stdoutStream.close();
+ } catch (IOException e) {
+ //never occurs // NOSONAR
+ }
+ }
+ if (stderrStream != null) {
+ try {
+ stderrStream.close();
+ } catch (IOException e) {
+ //never occurs // NOSONAR
+ }
+ }
}
if (!this.successStatusCodes.contains(pr.getExitCode())) {
throw new OnapCommandExecutionFailed(this.getName(), pr.getError(), pr.getExitCode());
}
- String outputValue = "";
-
if (this.output.equals("$stdout")) {
- outputValue = pr.getOutput();
+ if (pr.getStdout() != null) {
+ try (FileInputStream is = new FileInputStream(this.getStdoutPath())){
+ outputValue = pr.streamToString(is);
+ } catch (IOException e) {
+ //never occurs // NOSONAR
+ }
+ } else
+ outputValue = pr.getOutput();
+
+ } else if (this.output.equals("$stderr")) {
+ if (pr.getStderr() != null) {
+ try (FileInputStream is = new FileInputStream(this.getStderrPath())) {
+ outputValue = pr.streamToString(is);
+ } catch (IOException e) {
+ //never occurs // NOSONAR
+ }
+ } else
+ outputValue = pr.getError();
+
} else {
- outputValue = OnapCommandUtils.replaceLineFromInputParameters(this.output, paramMap);
- outputValue = OnapCommandUtils.replaceLineForSpecialValues(outputValue);
+ //remove ${tmp: and closing }
+ String tmpName = this.output.substring(7, this.output.length()-1);
+ String tmpFile = tmpFiles.get("tmp:" + tmpName);
+ if (tmpFile != null) {
+ try (FileInputStream is = new FileInputStream(tmpFile)) {
+ outputValue = pr.streamToString(is);
+ } catch (IOException e) {
+ //never occurs // NOSONAR
+ }
+ }
}
+ this.getResult().setDebugInfo(pr.toString() + "\n" + outputValue);
this.getResult().setOutput(outputValue);
//populate results
- for (Entry<String, String> resultMapEntry : this.getResultMap().entrySet()) {
- String value = OnapCommandUtils.replaceLineFromInputParameters(resultMapEntry.getValue(), paramMap);
- value = OnapCommandUtils.replaceLineForSpecialValues(value);
- this.getResult().getRecordsMap().get(resultMapEntry.getKey()).setValues(
- this.replaceLineFromOutputResults(value, outputValue));
- }
+ if (!this.getResult().getType().name().equalsIgnoreCase(OnapCommandResultType.TEXT.name()))
+ for (Entry<String, String> resultMapEntry : this.getResultMap().entrySet()) {
+ String attrName = resultMapEntry.getKey();
+ OnapCommandResultAttribute attr = this.getResult().getRecordsMap().get(attrName);
+
+ String value = OnapCommandUtils.replaceLineFromInputParameters(resultMapEntry.getValue(), paramMap);
+ value = OnapCommandUtils.replaceLineForSpecialValues(value);
+ attr.setValues(this.replaceLineFromOutputResults(value, outputValue));
+ }
//check for pass/failure
- if (!this.passCodes.contains(pr.getExitCode())) {
+ if (!this.passCodes.isEmpty() && !this.passCodes.contains(pr.getExitCode())) {
this.getResult().setPassed(false);
+ } else {
+ this.getResult().setPassed(true);
}
}
@@ -179,6 +297,30 @@ public class OpenCommandShellCmd extends OnapCommand {
this.output = output;
}
+ private Map<String, String> formTmpFiles(String line){
+
+ Map<String, String> result = new HashMap<>();
+
+ if (!line.contains("$s{tmp")) {
+ return result;
+ }
+
+ int currentIdx = 0;
+ while (currentIdx < line.length()) {
+ int idxS = line.indexOf("$s{tmp:", currentIdx); //check for output stream
+ if (idxS == -1) {
+ break;
+ }
+
+ int idxE = line.indexOf("}", idxS);
+ String tmpName = line.substring(idxS + 7, idxE);
+ tmpName = tmpName.trim();
+ result.put("tmp:" + tmpName, this.getOutputAttributeFilePath(tmpName, true));
+ currentIdx = idxE + 1;
+ }
+ return result;
+ }
+
private ArrayList<String> replaceLineFromOutputResults(String line, String output)
throws OnapCommandException {
@@ -217,8 +359,11 @@ public class OpenCommandShellCmd extends OnapCommand {
jsonPath = jsonPath.trim();
Object value = new Object();
try {
- // JSONArray or String
- value = JsonPath.read(output, jsonPath);
+ // Instead of parsing, just assign the json as it is
+ if (!jsonPath.equals("$"))
+ value = JsonPath.read(output, jsonPath);
+ else
+ value = output;
} catch (PathNotFoundException e1) { // NOSONAR
//set to blank for those entries which are missing from the output json
value = "";
diff --git a/profiles/command/src/main/java/org/onap/cli/fw/cmd/conf/OnapCommandCmdConstants.java b/profiles/command/src/main/java/org/onap/cli/fw/cmd/conf/OnapCommandCmdConstants.java
index 6594ef71..4f2d36b4 100644
--- a/profiles/command/src/main/java/org/onap/cli/fw/cmd/conf/OnapCommandCmdConstants.java
+++ b/profiles/command/src/main/java/org/onap/cli/fw/cmd/conf/OnapCommandCmdConstants.java
@@ -38,6 +38,7 @@ public class OnapCommandCmdConstants {
public static final String CMD_SECTIONS = "cli.schema.cmd.sections";
public static final String DEFAULT_PARAMETER_CMD_FILE_NAME = "default_input_parameters_cmd.yaml";
+ public static final String TIMEOUT = "timeout";
private OnapCommandCmdConstants() {
//as per coding standard !
}
diff --git a/profiles/command/src/main/resources/open-cli-schema/cmd/default_input_parameters_cmd.yaml b/profiles/command/src/main/resources/open-cli-schema/cmd/default_input_parameters_cmd.yaml
index b358a0c7..b6a97b0d 100644
--- a/profiles/command/src/main/resources/open-cli-schema/cmd/default_input_parameters_cmd.yaml
+++ b/profiles/command/src/main/resources/open-cli-schema/cmd/default_input_parameters_cmd.yaml
@@ -13,3 +13,13 @@
# limitations under the License.
open_cli_schema_version: 1.0
+
+parameters:
+ - name: timeout
+ type: string
+ description: timeout for command to complete the given task in milliseconds
+ short_option: u
+ long_option: timeout
+ default_value: 60000
+ is_optional: true
+ is_default_param: false \ No newline at end of file
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java b/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java
index 9b7b4039..e5f17bec 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java
@@ -45,9 +45,9 @@ public class OnapCommandHttpAuthClient {
private Map<String, String> loginCache = new HashMap<>();
- public OnapCommandHttpAuthClient(OnapHttpCommand cmd, boolean debug) throws OnapCommandHttpFailure {
+ public OnapCommandHttpAuthClient(OnapHttpCommand cmd) {
this.cmd = cmd;
- this.http = new OnapHttpConnection(debug);
+ this.http = new OnapHttpConnection();
}
/**
@@ -142,11 +142,6 @@ public class OnapCommandHttpAuthClient {
}
}
-
- public String getDebugInfo() {
- return this.http.getDebugInfo();
- }
-
/**
* Http call to external service.
*
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java
index 14728ad0..53a2d042 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java
@@ -16,6 +16,14 @@
package org.onap.cli.fw.http.cmd;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+
import org.onap.cli.fw.cmd.OnapCommand;
import org.onap.cli.fw.cmd.OnapCommandType;
import org.onap.cli.fw.conf.OnapCommandConfig;
@@ -34,19 +42,12 @@ import org.onap.cli.fw.http.utils.OnapCommandHttpUtils;
import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.schema.OnapCommandSchema;
+import org.onap.cli.fw.store.OnapCommandExecutionStore;
import org.onap.cli.fw.utils.OnapCommandUtils;
import org.onap.cli.http.mock.MockJsonGenerator;
import org.onap.cli.http.mock.MockRequest;
import org.onap.cli.http.mock.MockResponse;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-
/**
* Oclip http Command.
*
@@ -56,6 +57,8 @@ public class OnapHttpCommand extends OnapCommand {
private HttpInput input = new HttpInput();
+ private HttpResult output = new HttpResult();
+
private List<Integer> successStatusCodes = new ArrayList<>();
private Map<String, String> resultMap = new HashMap<>();
@@ -201,14 +204,11 @@ public class OnapHttpCommand extends OnapCommand {
@Override
protected void run() throws OnapCommandException {
+ this.authClient = new OnapCommandHttpAuthClient(this);
+
try {
// For auth/catalog type commands, login and logout logic is not required
boolean isAuthRequired = this.isAuthRequired();
-
- this.authClient = new OnapCommandHttpAuthClient(
- this,
- this.getResult().isDebug());
-
if (isAuthRequired) {
this.authClient.login();
}
@@ -218,24 +218,28 @@ public class OnapHttpCommand extends OnapCommand {
if (isAuthRequired) {
this.authClient.logout();
}
-
- if (this.getResult().isDebug() && authClient != null) {
- this.getResult().setDebugInfo(this.authClient.getDebugInfo());
- }
} catch (OnapCommandException e) {
- if (this.getResult().isDebug() && authClient != null) {
- this.getResult().setDebugInfo(this.authClient.getDebugInfo());
- }
throw e;
+ } finally {
+ this.getResult().setDebugInfo(this.input.toString() + "\n" + this.output.toString());
}
}
protected void processRequest() throws OnapCommandException {
HttpInput httpInput = OnapCommandHttpUtils.populateParameters(this.getParametersMap(), this.getInput());
- httpInput.setUri(this.authClient.getServiceUrl() + httpInput.getUri());
+ if (!httpInput.getUri().startsWith("http")) {
+ httpInput.setUri(this.authClient.getServiceUrl() + httpInput.getUri());
+ }
- HttpResult output = this.authClient.run(httpInput);
+ this.setInput(httpInput);
+
+ if (this.getExecutionContext() != null) {
+ OnapCommandExecutionStore.getStore().storeExectutionDebug(this.getExecutionContext(), this.getInput().toString());
+ } else {
+ this.getResult().setDebugInfo(this.getInput().toString());
+ }
+ this.output = this.authClient.run(this.getInput());
this.getResult().setOutput(output);
if (!this.getSuccessStatusCodes().contains(output.getStatus())) {
@@ -250,12 +254,17 @@ public class OnapHttpCommand extends OnapCommand {
}
Map<String, ArrayList<String>> results = OnapCommandHttpUtils.populateOutputs(this.getResultMap(), output);
- results = OnapCommandUtils.populateOutputsFromInputParameters(results, this.getParametersMap());
+ //results = OnapCommandUtils.populateOutputsFromInputParameters(results, this.getParametersMap());
for (OnapCommandResultAttribute attr : this.getResult().getRecords()) {
attr.setValues(results.get(attr.getName()));
}
- generateJsonMock(httpInput, output, this.getSchemaName());
+
+ try{
+ generateJsonMock(this.getInput(), output, this.getSchemaName());
+ } catch (OnapCommandFailedMocoGenerate e) {
+ //NO SONAR ignore it
+ }
}
private void generateJsonMock(HttpInput httpInput, HttpResult httpResult, String schemaName)
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java b/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java
index 2d14bb88..6a87ed13 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java
@@ -94,6 +94,7 @@ public class OnapCommandHttpConstants {
//context param
public static final String CONTEXT = "context";
public static final String CONTEXT_REMOVE_EMPTY_JSON_NODES = "remove_empty_node";
+ public static final String __BODY__ = "__body__";
// moco server const
public static final String VERIFY_MOCO_HOST = "cli.verify.host";
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java b/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java
index a2da0706..3f426bf3 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java
@@ -27,15 +27,18 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
+
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
@@ -79,10 +82,6 @@ public class OnapHttpConnection {
Map<String, String> mapCommonHeaders = new HashMap<> ();
- protected boolean debug = false;
-
- private String debugDetails = "";
-
public static class TrustAllX509TrustManager implements X509TrustManager {
@Override
@@ -101,18 +100,6 @@ public class OnapHttpConnection {
}
}
- /**
- * OnapHttpConnection Constructor.
- *
- * @param debug
- * boolean
- * @throws OnapCommandHttpFailure
- * exception
- */
- public OnapHttpConnection(boolean debug) {
- this.debug = debug;
- }
-
private void initHttpClient(boolean isSecured) throws OnapCommandHttpFailure {
if (this.httpClient == null) {
try {
@@ -137,10 +124,6 @@ public class OnapHttpConnection {
}
}
- public String getDebugInfo() {
- return this.debugDetails;
- }
-
private Map<String, String> getHttpHeaders(HttpResponse resp) {
Map<String, String> result = new HashMap<>();
@@ -244,9 +227,12 @@ public class OnapHttpConnection {
}
}
- private void addCommonCookies(CookieStore cookieStore) {
+ private void addCommonCookies(HttpInput input, CookieStore cookieStore) {
for (Entry<String, String> header : this.mapCommonHeaders.entrySet()) {
- Cookie cookie = new BasicClientCookie(header.getKey(), header.getValue());
+ //take care of overriden headers in OCS YAML
+ String value = input.getReqHeaders().getOrDefault(header.getKey(),
+ header.getValue());
+ Cookie cookie = new BasicClientCookie(header.getKey(), value);
cookieStore.addCookie(cookie);
}
}
@@ -267,7 +253,7 @@ public class OnapHttpConnection {
}
private void updateInputFromCookies(HttpInput input, CookieStore cookieStore) {
- addCommonCookies(cookieStore);
+ addCommonCookies(input, cookieStore);
for (String cookieName : input.getReqCookies().keySet()) {
BasicClientCookie cookie = new BasicClientCookie(cookieName, input.getReqCookies().get(cookieName));
cookie.setDomain(this.getDomain(input.getUri()));
@@ -320,6 +306,8 @@ public class OnapHttpConnection {
}
requestBase.setURI(URI.create(input.getUri()));
+ requestBase.setConfig(RequestConfig.custom()
+ .setSocketTimeout(30000).setConnectTimeout(50000).build());
for (Entry<String, String> h : input.getReqHeaders().entrySet()) {
requestBase.addHeader(h.getKey(), h.getValue());
@@ -328,7 +316,6 @@ public class OnapHttpConnection {
HttpResult result = new HttpResult();
try {
- this.debugDetails = "";
CookieStore cookieStore = new BasicCookieStore();
updateInputFromCookies(input, cookieStore);
HttpContext localContext = new BasicHttpContext();
@@ -344,12 +331,6 @@ public class OnapHttpConnection {
this.updateResultFromCookies(result, cookieStore.getCookies());
} catch (Exception e) { // NOSONAR
throw new OnapCommandHttpFailure(e);
- } finally {
- String info = input + " " + result;
- log.info(info);
- if (this.debug) {
- this.debugDetails = info;
- }
}
return result;
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 f4a6cee5..5cab0a68 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
@@ -76,24 +76,22 @@ public class OnapCommandHttpUtils {
}
}
+ inp.setUri(OnapCommandUtils.replaceLineForSpecialValues(input.getUri()));
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));
- }
+ boolean isRemoveEmptyNodes = Boolean.parseBoolean(input.getContext().getOrDefault(OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES, "false"));
- for (String h : input.getReqQueries().keySet()) {
- String value = input.getReqQueries().get(h);
- inp.getReqQueries().put(h, OnapCommandUtils.replaceLineFromInputParameters(value, params));
+ //Process for md5
+ Map <String, String> values = new HashMap<>();
+ for (Map.Entry<String, OnapCommandParameter> param: params.entrySet()) {
+ values.put(param.getKey(), param.getValue().getValue().toString());
}
- boolean isRemoveEmptyNodes = Boolean.parseBoolean(input.getContext().getOrDefault(OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES, "false"));
-
if (input.getMultiparts().size() > 0) {
for (HttpInput.Part part: input.getMultiparts()) {
+ part.setContent(OnapCommandUtils.replaceLineForSpecialValues(part.getContent(), values));
part.setContent(OnapCommandUtils.replaceLineFromInputParameters(part.getContent(), params));
if (isRemoveEmptyNodes) {
part.setContent(OnapCommandHttpUtils.normalizeJson(part.getContent()));
@@ -103,11 +101,28 @@ public class OnapCommandHttpUtils {
inp.setMultiparts(input.getMultiparts());
} else {
inp.setMultipartEntityName(input.getMultipartEntityName());
- inp.setBody(OnapCommandUtils.replaceLineFromInputParameters(input.getBody(), params));
+ inp.setBody(OnapCommandUtils.replaceLineForSpecialValues(input.getBody(), values));
+ inp.setBody(OnapCommandUtils.replaceLineFromInputParameters(inp.getBody(), params));
if (isRemoveEmptyNodes) {
inp.setBody(OnapCommandHttpUtils.normalizeJson(inp.getBody()));
}
}
+
+ //consider __body__ spl entry
+ values.put(OnapCommandHttpConstants.__BODY__, inp.getBody());
+
+ for (String h : input.getReqHeaders().keySet()) {
+ String value = input.getReqHeaders().get(h);
+ value = OnapCommandUtils.replaceLineForSpecialValues(value, values);
+ inp.getReqHeaders().put(h, OnapCommandUtils.replaceLineFromInputParameters(value, params));
+ }
+
+ for (String h : input.getReqQueries().keySet()) {
+ String value = input.getReqQueries().get(h);
+ value = OnapCommandUtils.replaceLineForSpecialValues(value, values);
+ inp.getReqQueries().put(h, OnapCommandUtils.replaceLineFromInputParameters(value, params));
+ }
+
return inp;
}
diff --git a/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java b/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java
index fab02ff2..f0115580 100644
--- a/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java
+++ b/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java
@@ -72,8 +72,7 @@ public class OnapHttpConnectionTest {
}
};
inp.setMethod("get");
- con = new OnapHttpConnection(true);
- con.getDebugInfo();
+ con = new OnapHttpConnection();
con.get(inp);
}
@@ -90,7 +89,7 @@ public class OnapHttpConnectionTest {
};
inp.setMethod("post");
- con = new OnapHttpConnection(true);
+ con = new OnapHttpConnection();
con.post(inp);
}
@@ -108,7 +107,7 @@ public class OnapHttpConnectionTest {
inp.setMethod("post");
inp.setBinaryData(true);
- con = new OnapHttpConnection(true);
+ con = new OnapHttpConnection();
con.post(inp);
}
@@ -123,7 +122,7 @@ public class OnapHttpConnectionTest {
}
};
inp.setMethod("put");
- con = new OnapHttpConnection(true);
+ con = new OnapHttpConnection();
con.put(inp);
}
@@ -138,7 +137,7 @@ public class OnapHttpConnectionTest {
}
};
inp.setMethod("delete");
- con = new OnapHttpConnection(true);
+ con = new OnapHttpConnection();
con.delete(inp);
}
@@ -153,14 +152,14 @@ public class OnapHttpConnectionTest {
}
};
inp.setMethod("other");
- con = new OnapHttpConnection(true);
+ con = new OnapHttpConnection();
con.request(inp);
}
@Test()
public void httpUnSecuredCloseExceptionTest() throws OnapCommandHttpFailure {
inp.setMethod("other");
- con = new OnapHttpConnection(true);
+ con = new OnapHttpConnection();
con.close();
}
@@ -185,7 +184,7 @@ public class OnapHttpConnectionTest {
inp.setReqHeaders(new HashMap<String, String>());
inp.setReqQueries(new HashMap<String, String>());
inp.setUri("https://192.168.99.10:80");
- OnapHttpConnection con = new OnapHttpConnection(false);
+ OnapHttpConnection con = new OnapHttpConnection();
con.get(inp);
} catch (OnapCommandHttpFailure e) {
assertEquals("0x3001::IO Exception", e.getMessage());