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;
}
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>");
}
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");
}
}
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();
}
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");
}
}
Aggregations