Reputation: 114
If Grizzly with a StaticHttpHandler is running, and a request is made to a static file (example index.html), then that file becomes locked. That is, it is impossible to edit and save index.html while Grizzly is running.
There's any solution or workaround to be able to save currently served static resources?
Upvotes: 1
Views: 870
Reputation: 1
I struggled with this for a while. The posts above work, but only if done after the server is started.
The server turns file caching back on when you start it, if you set it to false before it is running. Make sure to turn it off after you call server.start() as shown here.
It appears the Jersey 2.3.17 / Grizzly HttpServer turns caching on when you call
server.start();
despite setting it to false prior to starting it.
server.start(); // turns file cache back on
handler.setFileCacheEnabled(false); // turn it off again
// get every NetworkListener and set it to false (as these will also lock files)
for (NetworkListener l : server.getListeners()) {l.getFileCache().setEnabled(false); }
Upvotes: 0
Reputation: 1517
I couldn't find the server.getNetworkListnener method in Grizzly 2.3.16, so it worked for me when I did:
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUri), rc);
StaticHttpHandler staticHttpHandler = new StaticHttpHandler("docRoot");
staticHttpHandler.setFileCacheEnabled(false);
server.getServerConfiguration().addHttpHandler(staticHttpHandler);
Upvotes: 2