I am running into to some caching problems because Wildfly 8.2 only includes the Last-Modified response header by default when serving static files from a deployed war file. I would like Wildfly to include ETag, response header, which would solve my caching problems. Does anyone know if possible to configure in the standalone.xml file?
Asked
Active
Viewed 968 times
1
-
Take a look in: http://stackoverflow.com/questions/34133039/browser-cache-expiration-for-js-and-css-files-with-wildfly – Federico Sierra Apr 12 '16 at 14:12
-
Have already had a look, but saw no answer. It however seems that Undertow 1.2.x does not support etags for static files. See https://github.com/undertow-io/undertow/blob/07d0ccb1eefb04a3b712af4e2c8f3a303081b0b1/core/src/main/java/io/undertow/server/handlers/resource/PathResource.java and https://github.com/undertow-io/undertow/blob/07d0ccb1eefb04a3b712af4e2c8f3a303081b0b1/core/src/main/java/io/undertow/server/handlers/resource/ResourceHandler.java – Jesper Tejlgaard Apr 12 '16 at 14:40
-
@FedericoSierra Any idea of how to
and – Jesper Tejlgaard Apr 13 '16 at 07:33to include an etag of variable size, e.g. some hash on the content of a file. -
I think you can use a custom handler/filter to resolve this problem, see : https://kb.novaordis.com/index.php/Configuring_a_Custom_Undertow_Filter_in_WildFly or alternatively implement a servlet filter in your application. – Federico Sierra Apr 13 '16 at 13:14
-
Did you manage to solve this? – tggm Feb 16 '17 at 10:43
1 Answers
0
I have implemented workaround with special "resource" servlet serving war resources with ETag header.
Servlet extends from FileServlet class implemented in Omnifaces library (http://showcase.omnifaces.org/servlets/FileServlet). FileServlet implementation handles all HTTP caching headers correctly, all you need is to implement resource loading method getFile() to serve war resource files. Here is the example for correct cached serving all resources from "app" directory:
@WebServlet(value = {"/app/*"})
public class ApplicationResourceServlet extends FileServlet {
@Override
protected File getFile(HttpServletRequest request) throws IllegalArgumentException {
final String pathInfo = request.getPathInfo();
if (pathInfo == null || pathInfo.isEmpty() || "/".equals(pathInfo)) {
return null;
}
final String realPath = getServletContext().getRealPath("/app" + pathInfo);
if (realPath != null && Paths.get(realPath).toFile().exists()) {
return new File(realPath);
}
return null;
}
}

Marek Gregor
- 3,691
- 2
- 26
- 28