Search in sources :

Example 61 with ArchivePath

use of org.jboss.shrinkwrap.api.ArchivePath in project keycloak by keycloak.

the class UndertowDeployerHelper method addAnnotatedServlets.

private void addAnnotatedServlets(DeploymentInfo di, Archive<?> archive) {
    Map<ArchivePath, Node> classNodes = archive.getContent((ArchivePath path) -> {
        String stringPath = path.get();
        return (stringPath.startsWith("/WEB-INF/classes") && stringPath.endsWith("class"));
    });
    for (Map.Entry<ArchivePath, Node> entry : classNodes.entrySet()) {
        Node n = entry.getValue();
        if (n.getAsset() instanceof ClassAsset) {
            ClassAsset classAsset = (ClassAsset) n.getAsset();
            Class<?> clazz = classAsset.getSource();
            WebServlet annotation = clazz.getAnnotation(WebServlet.class);
            if (annotation != null) {
                ServletInfo undertowServlet = new ServletInfo(clazz.getSimpleName(), (Class<? extends Servlet>) clazz);
                String[] mappings = annotation.value();
                if (mappings != null) {
                    for (String urlPattern : mappings) {
                        undertowServlet.addMapping(urlPattern);
                    }
                }
                di.addServlet(undertowServlet);
            }
        }
    }
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) ClassAsset(org.jboss.shrinkwrap.api.asset.ClassAsset) WebServlet(javax.servlet.annotation.WebServlet) Node(org.jboss.shrinkwrap.api.Node) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArchivePath (org.jboss.shrinkwrap.api.ArchivePath)61 File (java.io.File)39 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)33 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)31 Node (org.jboss.shrinkwrap.api.Node)19 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)17 Map (java.util.Map)13 VirtualFile (org.jboss.vfs.VirtualFile)10 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 Archive (org.jboss.shrinkwrap.api.Archive)7 Deployment (org.jboss.arquillian.container.test.api.Deployment)6 Asset (org.jboss.shrinkwrap.api.asset.Asset)6 URL (java.net.URL)5 ArchiveAsset (org.jboss.shrinkwrap.api.asset.ArchiveAsset)5 JARArchive (org.wildfly.swarm.spi.api.JARArchive)5 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 ZipImporter (org.jboss.shrinkwrap.api.importer.ZipImporter)4 MalformedURLException (java.net.MalformedURLException)3