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

Vadim Beilin commented on CXF-7474:
-----------------------------------

In our case URLClassLoader.getURLs() contains only the URL of 
all_dependencies.jar, and all_dependencies.jar!/META-INF/MANIFEST.MF has 
swagger-ui-NNN.jar in its Class-Path attribute. So iteration over the 
URLClassLoader's classpath reveals all_dependencies.jar, but not the swagger-ui 
jar.

This is my test (I modified findSwaggerUiRoot to accept ClassLoader for testing 
purposes):

{code}
        File tmpfile = Files.createTempFile("all_dependencies", 
".jar").toFile();
        tmpfile.deleteOnExit();

        Manifest mf = new Manifest();
        mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
        mf.getMainAttributes().put(Attributes.Name.CLASS_PATH,
                "......./swagger-ui-2.1.2.jar"); // <- location of the 
swagger-ui jar, differrent form the default version
        JarOutputStream jos = new JarOutputStream(new 
FileOutputStream(tmpfile), mf);
        jos.flush();
        jos.close();

        try (URLClassLoader cl = new URLClassLoader(new URL[] { 
tmpfile.toURI().toURL() }, null);) {
            String uiroot = SwaggerUiResolver.findSwaggerUiRoot(cl, null, 
null); // <-- modification for testing purposes
            Assert.assertNotNull("not found in all_dependencies.jar", uiroot);
            Assert.assertThat(uiroot, containsString("2.1.2"));
        }
{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
>            Assignee: Sergey Beryozkin
>             Fix For: 3.1.13, 3.2.0
>
>
> 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)

Reply via email to