cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Olivier Paquet (JIRA)" <j...@apache.org>
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
                 URL: https://issues.apache.org/jira/browse/CXF-7474
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
    Affects Versions: 3.2.0
            Reporter: Olivier Paquet


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.

{code}
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.
{code}

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:

{code}
final String resourcesRootStart = "META-INF/resources/webjars/swagger-ui/";
ClassLoader cl = AbstractSwaggerFeature.class.getClassLoader();
if (cl instanceof URLClassLoader) { ...
{code}

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 :

{code}
} 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 + "/";
                      }
                  }
              }
            }
{code}

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
(v6.4.14#64029)

Mime
View raw message