bebo
bebo

Reputation: 114

Grizzly locks static served resources

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

Answers (3)

Chris Rodier
Chris Rodier

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

Itai Agmon
Itai Agmon

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

rlubke
rlubke

Reputation: 985

A possible workaround is to disable the FileCache.

HttpServer server = HttpServer.createSimpleServer();
server.getNetworkListener("grizzly").getFileCache().setEnabled(false);

If that doesn't help, I would suggest you log an issue so we can try to address it.

Upvotes: 3

Related Questions