aboutsummaryrefslogtreecommitdiffstats
path: root/profiles/http
diff options
context:
space:
mode:
authorKanagaraj M <mkr1481@gmail.com>2019-08-02 14:10:30 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2019-08-05 19:49:23 +0530
commitb100c49fbd130e4fe58ce82f1e5f765f13917703 (patch)
treecb5d5d0c42ea17939b98b76229cc341c6f2332d9 /profiles/http
parentf24ae00ec10cdcbab41429841926051ba08c88ec (diff)
Update framework
Issue-ID: CLI-169 Change-Id: Ice38da575d2e349bb875149afd894e348bc20253 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'profiles/http')
-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
6 files changed, 80 insertions, 80 deletions
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());