org.wildfly.swarm.Swarm Java Examples
The following examples show how to use
org.wildfly.swarm.Swarm.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeploymentFailureTest.java From thorntail with Apache License 2.0 | 6 votes |
@Test public void testDeploymentFailure() throws Exception { Swarm swarm = new Swarm(); swarm.start(); JARArchive a = ShrinkWrap.create(JARArchive.class, "bad-deployment.jar"); a.addModule("com.i.do.no.exist"); try { swarm.deploy(a); fail("should have throw a DeploymentException"); } catch (DeploymentException e) { // expected and correct assertThat(e.getArchive()).isSameAs(a); assertThat(e.getMessage()).contains("org.jboss.modules.ModuleNotFoundException: com.i.do.no.exist"); } finally { swarm.stop(); } }
Example #2
Source File: SwaggerWebAppConfiguration.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
@Override public List<Archive> getImplicitDeployments(SwaggerWebAppFraction fraction) throws Exception { List<Archive> list = new ArrayList<>(); try { // Get the swagger-ui bits as an Archive WARArchive war = Swarm.artifact("org.wildfly.swarm:swagger-webapp-ui:war:" + Container.VERSION, "swagger-webapp-ui.war") .as(WARArchive.class) .setContextRoot(fraction.getContext()); // If any user content has been provided, merge that with the swagger-ui bits Archive<?> userContent = fraction.getWebContent(); if (userContent != null) { war.merge(userContent); } //war.as(ZipExporter.class).exportTo(new File("swagger-webapp-ui.war"), true); list.add(war); } catch (Exception e) { e.printStackTrace(); } return list; }
Example #3
Source File: ZipkinJAXRSTest.java From thorntail with Apache License 2.0 | 6 votes |
@CreateSwarm public static Swarm newContainer() throws Exception { System.out.println("Log file: " + LOG_FILE); return new Swarm() .fraction( new LoggingFraction() .defaultColorFormatter() .consoleHandler(Level.INFO, "COLOR_PATTERN") .fileHandler("FILE", f -> { Map<String, String> fileProps = new HashMap<>(); fileProps.put("path", LOG_FILE); f.file(fileProps); f.level(Level.INFO); f.formatter("%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"); }) .rootLogger(Level.INFO, "CONSOLE", "FILE") ); }
Example #4
Source File: CommandLineTest.java From thorntail with Apache License 2.0 | 6 votes |
@Test public void testApplyPropertiesWithPropertiesHierarchy() throws Exception { // Given URL props = getClass().getClassLoader().getResource("hierarchy.properties"); CommandLine cmd = CommandLine.parse("--properties", props.toExternalForm()); Swarm swarm = mock(Swarm.class); // When cmd.applyProperties(swarm); // Then verify(swarm).withProperty("parent.children", "child1,child2"); verify(swarm).withProperty("parent.children.child1.name", "Jack"); verify(swarm).withProperty("parent.children.child2.name", "Jill"); verifyNoMoreInteractions(swarm); }
Example #5
Source File: CommandLine.java From thorntail with Apache License 2.0 | 6 votes |
/** * Apply properties and configuration from the parsed commandline to a container. * * @param swarm The Swarm instance to apply configuration to. * @throws IOException If an error occurs resolving any URL. */ public void apply(Swarm swarm) throws IOException, ModuleLoadException { applyProperties(swarm); applyConfigurations(swarm); if (get(HELP)) { displayVersion(System.err); System.err.println(); displayHelp(System.err); System.exit(0); } if (get(CONFIG_HELP) != null) { displayConfigHelp(System.err, get(CONFIG_HELP)); System.exit(0); } if (get(YAML_HELP) != null) { dumpYaml(System.err, get(YAML_HELP)); System.exit(0); } if (get(VERSION)) { displayVersion(System.err); } }
Example #6
Source File: Main.java From thorntail with Apache License 2.0 | 6 votes |
public static void main(String... args) throws Exception { swarm = new Swarm(args); swarm.fraction( new DatasourcesFraction() .jdbcDriver("h2", (d) -> { d.driverClassName("org.h2.Driver"); d.xaDatasourceClass("org.h2.jdbcx.JdbcDataSource"); d.driverModuleName("com.h2database.h2"); }) .dataSource("ExampleDS", (ds) -> { ds.driverName("h2"); ds.connectionUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"); ds.userName("sa"); ds.password("sa"); }) ); swarm.start().deploy(); }
Example #7
Source File: Main.java From thorntail with Apache License 2.0 | 6 votes |
public static void main(String... args) throws Exception { swarm = new Swarm(args); swarm.start(); Archive<?> deployment = swarm.createDefaultDeployment(); if (deployment == null) { throw new Error("Couldn't create default deployment"); } Node persistenceXml = deployment.get("WEB-INF/classes/META-INF/persistence.xml"); if (persistenceXml == null) { throw new Error("persistence.xml is not found"); } if (persistenceXml.getAsset() == null) { throw new Error("persistence.xml is not found"); } swarm.deploy(deployment); }
Example #8
Source File: CommandLine.java From thorntail with Apache License 2.0 | 6 votes |
/** * Apply configuration to the container. * * <p>Applies configuration from <code>Key.SERVER_CONFIG</code> and <code>Key.STAGE_CONFIG</code>.</p> * * @param swarm Swarm instance to configure. * @throws MalformedURLException If a URL is attempted to be read and fails. */ public void applyConfigurations(Swarm swarm) throws IOException { if (get(SERVER_CONFIG) != null) { swarm.withXmlConfig(get(SERVER_CONFIG)); } if (get(CONFIG) != null) { List<URL> configs = get(CONFIG); for (URL config : configs) { swarm.withConfig(config); } } if (get(PROFILES) != null) { List<String> profiles = get(PROFILES); for (String profile : profiles) { swarm.withProfile(profile); } } }
Example #9
Source File: SWARM553Test.java From thorntail with Apache License 2.0 | 6 votes |
@CreateSwarm public static Swarm newContainer() throws Exception { return new Swarm() .fraction( new LoggingFraction().periodicSizeRotatingFileHandler("FILE", (h) -> { h.level(Level.INFO) .append(true) .suffix(".yyyy-MM-dd") .rotateSize("30m") .enabled(true) .encoding("UTF-8") .maxBackupIndex(2); Map<String, String> fileSpec = new HashMap<>(); fileSpec.put("path", logFile); h.file(fileSpec); }).logger("br.org.sistemafieg.cliente", (l) -> { l.level(Level.INFO) .handler("FILE"); })); }
Example #10
Source File: AnnotationBasedMain.java From thorntail with Apache License 2.0 | 6 votes |
public static void main(String... args) throws Exception { if (System.getProperty("boot.module.loader") == null) { System.setProperty("boot.module.loader", "org.wildfly.swarm.bootstrap.modules.BootModuleLoader"); } String clsName = System.getProperty(ANNOTATED_CLASS_NAME); Class<?> cls = Class.forName(clsName); Method[] methods = cls.getMethods(); for (Method method : methods) { if (!Modifier.isStatic(method.getModifiers())) { continue; } CreateSwarm anno = method.getAnnotation(CreateSwarm.class); if (anno == null) { continue; } boolean startEagerly = anno.startEagerly(); ((Swarm) method.invoke(null)).start().deploy(); } }
Example #11
Source File: AbstractServerConfiguration.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
Archive<?> toArchive(T fraction) throws Exception { Archive<?> archive; if (this.asName == null) { archive = Swarm.artifact(this.gav); } else { archive = Swarm.artifact(this.gav, asName); } if (this.config != null) { this.config.accept(fraction, archive); } return archive; }
Example #12
Source File: Main.java From hola with Apache License 2.0 | 5 votes |
/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // Instantiate the container Swarm swarm = new Swarm(args); // Create one or more deployments WARArchive deployment = ShrinkWrap.create(WARArchive.class); // Add resource to deployment deployment.addPackage(Main.class.getPackage()); deployment.addAllDependencies(); // Add Web resources deployment.addAsWebResource( new ClassLoaderAsset("index.html", Main.class.getClassLoader()), "index.html"); deployment.addAsWebInfResource( new ClassLoaderAsset("WEB-INF/web.xml", Main.class.getClassLoader()), "web.xml"); deployment.addAsWebInfResource( new ClassLoaderAsset("WEB-INF/beans.xml", Main.class.getClassLoader()), "beans.xml"); // If There's a KEYCLOAK_SERVER_URL env var, then read the file if (System.getenv("KEYCLOAK_AUTH_SERVER_URL") != null) { deployment.addAsWebInfResource( new ClassLoaderAsset("keycloak.json", Main.class.getClassLoader()), "keycloak.json"); } swarm.start().deploy(deployment); }
Example #13
Source File: ArtifactDeployer.java From thorntail with Apache License 2.0 | 5 votes |
public void deploy() throws Exception { List<SimpleKey> subkeys = configView.simpleSubkeys(ConfigKey.of("thorntail", "deployment")); for (SimpleKey subkey : subkeys) { String spec = subkey.name(); if (!spec.contains(":")) { // TODO Should we really silently ignore this? Rather warn the user about a problem in his config? continue; } String[] parts = spec.split(":"); String groupId = parts[0]; int p = parts[1].lastIndexOf('.'); String artifactId; String packaging; if (p == -1) { artifactId = parts[1]; packaging = "jar"; } else { artifactId = parts[1].substring(0, p); packaging = parts[1].substring(p + 1); } JavaArchive artifact = Swarm.artifact(groupId + ":" + artifactId + ":" + packaging + ":*", artifactId + "." + packaging); deployer.get().deploy(artifact, spec); } }
Example #14
Source File: JolokiaSecuredTest.java From thorntail with Apache License 2.0 | 5 votes |
@CreateSwarm public static Swarm createSwarm() throws Exception { Swarm swarm = new Swarm() .fraction(new JolokiaFraction() .prepareJolokiaWar(JolokiaFraction.jolokiaAccess(access -> { // allow nobody, basically access.host("1.1.1.1"); })) ); return swarm; }
Example #15
Source File: MainWithProperties.java From thorntail with Apache License 2.0 | 5 votes |
public static void main(String... args) throws Exception { System.setProperty("thorntail.logging", "TRACE"); System.setProperty("thorntail.logging.custom.category", "DEBUG"); System.setProperty("thorntail.logging.pattern-formatters.MY_COLOR_PATTERN.pattern", "%K{level}%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p (%t) [%c.%M()] %s%e%n"); swarm = new Swarm(args); swarm.start().deploy(); }
Example #16
Source File: KeycloakArquillianTest.java From thorntail with Apache License 2.0 | 5 votes |
@CreateSwarm public static Swarm newContainer() throws Exception { URL migrationRealmUrl = KeycloakArquillianTest.class.getResource("/wildfly-swarm-keycloak-example-realm.json"); System.setProperty("keycloak.migration.file", migrationRealmUrl.toURI().getPath()); System.setProperty("keycloak.migration.provider", "singleFile"); System.setProperty("keycloak.migration.action", "import"); return new Swarm(); }
Example #17
Source File: KeycloakMultitenancyTest.java From thorntail with Apache License 2.0 | 5 votes |
@CreateSwarm public static Swarm newContainer() throws Exception { URL migrationRealmUrl = KeycloakMultitenancyTest.class.getResource("/wildfly-swarm-keycloak-example-realm.json"); System.setProperty("keycloak.migration.file", migrationRealmUrl.toURI().getPath()); System.setProperty("keycloak.migration.provider", "singleFile"); System.setProperty("keycloak.migration.action", "import"); return new Swarm(); }
Example #18
Source File: Main.java From thorntail with Apache License 2.0 | 5 votes |
public static void main(String... args) throws Exception { swarm = new Swarm(args); swarm.start(); JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "myapp.war"); deployment.addClass(MyResource.class); deployment.setContextRoot("rest"); deployment.addAllDependencies(); swarm.deploy(deployment); }
Example #19
Source File: DeploymentSuccessTest.java From thorntail with Apache License 2.0 | 5 votes |
@Test public void testDeploymentSuccess() throws Exception { Swarm swarm = new Swarm(); swarm.start(); JARArchive a = ShrinkWrap.create(JARArchive.class, "good-deployment.jar"); a.add(EmptyAsset.INSTANCE, "nothing.xml"); swarm.deploy(a); swarm.stop(); }
Example #20
Source File: ClassLoaderConfigLocator.java From thorntail with Apache License 2.0 | 4 votes |
public static ClassLoaderConfigLocator forApplication() throws ModuleLoadException { Module appModule = Module.getBootModuleLoader().loadModule(Swarm.APPLICATION_MODULE_NAME); return new ClassLoaderConfigLocator(appModule.getClassLoader()); }
Example #21
Source File: DependenciesContainer.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") default T addAllDependencies() throws Exception { List<JavaArchive> artifacts = Swarm.allArtifacts(); addAsLibraries(artifacts); return (T) this; }