Skip to content

Commit

Permalink
Merge pull request #1744 from laurentg/local-http-handler
Browse files Browse the repository at this point in the history
Add "--clientFiles" option to serve local files by http.
  • Loading branch information
abyrd committed Feb 19, 2015
2 parents 13aa3a3 + beab6d7 commit 03b76f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ public class CommandLineParameters implements Cloneable {
description = "Path to directory containing PointSets. Defaults to BASE_PATH/pointsets.")
public File pointSetDirectory;

@Parameter(names = {"--clientFiles"}, validateWith = ReadableDirectory.class,
description = "Path to directory containing local client files to serve.")
public File clientDirectory = null;

@Parameter(names = {"--router"}, validateWith = RouterId.class,
description = "One or more router IDs to build and/or serve, first one being the default.")
public List<String> routerIds;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/opentripplanner/standalone/GrizzlyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.glassfish.grizzly.http.server.HttpHandler;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.grizzly.http.server.NetworkListener;
import org.glassfish.grizzly.http.server.StaticHttpHandler;
import org.glassfish.grizzly.ssl.SSLContextConfigurator;
import org.glassfish.grizzly.ssl.SSLEngineConfigurator;
import org.glassfish.grizzly.threadpool.ThreadPoolConfig;
Expand Down Expand Up @@ -97,6 +98,17 @@ public void run() {
HttpHandler staticHandler = new CLStaticHttpHandler(GrizzlyServer.class.getClassLoader(), "/client/");
httpServer.getServerConfiguration().addHttpHandler(staticHandler, "/");

/*
* 3. A static content handler to serve local files from the filesystem, under the "local"
* path.
*/
if (params.clientDirectory != null) {
StaticHttpHandler localHandler = new StaticHttpHandler(
params.clientDirectory.getAbsolutePath());
localHandler.setFileCacheEnabled(false);
httpServer.getServerConfiguration().addHttpHandler(localHandler, "/local");
}

/* 3. Test alternate method (no Jersey). */
// As in servlets, * is needed in base path to identify the "rest" of the path.
// GraphService gs = (GraphService) iocFactory.getComponentProvider(GraphService.class).getInstance();
Expand Down

0 comments on commit 03b76f6

Please sign in to comment.