Skip to content

Instantly share code, notes, and snippets.

@lenards
Created July 25, 2010 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lenards/489143 to your computer and use it in GitHub Desktop.
Save lenards/489143 to your computer and use it in GitHub Desktop.
private void doGetPublicFile(HttpServletRequest request,
HttpServletResponse response, TreeLogger logger, String partialPath,
String moduleName) throws IOException {
// Create a logger branch for this request.
String msg = "The development shell servlet received a request for '"
+ partialPath + "' in module '" + moduleName + "' ";
logger = logger.branch(TreeLogger.TRACE, msg, null);
// ...
URL foundResource;
try {
// Look for the requested file on the public path.
//
ModuleDef moduleDef = getModuleDef(logger, moduleName);
foundResource = moduleDef.findPublicFile(partialPath);
if (foundResource == null) {
// Look in the place where we write compiled output.
File moduleDir = new File(getOutputDir(), moduleName);
File requestedFile = new File(moduleDir, partialPath);
if (requestedFile.exists()) {
try {
foundResource = requestedFile.toURI().toURL();
} catch (MalformedURLException e) {
// ignore since it was speculative anyway
}
}
if (foundResource == null) {
msg = "Resource not found: " + partialPath;
logger.log(TreeLogger.WARN, msg, null);
throw new UnableToCompleteException();
}
}
} catch (UnableToCompleteException e) {
sendErrorResponse(response, HttpServletResponse.SC_NOT_FOUND,
"Cannot find resource '" + partialPath
+ "' in the public path of module '" + moduleName + "'");
return;
}
// ... omitted
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment