X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FControllerContext.xtend;h=66e5cbf910fa159fcabb76a02326de23b069737d;hb=8304daea948c306cbdaf9ba4edb4b64e9840f8d9;hp=c2b82eae632290cc60d48df245d70fa1c583e8b8;hpb=2c7c9ef5e517de98e0d740f938762cc746dbcde1;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend index c2b82eae63..66e5cbf910 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend @@ -57,6 +57,8 @@ class ControllerContext implements SchemaServiceListener { val static MOUNT_MODULE = "yang-ext" val static MOUNT_NODE = "mount" public val static MOUNT = "yang-ext:mount" + val static URI_ENCODING_CHAR_SET = "ISO-8859-1" + val static URI_SLASH_PLACEHOLDER = "%2F"; @Property var SchemaContext globalSchema; @@ -98,7 +100,8 @@ class ControllerContext implements SchemaServiceListener { private def InstanceIdWithSchemaNode toIdentifier(String restconfInstance, boolean toMountPointIdentifier) { checkPreconditions - val pathArgs = Lists.newArrayList(Splitter.on("/").split(restconfInstance)) + val encodedPathArgs = Lists.newArrayList(Splitter.on("/").split(restconfInstance)) + val pathArgs = urlPathArgsDecode(encodedPathArgs) pathArgs.omitFirstAndLastEmptyString if (pathArgs.empty) { return null; @@ -353,7 +356,8 @@ class ControllerContext implements SchemaServiceListener { private def toUriString(Object object) { if(object === null) return ""; - return URLEncoder.encode(object.toString) +// return object.toString.replace("/",URI_SLASH_PLACEHOLDER) + return URLEncoder.encode(object.toString,URI_ENCODING_CHAR_SET) } private def InstanceIdWithSchemaNode collectPathArguments(InstanceIdentifierBuilder builder, List strings, @@ -545,12 +549,18 @@ class ControllerContext implements SchemaServiceListener { val typedef = (node as LeafSchemaNode).type; var decoded = TypeDefinitionAwareCodec.from(typedef)?.deserialize(urlDecoded) + var additionalInfo = "" if(decoded === null) { var baseType = RestUtil.resolveBaseTypeFrom(typedef) if(baseType instanceof IdentityrefTypeDefinition) { decoded = toQName(urlDecoded) + additionalInfo = "For key which is of type identityref it should be in format module_name:identity_name." } } + if (decoded === null) { + throw new ResponseException(BAD_REQUEST, uriValue + " from URI can't be resolved. "+ additionalInfo ) + } + map.put(node.QName, decoded); } @@ -599,11 +609,23 @@ class ControllerContext implements SchemaServiceListener { } override onGlobalContextUpdated(SchemaContext context) { - this.globalSchema = context; - for (operation : context.operations) { - val qname = operation.QName; - qnameToRpc.put(qname, operation); + if (context !== null) { + qnameToRpc.clear + this.globalSchema = context; + for (operation : context.operations) { + val qname = operation.QName; + qnameToRpc.put(qname, operation); + } } } + + def urlPathArgsDecode(List strings) { + val List decodedPathArgs = new ArrayList(); + for (pathArg : strings) { + decodedPathArgs.add(URLDecoder.decode(pathArg, URI_ENCODING_CHAR_SET)) + } + return decodedPathArgs + } + }