Skip to content

Instantly share code, notes, and snippets.

Last active May 12, 2017
What would you like to do?
An example of using Undertow ResponseHeader filters with WildFly Swarm
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.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")
// Create a FilterRef referencing the response header's key. The
// predicate is optional to restrict the application of this filter
// to specific requests.
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()
// Modify the default host of the default server to use our FilterRef
// Tell the Container to use our customized UndertowFraction
// Your application may have different code below to finish
// configuring and booting WildFly Swarm
WARArchive war = ShrinkWrap.create(WARArchive.class);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment