|
From: <php...@li...> - 2007-02-11 18:52:34
|
Hi,
those who want to run the PHP/Java Bridge on the
WebLogic application server need to implement their
own getRealPath(). The WebLogic getRealPath() API is
broken and always returns null. The following is a
getRealPath() emulation which uses the getResource()
API on WebLogic:
/**
* Identical to context2.getRealPath(pathInfoCGI).
On BEA
* WebLogic, which has a broken getRealPath()
implementation, we
* use context2.getResource(pathInfoCGI)) instead.
* @param context2 The servlet context.
* @param pathInfoCGI may be "" or "/" for
example.
* @return a valid path or null
*/
public static String getRealPath(ServletContext
context2, String pathInfoCGI) {
String ret = context2.getRealPath(pathInfoCGI);
if(ret!=null) return ret;
// The following is the workaround for BEA WebLogic
boolean stripSlash=false;
if(!pathInfoCGI.endsWith("/")) {
stripSlash=true;
if("".equals(pathInfoCGI)) pathInfoCGI = "/";
}
URL url = null;
try {
url = context2.getResource(pathInfoCGI);
} catch (MalformedURLException e) {
Util.printStackTrace(e);
return null;
}
if(!"file".equals(url.getProtocol())) return null;
ret = url.getPath();
if(stripSlash&&ret.endsWith("/")) ret =
ret.substring(0, ret.length()-1);
return ret.replace('/', File.separatorChar);
}
___________________________________________________________
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
|