FileInputStream is = null;
long length = 0;
String contentType = null;
String uri = request.uri();
if (uri.charAt(0) == '/') {
WOResourceManager rm = application.resourceManager();
String documentRoot = documentRoot();
File file = null;
StringBuilder sb = new StringBuilder(documentRoot.length() + uri.length());
String wodataKey = request.stringFormValueForKey("wodata");
if(uri.startsWith("/cgi-bin") && wodataKey != null) {
uri = wodataKey;
if(uri.startsWith("file:")) {
// remove file:/
uri = uri.substring(5);
} else {
}
} else {
int index = uri.indexOf("/wodata=");
if(index >= 0) {
uri = uri.substring(index+"/wodata=".length());
} else {
sb.append(documentRoot);
}
}
if (_useRequestHandlerPath) {
try {
WODynamicURL dynamicURL = new WODynamicURL(uri);
String requestHandlerPath = dynamicURL.requestHandlerPath();
if (requestHandlerPath == null || requestHandlerPath.length() == 0) {
sb.append(uri);
} else {
sb.append('/');
sb.append(requestHandlerPath);
}
}
catch (Exception e) {
throw new RuntimeException("Failed to parse URL '" + uri + "'.", e);
}
}
else {
sb.append(uri);
}
String path = sb.toString();
try {
path = path.replaceAll("\\?.*", "");
if (request.userInfo() != null && !request.userInfo().containsKey("HttpServletRequest")) {
/* PATH_INFO is already decoded by the servlet container */
path = path.replace('+', ' ');
path = URLDecoder.decode(path, CharEncoding.UTF_8);
}
file = new File(path);
length = file.length();
is = new FileInputStream(file);
contentType = rm.contentTypeForResourceNamed(path);
log.debug("Reading file '" + file + "' for uri: " + uri);
} catch (IOException ex) {
if (!uri.toLowerCase().endsWith("/favicon.ico")) {
log.info("Unable to get contents of file '" + file + "' for uri: " + uri);
}