Search code examples
httpdownloadwildflywildfly-9

Access file using HTTP from Wildfly server


I am facing an issue related to file access over HTTP in Wildfly(JBoss). I am running an application on Wildlfy-9.0.1.Final

In my application there is a link on click, it supposed to open respective file and display its content. But when I click on link it gives me 404-Not found error.

I could see that file exist on same path as given in href in anchor tag. I don't understand what it makes to give 404 Error.

Is there any other settings that I need to enabled in Wildfly to access files over HTTP. If so, please advice.

EDIT:

My path in <handlers> looks like this

path="/usr/local/jboss/server/default/deploy/"

This directory structure is not yet complete as there will be more path appended dynamically at run-time using java code where actual file will reside.

For ex: path="/usr/local/jboss/server/default/deploy/demo/1/filename"

of which /usr/local/jboss/server/default/deploy/ is static path and demo/1/filename is dynamic.

Also in /directory-listing-uri in location some path is dynamic generated at tun time.

For ex: Assume below is directory-listing-uri

http://[wildfly host]:[port]/{static}/{dynamic}/{dynamic}/{dynamicFileName}.iif

So I am not sure how wildfly will serve my purpose of displaying files.

Please correct if I am incorrect.


Solution

  • To expose a directory for file listing (and download), you could add two configuration elements in your standalone.xml configuration (if you run wildfly as standalone server) like this:

    <subsystem xmlns="urn:jboss:domain:undertow:2.0">
         ...
         <server name="default-server">
             ...
             <host name="default-host" alias="localhost">
                 ...
                 <location name="/directory-listing-uri" handler="directory-listing-handler"/>
                 ...
             </host>
             ...
         </server>
         ...
         <handlers>
             ...
             <file name="directory-listing-handler" path="/home/example/..." directory-listing="true"/>
         </handlers>
         ...
    </subsystem>
    

    Note: For jboss-cli configuration, you can take a look at this answer

    You will then get a nice Directory Listing GUI at this location:

    http://[wildfly host]:[port]/directory-listing-uri