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;
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) {
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;
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);
}
}
}
* @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));
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.";
* @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 {
}
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);
return path;
}
+ /**
+ * 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.
*
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);
}
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;
verifyAttListRpc(ctx, outPre);
}
+ /**
+ * 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.