I have a JavaEE application running on Wildfly 8.0.0 Final.
The application uses a lot of images and I don't want to store them in the database, so they are written to the hard disk.
How can I configure Wildfly/Undertow in order to serve these files (/var/images) on a certain URL, for example http://localhost:8080/myapplication/imagesFromDisk
?
In case you don't want to, or can't, configure the Undertow subsystem in
standalone.xml
, then you need to make it work within the.war
. For that, you may use a servlet to serve the files. There are few implementations around, the most famous (or highest on Google) is by BalusC. That one is licensed under LGPL, though. So I took theDefaultServlet
and made it more easily extensible, so you can feed it the right UndertowResource
, e.g. from a file system.Theoretically, some servlet in Undertow should be able to serve from a filesystem, too, but the
DefaultServlet
code seems to only count with resources within a deployment.Base class:
The file serving servlet (the one you will use in
web.xml
):And here's a servlet which works like the previous
DefaultServlet
- that is, serving from the deployment.Add another file handler and another location to the undertow subsystem in standalone.xml: