Skip to content

Commit

Permalink
fix(agent): improving serve store API to support directory listings
Browse files Browse the repository at this point in the history
  • Loading branch information
notthetup committed Oct 7, 2024
1 parent f1290c5 commit 11a70c5
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/main/java/org/arl/fjage/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -703,16 +703,32 @@ public Store getStore() {
/**
* Serve the Agent's store over HTTP.
*
* @param enable true to enable, false to disable
* @param directoryListing true to enable directory listing, false otherwise
* @return true if successful, false otherwise
*/
public boolean serveStore(boolean enable){
public boolean enableServeStore(boolean directoryListing){
WebServer webServer = getWebServer();
if (webServer != null) {
String path = "store/" + this.getClass().getCanonicalName().replace(".", "/");
if (webServer.hasContext(path) == enable) return true;
if (enable) webServer.add("/"+path, new File(path+"/"));
else webServer.remove("/"+path);
if (webServer.hasContext(path)) return false;
webServer.add("/"+path, new File(path+"/"), new WebServer.WebServerOptions().directoryListed(directoryListing));
return true;
}
log.warning("No web server found");
return false;
}

/**
* Stop serving the Agent's store over HTTP.
*
* @return true if successful, false otherwise
*/
public boolean disableServeStore(){
WebServer webServer = getWebServer();
if (webServer != null) {
String path = "store/" + this.getClass().getCanonicalName().replace(".", "/");
if (!webServer.hasContext(path)) return false;
webServer.remove("/"+path);
return true;
}
log.warning("No web server found");
Expand Down

0 comments on commit 11a70c5

Please sign in to comment.