[
https://issues.apache.org/jira/browse/CXF-8750?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Andriy Redko resolved CXF-8750.
-------------------------------
Resolution: Fixed
> Swagger UI not working in Karaf 4.4.0 due to a double slash
> -----------------------------------------------------------
>
> Key: CXF-8750
> URL: https://issues.apache.org/jira/browse/CXF-8750
> Project: CXF
> Issue Type: Bug
> Components: JAX-RS
> Affects Versions: 3.5.3, 3.4.8
> Environment: Karaf 4.4.0
> Apache CXF 3.5.3
> Reporter: Aleksy Wróblewski
> Priority: Major
> Labels: swagger
> Fix For: 4.0.0, 3.6.0, 3.5.4, 3.4.9
>
>
> Hello,
> we've been using Apache CXF for the REST API in our OSGi/Karaf project,
> deploying it via the [cxf
> feature|https://github.com/apache/cxf/blob/main/osgi/karaf/features/src/main/resources/features.xml]
> together with the webjars bundle for Swagger UI as described
> [here|https://cxf.apache.org/docs/openapifeature.html]. 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|https://github.com/apache/cxf/blob/main/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/ui/OsgiSwaggerUiResolver.java]:
> {code:java}
> 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;
> }
> {code}
> 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.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)