Undertow custom filter with "module=deployment.foo.war"
juraci.costa Aug 29, 2016 4:49 AMHello,
I'm trying to have an Undertow filter on Wildfly located inside a deployment, so that I can use Java EE goodies from within this filter. As per the class-loading documentation, I'd be able to reference a deployment "foo.war" by the module name "deployment.foo.war" . Turns out, it's not that simple I tried adding "deployment.proxy.war" to the filter configuration, but I get a "ModuleNotFoundException: deployment.proxy.war:main". Debugging it, it seems that the org.jboss.modules.LocalModuleFinder is used and its findModule(ModuleIdentifier, ModuleLoader) attempts to lookup the module from "deployment/proxy/war/main/" on both repo roots (WF_HOME/modules and WF_HOME/modules/system/layers/base) and it obviously won't find it there.
Just "for fun", I tried deploying the WAR in different ways, including by adding a "deployments/deployment[name=proxy.war, runtime-name=proxy.war]" to standalone.xml , with no luck. I do see that the deployment is successful though, and there are no errors during the boot of the server:
10:37:35,870 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0027: Starting deployment of "proxy.war" (runtime-name: "proxy.war") 10:37:40,921 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0010: Deployed "proxy.war" (runtime-name : "proxy.war") 10:37:41,054 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.1.0.CR1 (WildFly Core 2.2.0.CR9) started in 9566ms - Started 429 of 678 services (407 services are lazy, passive or on-demand)
The filter is configured like this:
<host name="default-host" alias="localhost"> <location name="/" handler="my-proxy"/> <filter-ref name="server-header"/> <filter-ref name="x-powered-by-header"/> <filter-ref name="my-filter"/> </host> <filters> <response-header name="server-header" header-name="Server" header-value="WildFly/10"/> <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/> <filter name="my-filter" class-name="org.foo.proxy.boundary.MyManagedFilter" module="deployment.proxy.war"/> </filters>
And this is the full exception:
10:38:17,216 ERROR [io.undertow.request] (default I/O-3) UT005071: Undertow request failed HttpServerExchange{ GET /example/v1/foo request {Accept=[*/*], User-Agent=[curl/7.47.1], Host=[localhost:8180]} response {}}: java.lang.RuntimeException: WFLYUT0070: Could not load handler org.foo.proxy.boundary.MyManagedFilter from deployment.proxy.war module at org.wildfly.extension.undertow.filters.CustomFilterDefinition.getHandlerClass(CustomFilterDefinition.java:115) at org.wildfly.extension.undertow.filters.CustomFilterDefinition.createHttpHandler(CustomFilterDefinition.java:95) at org.wildfly.extension.undertow.filters.FilterService.createHttpHandler(FilterService.java:57) at org.wildfly.extension.undertow.filters.FilterRef.createHttpHandler(FilterRef.java:69) at org.wildfly.extension.undertow.LocationService.configureHandlerChain(LocationService.java:104) at org.wildfly.extension.undertow.Host.configureRootHandler(Host.java:119) at org.wildfly.extension.undertow.Host.getOrCreateRootHandler(Host.java:173) at org.wildfly.extension.undertow.Host$HostRootHandler.handleRequest(Host.java:303) at io.undertow.server.handlers.NameVirtualHostHandler.handleRequest(NameVirtualHostHandler.java:54) at io.undertow.server.handlers.error.SimpleErrorPageHandler.handleRequest(SimpleErrorPageHandler.java:78) at io.undertow.server.handlers.CanonicalPathHandler.handleRequest(CanonicalPathHandler.java:49) at io.undertow.server.handlers.ChannelUpgradeHandler.handleRequest(ChannelUpgradeHandler.java:158) at io.undertow.server.protocol.http2.Http2UpgradeHandler.handleRequest(Http2UpgradeHandler.java:95) at io.undertow.server.handlers.DisallowedMethodsHandler.handleRequest(DisallowedMethodsHandler.java:61) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202) at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:233) at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:131) at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:148) at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:92) at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:51) at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92) at org.xnio.ChannelListeners$10.handleEvent(ChannelListeners.java:291) at org.xnio.ChannelListeners$10.handleEvent(ChannelListeners.java:286) at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92) at org.xnio.nio.QueuedNioTcpServer$1.run(QueuedNioTcpServer.java:128) at org.xnio.nio.WorkerThread.safeRun(WorkerThread.java:588) at org.xnio.nio.WorkerThread.run(WorkerThread.java:468) Caused by: org.jboss.modules.ModuleNotFoundException: deployment.proxy.war:main at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:223) at org.wildfly.extension.undertow.filters.CustomFilterDefinition.getHandlerClass(CustomFilterDefinition.java:112) ... 26 more
So, the question is: is it possible to have an Undertow filter on Wildfly deployed not as a "regular" module, but as a deployment instead?
Class Loading in WildFly - WildFly 10 - Project Documentation Editor