org.jboss.shrinkwrap.api.asset.UrlAsset Java Examples

The following examples show how to use org.jboss.shrinkwrap.api.asset.UrlAsset. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractServletsAdapterTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
protected static WebArchive servletDeploymentMultiTenant(String name, Class... servletClasses) {
    WebArchive servletDeployment = servletDeployment(name, null, servletClasses);

    String webInfPath = "/adapter-test/" + name + "/WEB-INF/";
    String config1 = "tenant1-keycloak.json";
    String config2 = "tenant2-keycloak.json";

    URL config1Url = AbstractServletsAdapterTest.class.getResource(webInfPath + config1);
    Assert.assertNotNull("config1Url should be in " + webInfPath + config1, config1Url);
    URL config2Url = AbstractServletsAdapterTest.class.getResource(webInfPath + config2);
    Assert.assertNotNull("config2Url should be in " + webInfPath + config2, config2Url);

    servletDeployment
            .add(new UrlAsset(config1Url), "/WEB-INF/classes/" + config1)
            .add(new UrlAsset(config2Url), "/WEB-INF/classes/" + config2);

    // In this scenario DeploymentArchiveProcessorUtils can not act automatically since the adapter configurations
    // are not stored in typical places. We need to modify them manually.
    DeploymentArchiveProcessorUtils.modifyOIDCAdapterConfig(servletDeployment, "/WEB-INF/classes/" + config1);
    DeploymentArchiveProcessorUtils.modifyOIDCAdapterConfig(servletDeployment, "/WEB-INF/classes/" + config2);

    return servletDeployment;
}
 
Example #2
Source File: AbstractTest.java    From ConfigJSR with Apache License 2.0 5 votes vote down vote up
public static void addFile(JavaArchive archive, String originalPath) {
    String resName = "internal/" + originalPath;
    URL resource = Thread.currentThread().getContextClassLoader().getResource(resName);
    if (resource == null) {
        throw new IllegalStateException("could not load test resource " + resName);
    }
    archive.addAsResource(new UrlAsset(resource),
            originalPath);
}
 
Example #3
Source File: AbstractTest.java    From ConfigJSR with Apache License 2.0 5 votes vote down vote up
public static void addFile(JavaArchive archive, String originalFile, String targetFile) {
    URL resource = Thread.currentThread().getContextClassLoader().getResource(originalFile);
    if (resource == null) {
        throw new IllegalStateException("could not load test resource " + originalFile);
    }
    archive.addAsResource(new UrlAsset(resource),
            targetFile);
}
 
Example #4
Source File: ManagementConsoleDeploymentProducer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Produces
public Archive managementConsoleWar() throws Exception {
    // Load the management-ui webjars.
    WARArchive war = ShrinkWrap.create(WARArchive.class, "management-console-ui.war");
    Module module = Module.getBootModuleLoader().loadModule("org.jboss.as.console");
    Iterator<Resource> resources = module.globResources("*");
    while (resources.hasNext()) {
        Resource each = resources.next();
        war.add(new UrlAsset(each.getURL()), each.getName());
    }
    war.setContextRoot(this.fraction.contextRoot());
    return war;
}
 
Example #5
Source File: SWClassLoader.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
protected URLConnection openConnection(final URL u) throws IOException {
    final String arName = key(u);

    final Archive<?> archive = archives.get(arName);
    final String path = path(archive.getName(), WebArchive.class.isInstance(archive) ? "/WEB-INF/classes/" : "", u);
    Node node = archive.get(path);
    if (node == null) {
        node = archive.get(path(archive.getName(), "", u)); // web resources
        if (node == null) {
            throw new IOException(u.toExternalForm() + " not found");
        }
    }

    final Asset asset = node.getAsset();
    if (UrlAsset.class.isInstance(asset)) {
        return URL.class.cast(Reflections.get(asset, "url")).openConnection();
    } else if (FileAsset.class.isInstance(asset)) {
        return File.class.cast(Reflections.get(asset, "file")).toURI().toURL().openConnection();
    } else if (ClassLoaderAsset.class.isInstance(asset)) {
        return ClassLoader.class.cast(Reflections.get(asset, "classLoader")).getResource(String.class.cast(Reflections.get(asset, "resourceName"))).openConnection();
    }

    return new URLConnection(u) {
        @Override
        public void connect() throws IOException {
            // no-op
        }

        @Override
        public InputStream getInputStream() throws IOException {
            final InputStream input = asset.openStream();
            final Collection<Closeable> c = closeables.get(arName);
            c.add(input);
            return input;
        }
    };
}
 
Example #6
Source File: OpenEJBArchiveProcessor.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static void addPersistenceXml(final Archive<?> archive, final String prefix, final AppModule appModule) {
    Node persistenceXml = archive.get(prefix.concat(PERSISTENCE_XML));
    if (persistenceXml == null && WEB_INF.equals(prefix)) {
        persistenceXml = archive.get(WEB_INF_CLASSES.concat(META_INF).concat(PERSISTENCE_XML));
    }
    if (persistenceXml != null) {
        final Asset asset = persistenceXml.getAsset();
        if (UrlAsset.class.isInstance(asset)) {
            appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(get(URL.class, "url", asset)));
        } else if (FileAsset.class.isInstance(asset)) {
            try {
                appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(get(File.class, "file", asset).toURI().toURL()));
            } catch (final MalformedURLException e) {
                appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset(), null)));
            }
        } else if (ClassLoaderAsset.class.isInstance(asset)) {
            final URL url = get(ClassLoader.class, "classLoader", asset).getResource(get(String.class, "resourceName", asset));
            if (url != null) {
                appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(url));
            } else {
                appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset(), null)));
            }
        } else {
            appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset(), null)));
        }
    }
}
 
Example #7
Source File: ManagedExecutorServiceGetPrincipalInTaskTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Deployment(testable = false)
public static Archive<?> app() {
    ClassLoader cl = ManagedExecutorServiceGetPrincipalInTaskTest.class.getClassLoader();
    URL tcUserFile = cl.getResource("managed/tomcat-users.xml");

    return ShrinkWrap.create(WebArchive.class, "mp.war")
        .addClasses(ConcurrencyServlet.class, User.class)
        .addAsManifestResource(new StringAsset(
            "<Context>" +
            "   <Realm className=\"" + MemoryRealm.class.getName() +
                "\" pathname=\""+ tcUserFile.getFile() + "\" />" +
            "</Context>"), "context.xml")
            .addAsWebInfResource(new UrlAsset(cl.getResource("managed/web.xml")), "web.xml");
}
 
Example #8
Source File: AbstractTest.java    From microprofile-config with Apache License 2.0 4 votes vote down vote up
public static void addFile(JavaArchive archive, String originalPath) {
    archive.addAsResource(new UrlAsset(Thread.currentThread().getContextClassLoader().getResource("internal/" + originalPath)),
            originalPath);
}
 
Example #9
Source File: AbstractTest.java    From microprofile-config with Apache License 2.0 4 votes vote down vote up
public static void addFile(JavaArchive archive, String originalFile, String targetFile) {
    archive.addAsResource(new UrlAsset(Thread.currentThread().getContextClassLoader().getResource(originalFile)),
            targetFile);
}
 
Example #10
Source File: URLJolokiaAccessPreparer.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
protected Asset getJolokiaAccessXmlAsset() {
    return new UrlAsset(this.url);
}
 
Example #11
Source File: AbstractServletsAdapterTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static WebArchive samlServletDeploymentMultiTenant(String name, String webXMLPath, 
        String config1, String config2,
        String keystore1, String keystore2, Class... servletClasses) {
    String baseSAMLPath = "/adapter-test/keycloak-saml/";
    String webInfPath = baseSAMLPath + name + "/WEB-INF/";

    URL webXML = AbstractServletsAdapterTest.class.getResource(baseSAMLPath + webXMLPath);
    Assert.assertNotNull("web.xml should be in " + baseSAMLPath + webXMLPath, webXML);

    WebArchive deployment = ShrinkWrap.create(WebArchive.class, name + ".war")
            .addClasses(servletClasses)
            .addAsWebInfResource(jbossDeploymentStructure, JBOSS_DEPLOYMENT_STRUCTURE_XML);

    String webXMLContent;
    try {
        webXMLContent = IOUtils.toString(webXML.openStream(), Charset.forName("UTF-8"))
                .replace("%CONTEXT_PATH%", name);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    deployment.add(new StringAsset(webXMLContent), "/WEB-INF/web.xml");

    // add the xml for each tenant in classes
    URL config1Url = AbstractServletsAdapterTest.class.getResource(webInfPath + config1);
    Assert.assertNotNull("config1Url should be in " + webInfPath + config1, config1Url);
    deployment.add(new UrlAsset(config1Url), "/WEB-INF/classes/" + config1);
    URL config2Url = AbstractServletsAdapterTest.class.getResource(webInfPath + config2);
    Assert.assertNotNull("config2Url should be in " + webInfPath + config2, config2Url);
    deployment.add(new UrlAsset(config2Url), "/WEB-INF/classes/" + config2);
    
    // add the keystores for each tenant in classes
    URL keystore1Url = AbstractServletsAdapterTest.class.getResource(webInfPath + keystore1);
    Assert.assertNotNull("keystore1Url should be in " + webInfPath + keystore1, keystore1Url);
    deployment.add(new UrlAsset(keystore1Url), "/WEB-INF/classes/" + keystore1);
    URL keystore2Url = AbstractServletsAdapterTest.class.getResource(webInfPath + keystore2);
    Assert.assertNotNull("keystore2Url should be in " + webInfPath + keystore2, keystore2Url);
    deployment.add(new UrlAsset(keystore2Url), "/WEB-INF/classes/" + keystore2);

    addContextXml(deployment, name);

    return deployment;
}