[NETCONF-587] Restconf Apidoc can't list mounted resources Created: 12/Dec/18  Updated: 19/Mar/19  Resolved: 19/Mar/19

Status: Resolved
Project: netconf
Component/s: restconf-nb
Affects Version/s: Oxygen, Oxygen SR3
Fix Version/s: Neon

Type: Bug Priority: High
Reporter: sandi wu Assignee: sandi wu
Resolution: Done Votes: 0
Labels: restconf
Remaining Estimate: 1 hour
Time Spent: Not Specified
Original Estimate: 1 hour

Issue Links:
Relates
relates to NETCONF-548 Netconf mounts Undefined in Oxygen SR1 Resolved
Priority: High

 Description   

Problem: when swagger access apidoc/apis/mounts via http://127.0.0.1:8181/apidoc/explorer/index.html
the explorer can't show mounted resources, only some undefined.
Walk the source code in sal-rest-docgen, find that the method "getListOfMounts" of
org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl generate a response json string entity.

{"instance":"/network-topology:network-topology/topology/topology-netconf/node/test/","id":1}

]
but it will be converted by org.opendaylight.aaa.provider.GsonProvider(located aaa-shiro)
specified in ApiDocApplication. GsonProvider internally use com.google.gson.Gson to do this:

public void writeTo(T type, Class<?> theClass, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws WebApplicationException {

try (PrintWriter printWriter = new PrintWriter(entityStream)) {
String json;
final MultivaluedMap<String, String> queryParameters = ui != null ? ui.getQueryParameters() : null;
if (queryParameters != null && queryParameters.containsKey(PRETTY_PRINT))

{ json = prettyGson.toJson(type); }

else

{ json = gson.toJson(type); }

printWriter.write(json);
printWriter.flush();
}
}
}

The problem is here, when the type parameter itself is a json string , it is no need to converted.
otherwise, the special character in type will escape.
For examle, GET /apidoc/apis/mounts will expect to return:
[\{"instance":"/network-topology:network-topology/topology/topology-netconf/node/test/","id":1}]

But now the string above will be converted by GsonProvider to:
"[\{\"instance\":\"/network-topology:network-topology/topology/topology-netconf/node/test/\",\"id\":1}]"

when the explorer/lib/odl/list_mounts.js, as follow:
var loadMountList = function( dom ) {
dom.empty();
dom.append( "<p>Loading. Please wait...</p>" );
$.ajax( {
url: "/apidoc/apis/mounts",
datatype: 'jsonp',
success: function( strData ){
var myData = strData;
var list = $( "<table></table>" );
for( var key in myData )

{ list.append( "<tr><td><a href=\"#\" onclick=\"loadMount(" + myData[key].id + ", '" + myData[key].instance + "')\">" + myData[key].instance + "</a></td></tr>"); }

dom.empty();
dom.append( list );
}
} );
}
will treat it as string other than a json object, so the page can't show the apis of mounted points.


Generated at Wed Feb 07 20:15:24 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.