cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Olivier Paquet (JIRA)" <>
Subject [jira] [Created] (CXF-7474) Swagger2Feature - Swagger UI not working with JBoss
Date Tue, 15 Aug 2017 07:11:00 GMT
Olivier Paquet created CXF-7474:

             Summary: Swagger2Feature - Swagger UI not working with JBoss
                 Key: CXF-7474
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
    Affects Versions: 3.2.0
            Reporter: Olivier Paquet


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

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
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))
                          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 ...

This message was sent by Atlassian JIRA

View raw message