Search in sources :

Example 6 with Node

use of org.jboss.shrinkwrap.api.Node in project wildfly-swarm by wildfly-swarm.

the class SecuredArchivePreparer method getKeycloakJson.

private InputStream getKeycloakJson() {
    InputStream keycloakJson = Thread.currentThread().getContextClassLoader().getResourceAsStream("keycloak.json");
    if (keycloakJson == null) {
        String appArtifact = System.getProperty(BootstrapProperties.APP_ARTIFACT);
        if (appArtifact != null) {
            try (InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream("_bootstrap/" + appArtifact)) {
                Archive tmpArchive = ShrinkWrap.create(JARArchive.class);
                tmpArchive.as(ZipImporter.class).importFrom(in);
                Node jsonNode = tmpArchive.get("keycloak.json");
                if (jsonNode == null) {
                    jsonNode = tmpArchive.get("WEB-INF/keycloak.json");
                }
                if (jsonNode != null && jsonNode.getAsset() != null) {
                    keycloakJson = jsonNode.getAsset().openStream();
                }
            } catch (IOException e) {
            // ignore
            }
        }
    }
    return keycloakJson;
}
Also used : JARArchive(org.wildfly.swarm.spi.api.JARArchive) Archive(org.jboss.shrinkwrap.api.Archive) InputStream(java.io.InputStream) ZipImporter(org.jboss.shrinkwrap.api.importer.ZipImporter) Node(org.jboss.shrinkwrap.api.Node) IOException(java.io.IOException)

Example 7 with Node

use of org.jboss.shrinkwrap.api.Node in project wildfly-swarm by wildfly-swarm.

the class SecuredTest method testExistingWebXml.

@Test
public void testExistingWebXml() {
    WARArchive archive = ShrinkWrap.create(WARArchive.class);
    ClassLoaderAsset asset = new ClassLoaderAsset("test-web.xml");
    archive.addAsWebInfResource(asset, "web.xml");
    archive.as(Secured.class).protect("/cheddar");
    Node webXml = archive.get("WEB-INF/web.xml");
    Asset newAsset = webXml.getAsset();
    InputStream in = newAsset.openStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    List<String> lines = reader.lines().map(String::trim).collect(Collectors.toList());
    assertThat(lines).contains("<servlet-name>comingsoon</servlet-name>");
    assertThat(lines).contains("<url-pattern>/cheddar</url-pattern>");
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Node(org.jboss.shrinkwrap.api.Node) BufferedReader(java.io.BufferedReader) ClassLoaderAsset(org.jboss.shrinkwrap.api.asset.ClassLoaderAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset) ClassLoaderAsset(org.jboss.shrinkwrap.api.asset.ClassLoaderAsset) WARArchive(org.wildfly.swarm.undertow.WARArchive) Test(org.junit.Test)

Example 8 with Node

use of org.jboss.shrinkwrap.api.Node in project wildfly-swarm by wildfly-swarm.

the class JolokiaWarDeploymentProducerTest method testPreferConfigValueURL_vs_API.

@Test
public void testPreferConfigValueURL_vs_API() throws Exception {
    URL resource = getClass().getClassLoader().getResource("my-jolokia-access2.xml");
    JolokiaWarDeploymentProducer producer = new JolokiaWarDeploymentProducer();
    producer.fraction = new JolokiaFraction().prepareJolokiaWar(JolokiaFraction.jolokiaAccess(access -> {
        access.host("1.1.1.1");
    }));
    producer.lookup = new MockArtifactLookup();
    producer.jolokiaAccessXML = resource.toExternalForm();
    Archive war = producer.jolokiaWar();
    Node xml = war.get("WEB-INF/classes/jolokia-access.xml");
    assertThat(xml).isNotNull();
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(xml.getAsset().openStream()))) {
        List<String> lines = reader.lines().collect(Collectors.toList());
        assertThat(lines).isNotEmpty();
        assertThat(lines.get(0)).contains("This is my-jolokia-access2.xml");
    }
}
Also used : Archive(org.jboss.shrinkwrap.api.Archive) InputStreamReader(java.io.InputStreamReader) Node(org.jboss.shrinkwrap.api.Node) BufferedReader(java.io.BufferedReader) JolokiaFraction(org.wildfly.swarm.jolokia.JolokiaFraction) URL(java.net.URL) Test(org.junit.Test)

Example 9 with Node

use of org.jboss.shrinkwrap.api.Node in project wildfly-swarm by wildfly-swarm.

the class JolokiaWarDeploymentProducerTest method testNoJolokiaAccessAtAll.

@Test
public void testNoJolokiaAccessAtAll() throws Exception {
    JolokiaWarDeploymentProducer producer = new JolokiaWarDeploymentProducer();
    producer.fraction = new JolokiaFraction();
    producer.lookup = new MockArtifactLookup();
    Archive war = producer.jolokiaWar();
    Node xml = war.get("WEB-INF/classes/jolokia-access.xml");
    assertThat(xml).isNull();
}
Also used : Archive(org.jboss.shrinkwrap.api.Archive) Node(org.jboss.shrinkwrap.api.Node) JolokiaFraction(org.wildfly.swarm.jolokia.JolokiaFraction) Test(org.junit.Test)

Example 10 with Node

use of org.jboss.shrinkwrap.api.Node in project wildfly-swarm by wildfly-swarm.

the class JolokiaWarDeploymentProducerTest method testJolokiaAccessViaUrlOnFraction.

@Test
public void testJolokiaAccessViaUrlOnFraction() throws Exception {
    URL resource = getClass().getClassLoader().getResource("my-jolokia-access.xml");
    JolokiaWarDeploymentProducer producer = new JolokiaWarDeploymentProducer();
    producer.fraction = new JolokiaFraction().prepareJolokiaWar(JolokiaFraction.jolokiaAccessXml(resource));
    producer.lookup = new MockArtifactLookup();
    Archive war = producer.jolokiaWar();
    Node xml = war.get("WEB-INF/classes/jolokia-access.xml");
    assertThat(xml).isNotNull();
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(xml.getAsset().openStream()))) {
        List<String> lines = reader.lines().collect(Collectors.toList());
        assertThat(lines).isNotEmpty();
        assertThat(lines.get(0)).contains("This is my-jolokia-access.xml");
    }
}
Also used : Archive(org.jboss.shrinkwrap.api.Archive) InputStreamReader(java.io.InputStreamReader) Node(org.jboss.shrinkwrap.api.Node) BufferedReader(java.io.BufferedReader) JolokiaFraction(org.wildfly.swarm.jolokia.JolokiaFraction) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Node (org.jboss.shrinkwrap.api.Node)66 Archive (org.jboss.shrinkwrap.api.Archive)20 ArchivePath (org.jboss.shrinkwrap.api.ArchivePath)20 IOException (java.io.IOException)19 Test (org.junit.Test)17 Asset (org.jboss.shrinkwrap.api.asset.Asset)16 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)15 File (java.io.File)14 Map (java.util.Map)14 InputStream (java.io.InputStream)13 URL (java.net.URL)13 BufferedReader (java.io.BufferedReader)10 InputStreamReader (java.io.InputStreamReader)10 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)8 JolokiaFraction (org.wildfly.swarm.jolokia.JolokiaFraction)8 ArrayList (java.util.ArrayList)7 ArchiveAsset (org.jboss.shrinkwrap.api.asset.ArchiveAsset)7 OpenEJBException (org.apache.openejb.OpenEJBException)6 ClassAsset (org.jboss.shrinkwrap.api.asset.ClassAsset)6 MalformedURLException (java.net.MalformedURLException)5