in runtime/local_jetty12/src/main/java/com/google/appengine/tools/development/jetty/LocalResourceFileServlet.java [110:204]
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String servletPath;
String pathInfo;
AppEngineWebXml appEngineWebXml = (AppEngineWebXml) getServletContext().getAttribute(
"com.google.appengine.tools.development.appEngineWebXml");
WebXml webXml = (WebXml) getServletContext().getAttribute(
"com.google.appengine.tools.development.webXml");
Boolean forwarded = request.getAttribute(__FORWARD_JETTY) != null;
if (forwarded == null) {
forwarded = Boolean.FALSE;
}
Boolean included = request.getAttribute(__INCLUDE_JETTY) != null;
if (included != null && included) {
servletPath = (String) request.getAttribute(__INCLUDE_SERVLET_PATH);
pathInfo = (String) request.getAttribute(__INCLUDE_PATH_INFO);
if (servletPath == null) {
servletPath = request.getServletPath();
pathInfo = request.getPathInfo();
}
} else {
included = Boolean.FALSE;
servletPath = request.getServletPath();
pathInfo = request.getPathInfo();
}
String pathInContext = URIUtil.addPaths(servletPath, pathInfo);
if (maybeServeWelcomeFile(pathInContext, included, request, response)) {
// We served a welcome file (either via redirecting, forwarding, or including).
return;
}
// Find the resource
Resource resource = null;
try {
resource = getResource(pathInContext);
// Handle resource
if (resource != null && resource.isDirectory()) {
if (included || staticFileUtils.passConditionalHeaders(request, response, resource)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
} else {
if (resource == null || !resource.exists()) {
logger.warning("No file found for: " + pathInContext);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else {
boolean isStatic = appEngineWebXml.includesStatic(resourceRoot + pathInContext);
boolean isResource = appEngineWebXml.includesResource(
resourceRoot + pathInContext);
boolean usesRuntime = webXml.matches(pathInContext);
Boolean isWelcomeFile = (Boolean)
request.getAttribute("com.google.appengine.tools.development.isWelcomeFile");
if (isWelcomeFile == null) {
isWelcomeFile = false;
}
if (!isStatic && !usesRuntime && !(included || forwarded)) {
logger.warning(
"Can not serve "
+ pathInContext
+ " directly. "
+ "You need to include it in <static-files> in your "
+ "appengine-web.xml.");
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
} else if (!isResource && !isWelcomeFile && (included || forwarded)) {
logger.warning(
"Could not serve "
+ pathInContext
+ " from a forward or "
+ "include. You need to include it in <resource-files> in "
+ "your appengine-web.xml.");
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
// passConditionalHeaders will set response headers, and
// return true if we also need to send the content.
if (included || staticFileUtils.passConditionalHeaders(request, response, resource)) {
staticFileUtils.sendData(request, response, included, resource);
}
}
}
} finally {
if (resource != null) {
// TODO: how to release
// resource.release();
}
}
}