Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-8750

Swagger UI not working in Karaf 4.4.0 due to a double slash

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.5.3, 3.4.8
    • 3.5.4, 3.4.9, 4.0.0, 3.6.0
    • JAX-RS
    • Karaf 4.4.0

      Apache CXF 3.5.3

    • Unknown

    Description

      Hello,

      we've been using Apache CXF for the REST API in our OSGi/Karaf project, deploying it via the cxf feature together with the webjars bundle for Swagger UI as described here. It was working fine, however at some point (I think when migrating to a newer Karaf version), the UI stopped working.

      I investigated this a little and it turns out that this is because of a double slash when locating the webjars resource via OsgiSwaggerUiResolver:

          private String getSwaggerUiRoot(Bundle b, String swaggerUiVersion) {
              if (swaggerUiVersion == null) { 
                  swaggerUiVersion = b.getVersion().toString();
              }
              URL entry = b.getEntry(SwaggerUiResolver.UI_RESOURCES_ROOT_START + swaggerUiVersion);
              if (entry != null) {
                  return entry.toString() + "/";
              }
              return null;
          }
      

      If the entry returned from Bundle.getEntry already contains a trailing slash, adding another one in the if block stops the webjars resources from being accessed because the URL is then incorrect. I think this depends on the OSGi implementation, whether it returns the entry with the trailing slash or not. Apache Felix in Karaf 4.4.0 returns it. So ideally it should be added conditionally if necessary, but not always.

      In our case, what was returned from the method was:

      bundle://c51ac79e-eaa5-4d6a-9456-35ff46a4fc9b_226.0:0/META-INF/resources/webjars/swagger-ui/4.13.2//

      while it should be:
      bundle://c51ac79e-eaa5-4d6a-9456-35ff46a4fc9b_226.0:0/META-INF/resources/webjars/swagger-ui/4.13.2/

      With the double slash, SwaggerUiService gets IOExceptions when trying to read the resources (index.html, swagger js/css files).

      I tested and without the extra slash it works fine again, will submit a pull request shortly.

      Attachments

        Activity

          People

            Unassigned Unassigned
            aleksy.wroblewski Aleksy Wróblewski
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: