use of org.wildfly.swarm.undertow.internal.UndertowExternalMountsAsset in project wildfly-swarm by wildfly-swarm.
the class ContextPathArchivePreparerTest method testExternalMount.
@SuppressWarnings("unchecked")
@Test
public void testExternalMount() throws Exception {
WARArchive archive = DefaultWarDeploymentFactory.archiveFromCurrentApp();
assertThat(archive.getContextRoot()).isNull();
URL url = getClass().getClassLoader().getResource("mounts.yml");
ConfigViewFactory factory = new ConfigViewFactory(new Properties());
factory.load("test", url);
factory.withProfile("test");
ConfigViewImpl view = factory.get(true);
List<String> mounts = view.resolve("swarm.context.mounts").as(List.class).getValue();
ContextPathArchivePreparer preparer = new ContextPathArchivePreparer(archive);
preparer.mounts = mounts;
preparer.process();
Node externalMount = archive.get(WARArchive.EXTERNAL_MOUNT_PATH);
assertThat(externalMount).isNotNull();
assertThat(externalMount.getAsset()).isInstanceOf(UndertowExternalMountsAsset.class);
UndertowExternalMountsAsset externalMountAsset = (UndertowExternalMountsAsset) externalMount.getAsset();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(externalMountAsset.openStream()))) {
assertThat(reader.readLine()).endsWith("external1");
assertThat(reader.readLine()).endsWith("external2");
}
}
use of org.wildfly.swarm.undertow.internal.UndertowExternalMountsAsset 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;
}
use of org.wildfly.swarm.undertow.internal.UndertowExternalMountsAsset in project wildfly-swarm by wildfly-swarm.
the class ContextPathArchivePreparer method process.
@Override
public void process() {
WARArchive warArchive = archive.as(WARArchive.class);
if (warArchive.getContextRoot() == null) {
warArchive.setContextRoot(contextPath.get());
}
UndertowExternalMountsAsset ut = null;
if (mounts != null) {
for (String mountPath : mounts) {
Path staticPath = Paths.get(mountPath);
if (!staticPath.isAbsolute()) {
staticPath = Paths.get(System.getProperty("user.dir"), staticPath.toString()).normalize();
}
if (ut == null) {
ut = new UndertowExternalMountsAsset();
}
ut.externalMount(staticPath.toString());
}
}
if (ut != null) {
warArchive.add(ut, WARArchive.EXTERNAL_MOUNT_PATH);
}
}
Aggregations