3

i have a JavaEE application running on Wildfly 9.0.1 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 on a certain URL, for example http://localhost:18080/picture/produit.jpg

ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176
Souu Ad
  • 41
  • 5
  • Possible duplicate of [How to configure Wildfly to serve static content (like images)?](http://stackoverflow.com/questions/22684037/how-to-configure-wildfly-to-serve-static-content-like-images) – Philippe Gonday Oct 14 '15 at 06:51

1 Answers1

2

You could add a file handler in your undertow configuration:

<subsystem xmlns="urn:jboss:domain:undertow:3.0">
        <buffer-cache name="default"/>
        <server name="default-server">
            <http-listener name="default" socket-binding="http" redirect-socket="https"/>
            <host name="default-host" alias="localhost">
                <location name="/" handler="welcome-content"/>
                <location name="/picture" handler="pictures"/>
                <filter-ref name="server-header"/>
                <filter-ref name="x-powered-by-header"/>
            </host>
        </server>
        <servlet-container name="default">
            <jsp-config/>
            <websockets/>
        </servlet-container>
        <handlers>
            <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
            <file name="pictures" path="${jboss.home.dir}/my_local_dir"/>
        </handlers>
        <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"/>
        </filters>
    </subsystem>
ehsavoie
  • 3,126
  • 1
  • 16
  • 14