5

I have a web application on Wildfly 10 and in the web application directory i have placed a zip file that I want to be downloaded when user clicks on the hyperlink. On the UI I have

Snippet

<div class="tyDiv" onclick="window.open('request.getContextPath() + "/downloads/Installer.exe")%>','_self')">
</div>

It creates correct url like

"http://192.168.2.123:8080/comp/downloads/Installer.exe"


Content-Type:text/html;charset=UTF-8

This works in JBoss6 as expected . It downloads the exe file but in Wildfly it display all the junk characters on the screen as its content type is text/html

I tried setting mime type in standalone-full.xml but did not work.

 <mime-mappings>
    <mime-mapping name="css" value="text/css"/>
    <mime-mapping name="exe" value="application/octet-stream"/>
 </mime-mappings>
happy
  • 2,550
  • 17
  • 64
  • 109
  • Could not reproduce this behaviour in vanilla Wildfly-10.0.0. My sequence of steps was ```cd deployments; mkdir foo.war; echo bar > foo.war/bar.exe, curl -v http://localhost:8080/foo/bar.exe``` and the resulting ```Content-Type``` was ```application/octet-stream```. There must be something else. Check whether there's no custom `mime-mapping` in web.xml. – Mišo Stankay Sep 21 '17 at 11:01
  • No. there is no mime-mapping instead I tried adding it into web.xml but It didn't work, – happy Sep 22 '17 at 04:27
  • I suggest that you try my approach on **vanilla** Wildfly installation. Then try adding artifacts to your project piece by piece to see when it went wrong again. – Mišo Stankay Sep 26 '17 at 07:47

1 Answers1

0

The documentation at undertow.io shows how to manually set the MIME type per response, eg. exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/octet-stream"); while the file with the MIME type mappings might possibly be called web.xml (make sure the correct file is being referenced). Beside that, I could imagine that the servlet-filter may not be configured as it should - and it dispatches the request where they should not end up (have found https://stackoverflow.com/tags/servlet-filters/info). while this answer here even shows how to add MIME types at runtime: https://stackoverflow.com/a/38021097/549372 (ordinary is should nevertheless serve application/octet-stream while writing a binary stream to the output - which implies, that it also could be the result of a wrongful input stream).

Martin Zeitler
  • 1
  • 19
  • 155
  • 216