You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Sergey Beryozkin (JIRA)" <ji...@apache.org> on 2017/08/15 08:59:00 UTC

[jira] [Commented] (CXF-7474) Swagger2Feature - Swagger UI not working with JBoss

    [ https://issues.apache.org/jira/browse/CXF-7474?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16126965#comment-16126965 ] 

Sergey Beryozkin commented on CXF-7474:
---------------------------------------

Hi, why did you need to do 
{code:java}
"urlStr = urlStr.replace("META-INF/resources/webjars/swagger-ui/", "");"
{code} 
?

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