Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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