use of org.jboss.shrinkwrap.api.Archive 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.Archive 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.Archive 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.Archive 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");
}
}
use of org.jboss.shrinkwrap.api.Archive in project wildfly-swarm by wildfly-swarm.
the class StaticContentContainer method staticContent.
/**
* Enable static content to be served from a given base in the classpath.
*
* @param base The path prefix to use for static content.
* @return
*/
@SuppressWarnings("unchecked")
default T staticContent(String base) {
try {
// Add all the static content from the current app to the archive
Archive allResources = DefaultWarDeploymentFactory.archiveFromCurrentApp();
// Here we define static as basically anything that's not a
// Java class file or under WEB-INF or META-INF
mergeIgnoringDuplicates(allResources, base, Filters.exclude(".*\\.class$"));
} catch (Exception ex) {
log.log(Level.WARNING, "Error setting up static resources", ex);
}
Node node = get(EXTERNAL_MOUNT_PATH);
UndertowExternalMountsAsset asset;
if (node == null) {
asset = new UndertowExternalMountsAsset();
add(asset, EXTERNAL_MOUNT_PATH);
} else {
Asset tempAsset = node.getAsset();
if (!(tempAsset instanceof UndertowExternalMountsAsset)) {
asset = new UndertowExternalMountsAsset(tempAsset.openStream());
add(asset, EXTERNAL_MOUNT_PATH);
} else {
asset = (UndertowExternalMountsAsset) node.getAsset();
}
}
// Add external mounts for static content so changes are picked up
// immediately during development
Path webResources = Paths.get(System.getProperty("user.dir"), "src", "main", "webapp");
if (base != null) {
webResources = webResources.resolve(base);
}
if (Files.exists(webResources)) {
asset.externalMount(webResources.toString());
}
webResources = Paths.get(System.getProperty("user.dir"), "src", "main", "resources");
if (base != null) {
webResources = webResources.resolve(base);
}
if (Files.exists(webResources)) {
asset.externalMount(webResources.toString());
}
return (T) this;
}
Aggregations