summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java18
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java29
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java3
-rw-r--r--restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java49
4 files changed, 83 insertions, 16 deletions
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java
index f9a1ecbf..91ce3338 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java
@@ -54,6 +54,7 @@ import java.util.Map;
import static java.lang.String.format;
import static org.apache.commons.lang3.StringUtils.join;
+import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PATCH;
import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.POST;
import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PUT;
import static org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode.parseParam;
@@ -153,7 +154,8 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin {
InstanceIdentifierContext<?> insIdCtx = getInsIdCtx(p, uri);
String req = null;
- if (p.httpMethod == POST || p.httpMethod == PUT) {
+ if (p.httpMethod == POST || p.httpMethod == PUT
+ || p.httpMethod == PATCH) {
req = serializeRequest(props, p, uri, insIdCtx);
}
if (req == null && p.requestBody != null) {
@@ -181,8 +183,8 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin {
log.error(REQ_ERR + e.getMessage(), e);
String prefix = parseParam(paramMap, RES_PRE, false, null);
- if (retryPolicy == null || shouldRetry == false) {
- setFailureResponseStatus(ctx, prefix, e.getMessage(), r);
+ if (retryPolicy == null || !shouldRetry) {
+ setFailureResponseStatus(ctx, prefix, e.getMessage());
} else {
if (retryCount == null) {
retryCount = 0;
@@ -198,12 +200,11 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin {
sendRequest(paramMap, ctx, retryCount);
} else {
log.debug(MAX_RETRY_ERR);
- setFailureResponseStatus(ctx, prefix,
- e.getMessage(), r);
+ setFailureResponseStatus(ctx, prefix, e.getMessage());
}
} catch (Exception ex) {
log.error(NO_MORE_RETRY, ex);
- setFailureResponseStatus(ctx, prefix, RETRY_FAIL, r);
+ setFailureResponseStatus(ctx, prefix, RETRY_FAIL);
}
}
}
@@ -338,11 +339,10 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin {
* @param ctx service logic context
* @param prefix prefix to be added
* @param errMsg error message
- * @param res http response
*/
private void setFailureResponseStatus(SvcLogicContext ctx, String prefix,
- String errMsg, HttpResponse res) {
- res = new HttpResponse();
+ String errMsg) {
+ HttpResponse res = new HttpResponse();
res.code = 500;
res.message = errMsg;
ctx.setAttribute(prefix + RES_CODE, String.valueOf(res.code));
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java
index 0f9c9401..b51272f7 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java
@@ -97,8 +97,6 @@ public final class RestconfApiUtils {
private static final String URL_SYNTAX = "The following URL cannot be " +
"parsed into URI : ";
- private static final String RESTCONF_PATH = "/restconf/operations/";
-
private static final String PUT_NODE_ERR = "The following URL does not " +
"contain minimum two nodes for PUT operation.";
@@ -136,7 +134,7 @@ public final class RestconfApiUtils {
* @return YANG path pointing to parent
* @throws SvcLogicException when parsing the URL fails
*/
- static String parseUrl(String url, HttpMethod method)
+ public static String parseUrl(String url, HttpMethod method)
throws SvcLogicException {
URI uri;
try {
@@ -146,9 +144,7 @@ public final class RestconfApiUtils {
}
String path = uri.getPath();
- if (path.contains(RESTCONF_PATH)) {
- path = path.replaceFirst(RESTCONF_PATH, "");
- }
+ path = getParsedPath(path);
if (method == PUT) {
if (!path.contains(SLASH)) {
throw new SvcLogicException(PUT_NODE_ERR + url);
@@ -159,6 +155,27 @@ public final class RestconfApiUtils {
}
/**
+ * Returns the path which contains only the schema nodes.
+ *
+ * @param path path
+ * @return path representing schema
+ */
+ private static String getParsedPath(String path) {
+ String firstHalf;
+ if (path.contains(":")) {
+ String[] p = path.split(":");
+ if (p[0].contains(SLASH)) {
+ int slash = p[0].lastIndexOf(SLASH);
+ firstHalf = p[0].substring(slash + 1);
+ } else {
+ firstHalf = p[0];
+ }
+ return firstHalf + ":" + p[1];
+ }
+ return path;
+ }
+
+ /**
* Returns the schema context of the YANG files present in a directory.
*
* @param di directory path
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java
index 6f9f9070..1fd0d2de 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/MdsalSerializerHelper.java
@@ -274,11 +274,12 @@ public class MdsalSerializerHelper extends SerializerHelper<SchemaNode, SchemaCo
if (curSchemaNode instanceof DataSchemaNode) {
Deque<DataSchemaNode> dataSchema = findSchemaNodeByNameAndNamespace(
(DataSchemaNode) curSchemaNode, name, namespace.moduleNs());
+
if (dataSchema != null && !dataSchema.isEmpty()) {
childNode = dataSchema.pop();
}
- if (!dataSchema.isEmpty()) {
+ if (dataSchema != null && !dataSchema.isEmpty()) {
childNode = findSchemaForChild(((ChoiceSchemaNode) childNode),
qname);
}
diff --git a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java
index 0f46d625..6c11206c 100644
--- a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java
+++ b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java
@@ -41,6 +41,10 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.GET;
+import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.POST;
+import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PUT;
+import static org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiUtils.parseUrl;
import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_FROM_JSON_RPC;
import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_FROM_XML_RPC;
import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_ID;
@@ -317,6 +321,51 @@ public class DataFormatSerializerTest {
}
/**
+ * Verifies URL parser returning path with only schema information for all
+ * kind of URL.
+ *
+ * @throws SvcLogicException when test case fails
+ */
+ @Test
+ public void validateUrlParser() throws SvcLogicException {
+ String actVal = "identity-test:test";
+ String url1 = "http://echo.getpostman.com/restconf/operations/" +
+ actVal;
+ String url2 = "http://echo.getpostman.com/restconf/data/" + actVal;
+ String url3 = "https://echo.getpostman.com/restconf/operations/" +
+ actVal;
+ String url4 = "https://echo.getpostman.com/restconf/data/" + actVal +
+ "/for-put";
+ String url5 = "http://localhost:8282/restconf/operations/" + actVal;
+ String url6 = "https://localhost:8282/restconf/operations/" + actVal;
+ String url7 = "http://localhost:8282/restconf/data/" + actVal +
+ "/for-put";
+ String url8 = "https://localhost:8282/restconf/data/" + actVal;
+ String url9 = "http://182.2.61.24:2250/restconf/data/" + actVal;
+ String url10 = "https://182.2.61.24:2250/restconf/operations/" + actVal;
+ String val1 = parseUrl(url1, POST);
+ String val2 = parseUrl(url2, GET);
+ String val3 = parseUrl(url3, POST);
+ String val4 = parseUrl(url4, PUT);
+ String val5 = parseUrl(url5, GET);
+ String val6 = parseUrl(url6, POST);
+ String val7 = parseUrl(url7, PUT);
+ String val8 = parseUrl(url8, POST);
+ String val9 = parseUrl(url9, GET);
+ String val10 = parseUrl(url10, POST);
+ assertThat(val1, is(actVal));
+ assertThat(val2, is(actVal));
+ assertThat(val3, is(actVal));
+ assertThat(val4, is(actVal));
+ assertThat(val5, is(actVal));
+ assertThat(val6, is(actVal));
+ assertThat(val7, is(actVal));
+ assertThat(val8, is(actVal));
+ assertThat(val9, is(actVal));
+ assertThat(val10, is(actVal));
+ }
+
+ /**
* Creates attribute list for encoding JSON or XML with identity-ref YANG
* file.
*