On Github lance / swarm-preso
A single .jar file containing your application, the portions of WildFly required to support it, an internal Maven repository of dependencies, plus a shim to bootstrap it all.
A well-defined collection of application capabilities. May map directly to a WildFly subsystem, or bring in external capabilities such as Netflix Ribbon.
<dependency> <groupid>org.wildfly.swarm</groupid> <artifactid>wildfly-swarm-jaxrs</artifactid> <version>${swarm.version}</version> </dependency>
<plugin> <groupid>org.wildfly.swarm</groupid> <artifactid>wildfly-swarm-plugin</artifactid> <executions> <execution> <goals> <goal>package</goal> </goals> </execution> </executions> </plugin>
<!-- include the JAX-RS with CDI+JAXB Fractions --> <dependency> <groupid>org.wildfly.swarm</groupid> <artifactid>wildfly-swarm-jaxrs-weld</artifactid> <version>${version.swarm}</version> </dependency> <dependency> <groupid>org.wildfly.swarm</groupid> <artifactid>wildfly-swarm-jaxrs-jaxb</artifactid> <version>${version.swarm}</version> </dependency> <!-- Make it a Swarm App --> <plugin> <groupid>org.wildfly.swarm</groupid> <artifactid>wildfly-swarm-plugin</artifactid> <version>${version.swarm}</version> <executions> <execution> <goals> <goal>package</goal> </goals> </execution> </executions> </plugin>
$ mvn package
target/myApp-swarm.jar
$ java -jar myApp-swarm.jar
$ mvn wildfly-swarm:run
@Path("/") public class PricingResource { @GET @Path("/book/{id}") @Produces("application/json") public Integer search(@PathParam("id") String id, @Context SecurityContext context) { KeycloakPrincipal principal = (KeycloakPrincipal) context.getUserPrincipal(); if ( principal != null && principal.getKeycloakSecurityContext() != null ) { return 9; } return 10; } }
public class Main { public static void main(String... args) throws Exception { // Create a simple shrinkwrapped JAX-RS app Container container = new Container(); JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class); deployment.addPackage(Main.class.getPackage()); // Make it discoverable via Ribbon deployment.as(RibbonArchive.class).setApplicationName("pricing"); deployment.as(Secured.class); container.start(); container.deploy(deployment); } }
public class Main { public static void main(String...args) { CacheContainer webCache = new CacheContainer("web") .defaultCache("dist") .jgroupsTransport(new JGroupsTransport().lockTimeout(60000L)) .distributedCache("dist", distCache -> distCache .mode("ASYNC") .l1Lifespan(0L) .owners(2) .lockingComponent(new LockingComponent().isolation("REPEATABLE_READ")) .transactionComponent(new TransactionComponent().mode("BATCH")) .fileStore(new FileStore())); InfinispanFraction fraction = new InfinispanFraction(); fraction.cacheContainer( webCache ); Container container = new Container(); container.fraction( fraction ); // Start the container container.start(); } }
public class Main { public static void main(String[] args) throws Exception { Container container = new Container(); container.subsystem(new TransactionsFraction(4712, 4713)); container.start(); JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class); deployment.addResource(MyResource.class); container.deploy(deployment); } }
@Path("/") public class MyResource { @Path("begincommit") @GET @Produces("text/plain") public String beginCommit() throws Exception { UserTransaction txn = (UserTransaction) new InitialContext() .lookup("java:comp/UserTransaction"); String value = "Transaction "; try { txn.begin(); value += "begun ok"; try { txn.commit(); value += " and committed ok"; } catch (final Throwable ex) { value += " but failed to commit"; } } }