/** Returns the path to be used as the servlet name. */ private Path getPagePath(String pathName) { Path rootDir = _webApp.getRootDirectory(); String realPath = _webApp.getRealPath(pathName); Path path = rootDir.lookupNative(realPath); if (path.isFile() && path.canRead()) return path; java.net.URL url; ClassLoader loader = _webApp.getClassLoader(); if (loader != null) { url = _webApp.getClassLoader().getResource(pathName); String name = url != null ? url.toString() : null; path = null; if (url != null && (name.endsWith(".jar") || name.endsWith(".zip"))) path = JarPath.create(Vfs.lookup(url.toString())).lookup(pathName); else if (url != null) path = Vfs.lookup(url.toString()); if (path != null && path.isFile() && path.canRead()) return path; } url = ClassLoader.getSystemResource(pathName); String name = url != null ? url.toString() : null; path = null; if (url != null && (name.endsWith(".jar") || name.endsWith(".zip"))) path = JarPath.create(Vfs.lookup(url.toString())).lookup(pathName); else if (url != null) path = Vfs.lookup(url.toString()); if (path != null && path.isFile() && path.canRead()) return path; else return null; }
private void setEnvironment(ClientSocket stream, WriteStream ws, HttpServletRequest req) throws IOException { addHeader(stream, ws, "REQUEST_URI", req.getRequestURI()); addHeader(stream, ws, "REQUEST_METHOD", req.getMethod()); addHeader(stream, ws, "SERVER_SOFTWARE", "Resin/" + VersionFactory.getVersion()); addHeader(stream, ws, "SERVER_NAME", req.getServerName()); // addHeader(stream, ws, "SERVER_ADDR=" + req.getServerAddr()); addHeader(stream, ws, "SERVER_PORT", String.valueOf(req.getServerPort())); addHeader(stream, ws, "REMOTE_ADDR", req.getRemoteAddr()); addHeader(stream, ws, "REMOTE_HOST", req.getRemoteAddr()); // addHeader(stream, ws, "REMOTE_PORT=" + req.getRemotePort()); if (req.getRemoteUser() != null) addHeader(stream, ws, "REMOTE_USER", req.getRemoteUser()); else addHeader(stream, ws, "REMOTE_USER", ""); if (req.getAuthType() != null) addHeader(stream, ws, "AUTH_TYPE", req.getAuthType()); addHeader(stream, ws, "GATEWAY_INTERFACE", "CGI/1.1"); addHeader(stream, ws, "SERVER_PROTOCOL", req.getProtocol()); if (req.getQueryString() != null) addHeader(stream, ws, "QUERY_STRING", req.getQueryString()); else addHeader(stream, ws, "QUERY_STRING", ""); String scriptPath = req.getServletPath(); String pathInfo = req.getPathInfo(); WebApp webApp = (WebApp) req.getServletContext(); Path appDir = webApp.getAppDir(); String realPath = webApp.getRealPath(scriptPath); if (!appDir.lookup(realPath).isFile() && pathInfo != null) scriptPath = scriptPath + pathInfo; /* * FastCGI (specifically quercus) uses the PATH_INFO and PATH_TRANSLATED * for the script path. */ log.finer("STREAM file: " + webApp.getRealPath(scriptPath)); addHeader(stream, ws, "PATH_INFO", req.getContextPath() + scriptPath); addHeader(stream, ws, "PATH_TRANSLATED", webApp.getRealPath(scriptPath)); /* These are the values which would be sent to CGI. addHeader(stream, ws, "SCRIPT_NAME", req.getContextPath() + scriptPath); addHeader(stream, ws, "SCRIPT_FILENAME", app.getRealPath(scriptPath)); if (pathInfo != null) { addHeader(stream, ws, "PATH_INFO", pathInfo); addHeader(stream, ws, "PATH_TRANSLATED", req.getRealPath(pathInfo)); } else { addHeader(stream, ws, "PATH_INFO", ""); addHeader(stream, ws, "PATH_TRANSLATED", ""); } */ int contentLength = req.getContentLength(); if (contentLength < 0) addHeader(stream, ws, "CONTENT_LENGTH", "0"); else addHeader(stream, ws, "CONTENT_LENGTH", String.valueOf(contentLength)); ServletContext rootContext = webApp.getContext("/"); if (rootContext != null) addHeader(stream, ws, "DOCUMENT_ROOT", rootContext.getRealPath("/")); CharBuffer cb = new CharBuffer(); Enumeration e = req.getHeaderNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = req.getHeader(key); if (key.equalsIgnoreCase("content-length")) addHeader(stream, ws, "CONTENT_LENGTH", value); else if (key.equalsIgnoreCase("content-type")) addHeader(stream, ws, "CONTENT_TYPE", value); else if (key.equalsIgnoreCase("if-modified-since")) { } else if (key.equalsIgnoreCase("if-none-match")) { } else if (key.equalsIgnoreCase("authorization")) { } else if (key.equalsIgnoreCase("proxy-authorization")) { } else addHeader(stream, ws, convertHeader(cb, key), value); } }
public String getRealPath(String uri) { WebApp webApp = getWebApp(); return webApp.getRealPath(uri); }
/** * Given a request and response, returns the compiled Page. For example, JspManager will return * the JspPage and XtpManager will return the XtpPage. * * @param req servlet request for generating the page. * @param res servlet response to any needed error messages. */ private Page getSubPage(HttpServletRequest req, HttpServletResponse res) throws Exception { CauchoRequest cauchoRequest = null; initGetPage(); /* if (! _webApp.isActive()) throw new UnavailableException("JSP compilation unavailable during restart", 10); */ if (req instanceof CauchoRequest) cauchoRequest = (CauchoRequest) req; String servletPath; if (cauchoRequest != null) servletPath = cauchoRequest.getPageServletPath(); else servletPath = RequestAdapter.getPageServletPath(req); if (servletPath == null) servletPath = "/"; String uri; if (cauchoRequest != null) uri = cauchoRequest.getPageURI(); else uri = RequestAdapter.getPageURI(req); Path appDir = _webApp.getRootDirectory(); String realPath; Path subcontext; ServletConfig config = null; String jspPath = (String) req.getAttribute("caucho.jsp.jsp-file"); if (jspPath != null) { req.removeAttribute("caucho.jsp.jsp-file"); subcontext = getPagePath(jspPath); return _manager.getPage(uri, jspPath, subcontext, config); } String pathInfo; if (cauchoRequest != null) pathInfo = cauchoRequest.getPagePathInfo(); else pathInfo = RequestAdapter.getPagePathInfo(req); subcontext = getPagePath(servletPath); if (subcontext != null) return _manager.getPage(servletPath, subcontext); if (pathInfo == null) { realPath = _webApp.getRealPath(servletPath); subcontext = appDir.lookupNative(realPath); return _manager.getPage(servletPath, subcontext); } subcontext = getPagePath(servletPath + pathInfo); if (subcontext != null) return _manager.getPage(servletPath + pathInfo, subcontext); // If servlet path exists, can't use pathInfo to lookup servlet, // because /jsp/WEB-INF would be a security hole if (servletPath != null && !servletPath.equals("")) { // server/0035 throw new FileNotFoundException(L.l("{0} was not found on this server.", uri)); // return null; } subcontext = getPagePath(pathInfo); if (subcontext != null) return _manager.getPage(pathInfo, subcontext); subcontext = getPagePath(uri); if (subcontext == null) throw new FileNotFoundException(L.l("{0} was not found on this server.", uri)); return _manager.getPage(uri, subcontext); }