Uploaded image for project: 'netconf'
  1. netconf
  2. NETCONF-587

Restconf Apidoc can't list mounted resources

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: High High
    • Neon
    • Oxygen, Oxygen SR3
    • restconf-nb
    • High

      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.

            wusandi sandi wu
            wusandi sandi wu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 1 hour
                1h
                Remaining:
                Remaining Estimate - 1 hour
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified