Description
Hi,
We currently try to use the Swagger2Feature with the Swagger UI integration, so following your documentation. So we added the dependency in our Maven project.
Enabling Swagger UI First one needs to add the following <dependency> <groupId>org.webjars</groupId> <artifactId>swagger-ui</artifactId> <version>2.2.10-1</version> </dependency> The newest version 3.x of swagger-ui can also be used.
But after deploying the application in a JBoss 6.4 EAP, the url containing the /api-docs could not be mapped.
So I debugged the https://github.com/apache/cxf/blob/master/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java and found out that you do something like:
final String resourcesRootStart = "META-INF/resources/webjars/swagger-ui/"; ClassLoader cl = AbstractSwaggerFeature.class.getClassLoader(); if (cl instanceof URLClassLoader) { ...
But in JBoss the Classloader is of type ModuleClassloader, so it will never get into this if case.
So I added the following code to bypass this issue :
} else { Enumeration<URL> urls = cl.getResources("META-INF/resources/webjars/swagger-ui/"); while (urls.hasMoreElements()) { URL url = urls.nextElement(); String urlStr = url.toString(); urlStr = urlStr.replace("META-INF/resources/webjars/swagger-ui/", ""); int swaggerUiIndex = urlStr.lastIndexOf("/swagger-ui-"); if (swaggerUiIndex != -1) { boolean urlEndsWithJarSep = urlStr.endsWith(".jar!/"); if (urlEndsWithJarSep || urlStr.endsWith(".jar")) { int offset = urlEndsWithJarSep ? 6 : 4; String version = urlStr.substring(swaggerUiIndex + 12, urlStr.length() - offset); if (swaggerUiVersion != null && !swaggerUiVersion.equals(version)) { continue; } if (!urlEndsWithJarSep) { urlStr = "jar:" + urlStr + "!/"; } return urlStr + resourcesRootStart + version + "/"; } } } }
This was not working directly because of the JBoss VFS filesystem, so I moved the swagger-ui.jar into a separater JBoss module which I included using a jboss-deploymentstructure.xml.
Now the url http://localhost:8081/.../app/swaggerSample/api-docs?url=http://localhost:8081/.../app/swaggerSample/swagger.json is working and displays me the Swagger UI.
Here are the information:
- CXF version: 3.2.0-SNAPSHOT
- Java 8
- JBoss 6.4 EAP / JBoss Wildfly 10
I can provide you with all information in case you need my project / war file ...