Search in sources :

Example 1 with DeploymentContext

use of org.wildfly.swarm.container.runtime.cdi.DeploymentContext in project wildfly-swarm by wildfly-swarm.

the class ConfigurableManagerTest method testDeploymentConfigurableUsingAlias.

@Test
public void testDeploymentConfigurableUsingAlias() throws Exception {
    Properties props = new Properties();
    Map<String, String> env = new HashMap<>();
    ConfigViewFactory factory = new ConfigViewFactory(props, env);
    factory.withProperty("swarm.http.context", "/myapp");
    ConfigView configView = factory.get(true);
    DeploymentContext context = new DeploymentContextImpl();
    ConfigurableManager manager = new ConfigurableManager(configView, context);
    Archive archive = ShrinkWrap.create(JavaArchive.class, "myapp.war");
    try {
        context.activate(archive, archive.getName(), false);
        Component component = new Component();
        manager.scan(component);
        assertThat(component.context.get()).isEqualTo("/myapp");
    } finally {
        context.deactivate();
    }
}
Also used : DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) Archive(org.jboss.shrinkwrap.api.Archive) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) HashMap(java.util.HashMap) ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) ConfigViewFactory(org.wildfly.swarm.container.config.ConfigViewFactory) Properties(java.util.Properties) DeploymentContextImpl(org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl) Test(org.junit.Test)

Example 2 with DeploymentContext

use of org.wildfly.swarm.container.runtime.cdi.DeploymentContext in project wildfly-swarm by wildfly-swarm.

the class ConfigurableManagerTest method testDeploymentConfigurable.

@Test
public void testDeploymentConfigurable() throws Exception {
    Properties props = new Properties();
    Map<String, String> env = new HashMap<>();
    ConfigViewFactory factory = new ConfigViewFactory(props, env);
    factory.withProperty("swarm.deployment.[myapp.war].context", "/myapp");
    ConfigView configView = factory.get(true);
    DeploymentContext context = new DeploymentContextImpl();
    ConfigurableManager manager = new ConfigurableManager(configView, context);
    Archive archive = ShrinkWrap.create(JavaArchive.class, "myapp.war");
    try {
        context.activate(archive, archive.getName(), false);
        Component component = new Component();
        manager.scan(component);
        assertThat(component.context.get()).isEqualTo("/myapp");
    } finally {
        context.deactivate();
    }
}
Also used : DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) Archive(org.jboss.shrinkwrap.api.Archive) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) HashMap(java.util.HashMap) ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) ConfigViewFactory(org.wildfly.swarm.container.config.ConfigViewFactory) Properties(java.util.Properties) DeploymentContextImpl(org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl) Test(org.junit.Test)

Example 3 with DeploymentContext

use of org.wildfly.swarm.container.runtime.cdi.DeploymentContext in project wildfly-swarm by wildfly-swarm.

the class ServerBootstrapImpl method bootstrap.

@Override
public Server bootstrap() throws Exception {
    try (AutoCloseable bootstrap = Performance.time("Bootstrap")) {
        Module module = Module.getBootModuleLoader().loadModule("swarm.container");
        return ClassLoading.withTCCL(new ExtensionPreventionClassLoaderWrapper(module.getClassLoader()), () -> {
            try (AutoCloseable logFractionHandle = Performance.time("Log fractions")) {
                logFractions();
            }
            RuntimeServer outerServer = LogSilencer.silently("org.jboss.weld", "ServiceLoader").execute(() -> {
                Weld weld = new Weld(WELD_INSTANCE_ID);
                weld.setClassLoader(module.getClassLoader());
                ConfigViewProducingExtension configViewProducingExtension = new ConfigViewProducingExtension(this.configView);
                DeploymentContext deploymentContext = new DeploymentContextImpl();
                ConfigurableManager configurableManager = new ConfigurableManager(this.configView, deploymentContext);
                // Add Extension that adds User custom bits into configurator
                weld.addExtension(new FractionProducingExtension(explicitlyInstalledFractions, configurableManager));
                weld.addExtension(new ConfigurableExtension(configurableManager));
                weld.addExtension(new CommandLineArgsExtension(args));
                weld.addExtension(configViewProducingExtension);
                weld.addExtension(new XMLConfigProducingExtension(this.xmlConfigURL));
                weld.addExtension(new InterfaceExtension(this.configView));
                weld.addExtension(new OutboundSocketBindingExtension(this.outboundSocketBindings));
                weld.addExtension(new SocketBindingExtension(this.socketBindings));
                weld.addExtension(new DeploymentScopedExtension(deploymentContext));
                weld.addExtension(new ImplicitArchiveExtension());
                for (Class<?> each : this.userComponents) {
                    weld.addBeanClass(each);
                }
                weld.property("org.jboss.weld.se.shutdownHook", false);
                WeldContainer weldContainer = null;
                RuntimeServer server = null;
                try (AutoCloseable weldRelated = Performance.time("Weld-related")) {
                    try (AutoCloseable weldInitHandle = Performance.time("Weld initialize")) {
                        weldContainer = weld.initialize();
                    }
                    try (AutoCloseable serverSelectHandle = Performance.time("Server construction")) {
                        server = weldContainer.select(RuntimeServer.class).get();
                    }
                }
                return server;
            });
            try (AutoCloseable weldInitHandle = Performance.time("Server start")) {
                outerServer.start(true);
            }
            return outerServer;
        });
    } finally {
        SwarmMetricsMessages.MESSAGES.bootPerformance(Performance.dump());
    }
}
Also used : InterfaceExtension(org.wildfly.swarm.container.runtime.cdi.InterfaceExtension) OutboundSocketBindingExtension(org.wildfly.swarm.container.runtime.cdi.OutboundSocketBindingExtension) FractionProducingExtension(org.wildfly.swarm.container.runtime.cdi.FractionProducingExtension) WeldContainer(org.jboss.weld.environment.se.WeldContainer) ConfigViewProducingExtension(org.wildfly.swarm.container.runtime.cdi.ConfigViewProducingExtension) Weld(org.jboss.weld.environment.se.Weld) DeploymentContextImpl(org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl) DeploymentScopedExtension(org.wildfly.swarm.container.runtime.cdi.DeploymentScopedExtension) DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) XMLConfigProducingExtension(org.wildfly.swarm.container.runtime.cdi.XMLConfigProducingExtension) ImplicitArchiveExtension(org.wildfly.swarm.container.runtime.cdi.ImplicitArchiveExtension) CommandLineArgsExtension(org.wildfly.swarm.container.runtime.cli.CommandLineArgsExtension) ConfigurableExtension(org.wildfly.swarm.container.runtime.cdi.configurable.ConfigurableExtension) Module(org.jboss.modules.Module) OutboundSocketBindingExtension(org.wildfly.swarm.container.runtime.cdi.OutboundSocketBindingExtension) SocketBindingExtension(org.wildfly.swarm.container.runtime.cdi.SocketBindingExtension)

Example 4 with DeploymentContext

use of org.wildfly.swarm.container.runtime.cdi.DeploymentContext in project wildfly-swarm by wildfly-swarm.

the class ConfigurableManagerTest method testDeploymentConfigurableUsingBoth.

@Test
public void testDeploymentConfigurableUsingBoth() throws Exception {
    Properties props = new Properties();
    Map<String, String> env = new HashMap<>();
    ConfigViewFactory factory = new ConfigViewFactory(props, env);
    factory.withProperty("swarm.deployment.[myapp.war].context", "/my-specific-app");
    factory.withProperty("swarm.http.context", "/my-alias-app");
    ConfigView configView = factory.get(true);
    DeploymentContext context = new DeploymentContextImpl();
    ConfigurableManager manager = new ConfigurableManager(configView, context);
    Archive archive = ShrinkWrap.create(JavaArchive.class, "myapp.war");
    try {
        context.activate(archive, archive.getName(), false);
        Component component = new Component();
        manager.scan(component);
        assertThat(component.context.get()).isEqualTo("/my-specific-app");
    } finally {
        context.deactivate();
    }
    Archive archiveToo = ShrinkWrap.create(JavaArchive.class, "otherapp.war");
    try {
        context.activate(archiveToo, archiveToo.getName(), false);
        Component component = new Component();
        manager.scan(component);
        assertThat(component.context.get()).isEqualTo("/my-alias-app");
    } finally {
        context.deactivate();
    }
}
Also used : DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) Archive(org.jboss.shrinkwrap.api.Archive) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) HashMap(java.util.HashMap) ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) ConfigViewFactory(org.wildfly.swarm.container.config.ConfigViewFactory) Properties(java.util.Properties) DeploymentContextImpl(org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl) Test(org.junit.Test)

Aggregations

DeploymentContext (org.wildfly.swarm.container.runtime.cdi.DeploymentContext)4 DeploymentContextImpl (org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl)4 HashMap (java.util.HashMap)3 Properties (java.util.Properties)3 Archive (org.jboss.shrinkwrap.api.Archive)3 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)3 Test (org.junit.Test)3 ConfigViewFactory (org.wildfly.swarm.container.config.ConfigViewFactory)3 ConfigView (org.wildfly.swarm.spi.api.config.ConfigView)3 Module (org.jboss.modules.Module)1 Weld (org.jboss.weld.environment.se.Weld)1 WeldContainer (org.jboss.weld.environment.se.WeldContainer)1 ConfigViewProducingExtension (org.wildfly.swarm.container.runtime.cdi.ConfigViewProducingExtension)1 DeploymentScopedExtension (org.wildfly.swarm.container.runtime.cdi.DeploymentScopedExtension)1 FractionProducingExtension (org.wildfly.swarm.container.runtime.cdi.FractionProducingExtension)1 ImplicitArchiveExtension (org.wildfly.swarm.container.runtime.cdi.ImplicitArchiveExtension)1 InterfaceExtension (org.wildfly.swarm.container.runtime.cdi.InterfaceExtension)1 OutboundSocketBindingExtension (org.wildfly.swarm.container.runtime.cdi.OutboundSocketBindingExtension)1 SocketBindingExtension (org.wildfly.swarm.container.runtime.cdi.SocketBindingExtension)1 XMLConfigProducingExtension (org.wildfly.swarm.container.runtime.cdi.XMLConfigProducingExtension)1