Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-3266

RestEasy JSAPI Servlet does not work with root "/" or empty @ApplicationPath("")

    XMLWordPrintable

Details

    Description

      If using a @ApplicationPath("") or @ApplicationPath("/") the JSAPIWriter appends a trailing slash onto the uri. The endpoint is then also appended in the generated javascript client which results in a double slash in the final url.

      For example from generated client javascript:

      REST.apiURL = 'https://localhost:17080/api/';
      var ListApi = {};
      // POST /list/contact
      ListApi.contact = function(_params){
       var params = _params ? _params : {};
       var request = new REST.Request();
       request.setMethod('POST');
       var uri = params.$apiURL ? params.$apiURL : REST.apiURL;
       uri += '/list/contact';

      The end url is: https://localhost:17080/api//list/contact which fails due to the double slash.

      The buggy code in question is in JSAPIWriter at line 51:

            for (Map.Entry<String, ServiceRegistry> entry : serviceRegistries.entrySet())
            {
               String uri = base;
               if (entry.getKey() != null) uri += entry.getKey();

      For a empty @ApplicationPath(""), the service registry will have an entry.getKey() of "/" which erroneously gets appended to the uri.

      Fix could maybe be:

      if (entry.getKey() != null && !entry.getKey().equals("/")) uri += entry.getKey();

       

       

       

      Attachments

        Activity

          People

            pberan@redhat.com Petr Beran
            coachautomator Franz Schöning (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: