Embedded Undertow in WAR stopped working for us since we upgraded to Spring Boot 1.5.2.RELEASE. I tried to make a small sample but can't reproduce it in the sample. Wonder if any expert can give me some hints from the stack trace.
The problem went away after we switched to Tomcat but we like the small foot-print of Undertow.
The POM segment used to build the WAR,
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration />
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
</dependencies>
</profile>
The exception with stack trace,
2017-05-18 15:37:49.699 ERROR 3732 --- [ XNIO-2 I/O-15] io.undertow.request : UT005071: Undertow r
equest failed HttpServerExchange{ GET /catalog-dev/api/providers request {Connection=[keep-alive], Accept=[text/html,app
lication/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8], Accept-Language=[en-US,en;q=0.8], Accept-Encoding=[gzip,
deflate, sdch], User-Agent=[Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.
0.2987.133 Safari/537.36], Upgrade-Insecure-Requests=[1], Host=[osialr-2008-vmt:8888]} response {}}
java.lang.RuntimeException: java.net.MalformedURLException: No !/ in spec 'file:M:\Source\catalog\search\server\target\c
atalog-server'
at io.undertow.servlet.handlers.ServletPathMatches.getServletHandlerByPath(ServletPathMatches.java:126)
at io.undertow.servlet.handlers.ServletInitialHandler.handleRequest(ServletInitialHandler.java:151)
at io.undertow.server.handlers.HttpContinueReadHandler.handleRequest(HttpContinueReadHandler.java:65)
at io.undertow.server.handlers.PathHandler.handleRequest(PathHandler.java:94)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:211)
at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:243)
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:134)
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:580)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:464)
Caused by: java.net.MalformedURLException: No !/ in spec 'file:M:\Source\catalog\search\server\target\catalog-server'
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at org.springframework.boot.context.embedded.undertow.JarResourceManager.getResource(JarResourceManager.java:50)
at org.springframework.boot.context.embedded.undertow.CompositeResourceManager.getResource(CompositeResourceMana
ger.java:51)
at io.undertow.servlet.handlers.ServletPathMatches.getServletHandlerByPath(ServletPathMatches.java:96)
... 16 common frames omitted
Caused by: java.lang.IllegalArgumentException: No !/ in spec 'file:M:\Source\catalog\search\server\target\catalog-server
'
at org.springframework.boot.loader.jar.Handler.getFileFromSpec(Handler.java:159)
at org.springframework.boot.loader.jar.Handler.parseURL(Handler.java:149)
... 22 common frames omitted
2017-05-18 15:38:09.312 ERROR 3732 --- [ XNIO-2 I/O-15] io.undertow.request : UT005071: Undertow r
equest failed HttpServerExchange{ GET /catalog-dev/api/groups request {Connection=[keep-alive], Accept=[text/html,applic
ation/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8], Accept-Language=[en-US,en;q=0.8], Accept-Encoding=[gzip, de
flate, sdch], User-Agent=[Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2
987.133 Safari/537.36], Upgrade-Insecure-Requests=[1], Host=[osialr-2008-vmt:8888]} response {}}
java.lang.RuntimeException: java.net.MalformedURLException: No !/ in spec 'file:M:\Source\catalog\search\server\target\c
atalog-server'
at io.undertow.servlet.handlers.ServletPathMatches.getServletHandlerByPath(ServletPathMatches.java:126)
at io.undertow.servlet.handlers.ServletInitialHandler.handleRequest(ServletInitialHandler.java:151)
at io.undertow.server.handlers.HttpContinueReadHandler.handleRequest(HttpContinueReadHandler.java:65)
at io.undertow.server.handlers.PathHandler.handleRequest(PathHandler.java:94)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:211)
at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:243)
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:134)
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:58)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:88)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:559)
Caused by: java.net.MalformedURLException: No !/ in spec 'file:M:\Source\catalog\search\server\target\catalog-server'
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at org.springframework.boot.context.embedded.undertow.JarResourceManager.getResource(JarResourceManager.java:50)
at org.springframework.boot.context.embedded.undertow.CompositeResourceManager.getResource(CompositeResourceMana
ger.java:51)
at io.undertow.servlet.handlers.ServletPathMatches.getServletHandlerByPath(ServletPathMatches.java:96)
... 11 common frames omitted
Caused by: java.lang.IllegalArgumentException: No !/ in spec 'file:M:\Source\catalog\search\server\target\catalog-server
'
at org.springframework.boot.loader.jar.Handler.getFileFromSpec(Handler.java:159)
at org.springframework.boot.loader.jar.Handler.parseURL(Handler.java:149)
... 17 common frames omitted
Versions: Spring Boot: 1.5.2.RELEASE Java: version "1.8.0_121" Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode) OS: Windows 10 64-bit
Comment From: wilkinsona
I can't tell why it's happening, but the path that's being used looks wrong to me as it's using \
rather than /
:
file:M:\Source\catalog\search\server\target\catalog-server
The logic in Undertow's ServletPathMatches
expects /
to be used. For example:
boolean pathEndsWithSlash = remaining.endsWith("/");
final String pathWithTrailingSlash = pathEndsWithSlash ? remaining : remaining + "/";
After some experimentation, I can't see how Undertow can be made to use \
rather than /
in the path, but that appears to be the cause of the problem. Without a sample that reproduces the problem, I'm not sure that we'll be able to get any closer with the diagnosis. Perhaps the above can help you to spot something in your configuration?
Comment From: zzcoder
It shouldn't use that path to start with. That's where the WAR was built. When the WAR runs from another machine, that path doesn't exist. I will track that down first. Thanks!
Comment From: wilkinsona
Great, thanks. I'm going to close this for now. If the problem persists, please comment with some more details and we can take another look.
Comment From: zzcoder
We need this feature again after several years. The problem still exists with current Spring releases. Can we re-open this ticket?
Comment From: bclozel
We can reopen this ticket if you provide a sample application that reproduces the issue with a Spring Boot version currently supported.
Comment From: zzcoder
Traced the issue to Undertow and reported the bug: https://issues.redhat.com/browse/UNDERTOW-1958
Comment From: zzcoder
I was confused. The bug is in the Undertow integration code so it's a Spring Boot's bug after all. Here is the message from Undertow team:
Spring class: https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/JarResourceManager.java#L39 contain file reference with all the quirks. This is most likely place that should handle it properly.
I attached an example, you can reproduce the error like this,
mvn package
java -jar target/test-server##1.0.war
curl "http://localhost:8080/hello"