Last active
May 12, 2017 17:39
-
-
Save bbrowning/4beb120ccf48ae3f7a19 to your computer and use it in GitHub Desktop.
An example of using Undertow ResponseHeader filters with WildFly Swarm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jboss.shrinkwrap.api.ShrinkWrap; | |
import org.wildfly.swarm.config.undertow.FilterConfiguration; | |
import org.wildfly.swarm.config.undertow.configuration.ResponseHeader; | |
import org.wildfly.swarm.config.undertow.server.host.FilterRef; | |
import org.wildfly.swarm.container.Container; | |
import org.wildfly.swarm.undertow.UndertowFraction; | |
import org.wildfly.swarm.undertow.WARArchive; | |
public class Main { | |
public static void main(String... args) throws Exception { | |
Container container = new Container(); | |
// Create a ResponseHeader identified by a key with the desired HTTP | |
// header name and value | |
ResponseHeader responseHeader = new ResponseHeader("foo-header") | |
.headerName("foo") | |
.headerValue("bar"); | |
// Create a FilterRef referencing the response header's key. The | |
// predicate is optional to restrict the application of this filter | |
// to specific requests. | |
// http://undertow.io/undertow-docs/undertow-docs-1.2.0/predicates-attributes-handlers.html | |
FilterRef filterRef = new FilterRef("foo-header") | |
.predicate("path-suffix['.html'] or path-prefix['/js']"); | |
// Modify the default UndertowFraction to include our ResponseHeader | |
UndertowFraction fraction = UndertowFraction.createDefaultFraction() | |
.filterConfiguration(new FilterConfiguration() | |
.responseHeader(responseHeader)); | |
// Modify the default host of the default server to use our FilterRef | |
fraction.subresources().server("default-server").subresources() | |
.host("default-host").filterRef(filterRef); | |
// Tell the Container to use our customized UndertowFraction | |
container.fraction(fraction); | |
// Your application may have different code below to finish | |
// configuring and booting WildFly Swarm | |
container.start(); | |
WARArchive war = ShrinkWrap.create(WARArchive.class); | |
war.staticContent(); | |
war.addAllDependencies(); | |
container.deploy(war); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment