Uploaded image for project: 'Blazegraph (by SYSTAP)'
  1. Blazegraph (by SYSTAP)
  2. BLZG-1143

Extension REST API does not support multiple context values

    Details

    • Type: Bug
    • Status: Done
    • Resolution: Done
    • Affects Version/s: BIGDATA_RELEASE_1_4_0
    • Fix Version/s: None
    • Component/s: B+Tree

      Description

      This was first reported for DELETE-BY-ACCESS-PATH. The RemoteRepository is using this pattern to build up these URL query parameters (similar code applies for other REST API methods).

                  if (remove.context != null && remove.context.length > 0) {
                      // set the default context.
                      opts.addRequestParam("context-uri", toStrings(remove.context));
                  }
      

      However, this was not properly turned into multiple URL query parameters in AbstractConnectOptions:

          static public void addQueryParams(final StringBuilder urlString,
                  final Map<String, String[]> requestParams)
                  throws UnsupportedEncodingException {
              if (requestParams == null)
                  return;
              boolean first = true;
              for (Map.Entry<String, String[]> e : requestParams.entrySet()) {
                  urlString.append(first ? "?" : "&");
                  first = false;
                  final String name = e.getKey();
                  final String[] vals = e.getValue();
                  if (vals == null) {
                      urlString.append(URLEncoder.encode(name, RemoteRepository.UTF8));
                  } else {
                      for (String val : vals) {
                          urlString.append(URLEncoder.encode(name, RemoteRepository.UTF8));
                          urlString.append("=");
                          urlString.append(URLEncoder.encode(val, RemoteRepository.UTF8));
                      }
                  }
              } // next Map.Entry
      
          }
      

      The problem is that the "&" character was not appended if the array of values was of length GT ONE. In this case the values were concatenated together rather than appearing as distinct URL query parameter values.

      See BLZG-1209 Resource... contexts not encoded/decoded according to openrdf semantics (REST API)

        Activity

        Hide
        bryanthompson bryanthompson added a comment -

        Ok. The bug is that the AbstractConnectOptions.addQueryParams() method mentioned above does not add a "?" or "&" character inside of the loop over multiple bindings for a given URL request parameter. This results in them all being smushed together by the API.

        It appears that we lack unit test coverage for cases where the URL request parameter appears more than once so this issue was not detected.

        Show
        bryanthompson bryanthompson added a comment - Ok. The bug is that the AbstractConnectOptions.addQueryParams() method mentioned above does not add a "?" or "&" character inside of the loop over multiple bindings for a given URL request parameter. This results in them all being smushed together by the API. It appears that we lack unit test coverage for cases where the URL request parameter appears more than once so this issue was not detected.
        Hide
        bryanthompson bryanthompson added a comment -

        The fix is:

            static public void addQueryParams(final StringBuilder urlString,
                    final Map<String, String[]> requestParams)
                    throws UnsupportedEncodingException {
                if (requestParams == null)
                    return;
                boolean first = true;
                for (Map.Entry<String, String[]> e : requestParams.entrySet()) {
                    final String name = e.getKey();
                    final String[] vals = e.getValue();
                    if (vals == null) {
                        urlString.append(first ? "?" : "&");
                        first = false;
                        urlString.append(URLEncoder.encode(name, RemoteRepository.UTF8));
                    } else {
                        for (String val : vals) {
                            urlString.append(first ? "?" : "&");
                            first = false;
                            urlString.append(URLEncoder.encode(name, RemoteRepository.UTF8));
                            urlString.append("=");
                            urlString.append(URLEncoder.encode(val, RemoteRepository.UTF8));
                        }
                    }
                } // next Map.Entry
        
            }
        
        Show
        bryanthompson bryanthompson added a comment - The fix is: static public void addQueryParams(final StringBuilder urlString, final Map<String, String[]> requestParams) throws UnsupportedEncodingException { if (requestParams == null) return; boolean first = true; for (Map.Entry<String, String[]> e : requestParams.entrySet()) { final String name = e.getKey(); final String[] vals = e.getValue(); if (vals == null) { urlString.append(first ? "?" : "&"); first = false; urlString.append(URLEncoder.encode(name, RemoteRepository.UTF8)); } else { for (String val : vals) { urlString.append(first ? "?" : "&"); first = false; urlString.append(URLEncoder.encode(name, RemoteRepository.UTF8)); urlString.append("="); urlString.append(URLEncoder.encode(val, RemoteRepository.UTF8)); } } } // next Map.Entry }
        Hide
        bryanthompson bryanthompson added a comment -

        Committed revision ac25eb223ef4922c312b85c35dade48b1bb3110e

        Show
        bryanthompson bryanthompson added a comment - Committed revision ac25eb223ef4922c312b85c35dade48b1bb3110e

          People

          • Assignee:
            bryanthompson bryanthompson
            Reporter:
            bryanthompson bryanthompson
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: