View Full Version : Set Quercus base file path

07-12-2010, 03:12 AM

I am using Quercus to execute the serverside portion of KCFinder. However, I am running into difficulties as to where Quercus resolves pathnames to.

I have a resources servlet that serves static files. I also have a web app context parameter called "resourceBase" that tells my resource servlet where to find the files its supposed to be serving. This is necessary because I am serving static files from elsewhere in my filesystem (ie, not inside my webapp/appname/ folder).

I am developing my app in NetBeans. When I run it, NetBeans copies all the files to $project_home/build and then starts Tomcat, which makes all paths relative to there. However, my "resourceBase" setting allows the resource servlet to see files elsewhere in the filesystem. My .php files are in this location.

Now, when I run Quercus, it expects all files to be relative to "/" in the Web Application Context, which is the NetBeans build directory. Thus, when trying to run a script, it fails because the script does not exist there.

I cannot use a symlink to get around this because the production server is running Windows (this is outside my control).

Is there a way to make set the base path for Quercus to somewhere else in the filesystem, and resolve all filenames relative to that? (I am running Quercus by invoking it as a servlet everytime a file with a ".php" extension is encountered by the resource servlet).


07-13-2010, 02:43 AM
I have managed to get Quercus to load files from the new location by instantiating the Quercus servlet manually and overriding the getRealPath() method of the ServletContext to return a path relative to my actual resources directory.

Additionally, I had to modify the method getPath() in com.caucho.quercus.servlet.QuercusServletImpl to:

Path getPath(HttpServletRequest req)
String pathInfo = QuercusRequestAdapter.getPagePathInfo(req);
String realPath = Vfs.lookup().getFullPath() + pathInfo;
return new FilePath(realPath);

because it was using the HttpServletRequest object's getRealPath (which is deprecated by the way) instead of the ServletContext's getRealPath.

However, I am now faced with the same issue, this time from inside PHP. When I upload a file (using KCFinder), it appears relative to my context root and not my resources directory. This means that once the file has been uploaded, it can no longer be reached, because my resources servlet only looks in my resources directory (KCFinder is also being served from this directory).

How can I solve this?

07-13-2010, 05:13 AM
I solved it by modifying KCFinder to look at my Java session variables, and adjust its paths accordingly. Since the $request object was not available (unlike what the documentation suggests), I ended up implementing a custom function to expose my Java session variables.