Uploaded image for project: 'Thorntail'
  1. Thorntail
  2. THORN-574

Keycloak Fraction fails because of ClassCastException when web.xml is added via Shrinkwrap

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 1.0.0.Final
    • Fix Version/s: 2016.8
    • Component/s: None
    • Labels:
      None
    • Steps to Reproduce:
      Hide

      Set up a minimal swarm project including the dependency

             <dependency>
                  <groupId>org.wildfly.swarm</groupId>
                  <artifactId>keycloak</artifactId>
              </dependency>
      

      Add the follwing main class to your project and use either the IDE or maven to run it

      public class SwarmApp {
      
          public static void main(String[] args) throws Exception {
              Container container = new Swarm(args);
      
              // this would cause an exception
      //        WARArchive archive = ShrinkWrap.create(WARArchive.class)
      //                .addAsWebResource("index.xhtml")
      //                .addAsWebInfResource("WEB-INF/faces-config.xml")
      //                .addAsWebInfResource("WEB-INF/web.xml");
      
              // this works as the web xml is explicitly set as an WebXMLAsset wich extends
              // the NamedAsset Interface
              WARArchive archive = ShrinkWrap.create(WARArchive.class)
                      .addAsWebResource("index.xhtml")
                      .addAsWebInfResource("WEB-INF/faces-config.xml")
                      .setWebXML(new WebXmlAsset(new ClassLoaderAsset("WEB-INF/web.xml").openStream()));
      
              archive.as(Secured.class);
      
              container.start();
      
              container.deploy(archive);
          }
      }
      
      Show
      Set up a minimal swarm project including the dependency <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>keycloak</artifactId> </dependency> Add the follwing main class to your project and use either the IDE or maven to run it public class SwarmApp { public static void main( String [] args) throws Exception { Container container = new Swarm(args); // this would cause an exception // WARArchive archive = ShrinkWrap.create(WARArchive.class) // .addAsWebResource( "index.xhtml" ) // .addAsWebInfResource( "WEB-INF/faces-config.xml" ) // .addAsWebInfResource( "WEB-INF/web.xml" ); // this works as the web xml is explicitly set as an WebXMLAsset wich extends // the NamedAsset Interface WARArchive archive = ShrinkWrap.create(WARArchive.class) .addAsWebResource( "index.xhtml" ) .addAsWebInfResource( "WEB-INF/faces-config.xml" ) .setWebXML( new WebXmlAsset( new ClassLoaderAsset( "WEB-INF/web.xml" ).openStream())); archive.as(Secured.class); container.start(); container.deploy(archive); } }

      Description

      When using Shrinkwrap to deploy a WARARchive (undertow-api) while adding the web.xml either via the WARArchive#addAsWebInfResource or the WARArchive#setWebXML methods the deployment fails with a ExtensionLoadingException based on the follwoing stack trace:

      Stacktrace
      Exception in thread "main" org.jboss.shrinkwrap.impl.base.ExtensionLoadingException: Failed to instantiate class of type class org.jboss.shrinkwrap.impl.base.MemoryMapArchiveImpl. The underlying constructor threw an exception.
      	at org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader.createExtension(ServiceExtensionLoader.java:365)
      	at org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader.createFromLoadExtension(ServiceExtensionLoader.java:223)
      	at org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader.load(ServiceExtensionLoader.java:108)
      	at org.jboss.shrinkwrap.impl.base.ArchiveBase.as(ArchiveBase.java:686)
      	at org.jboss.shrinkwrap.impl.base.AssignableBase.as(AssignableBase.java:67)
      	at at.ac.fhkufstein.swarm.study.SwarmApp.main(SwarmApp.java:20)
      Caused by: java.lang.reflect.InvocationTargetException
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      	at org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader.createExtension(ServiceExtensionLoader.java:354)
      	... 5 more
      Caused by: java.lang.ClassCastException: org.jboss.shrinkwrap.api.asset.ClassLoaderAsset cannot be cast to org.jboss.shrinkwrap.api.asset.NamedAsset
      	at org.wildfly.swarm.keycloak.internal.SecuredImpl.<init>(SecuredImpl.java:55)
      	... 10 more
      

      As far as I can see this happens as the constructor of the SecuredImpl class looks for the web.xml node in the deployment and casts it explicitly to a NamedAsset - which causes the aforementioned Exception.

      As no method of the interface is ever used at this point and it fails at least in the cases I encountered today I propose to omit the cast and use the more general Asset interface instead - if you see this suggestion as a fitting solution I would be glad to set up the needed pull request.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                bob.mcwhirter Bob McWhirter
                Reporter:
                WalternativE Gregor Beyerle
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: