It is not a bug, "ServletContext.getRealPath("") never return a real path on
OSGI container.

For Equinox framework, use the following code fragment:

import org.eclipse.core.runtime. FileLocator;
...

ServletContext context = request.getSession().getServletContext();
URL url = context.getResource("/");
String realPath = FileLocator.toFileURL(url).getPath();




-----Original Message-----
From: asookazian2 [mailto:asookaz...@gmail.com] 
Sent: Thursday, March 06, 2014 8:12 AM
To: user@karaf.apache.org
Subject: unable to getRealPath for servlet context

I found the following Jetty bug report: 
http://jira.codehaus.org/browse/JETTY-675
<http://jira.codehaus.org/browse/JETTY-675>  

User states the following:

"ServletContext.getRealPath("") returns null instead of returning the root
dir of the webapp"

I am able to reproduce this behavior in my WAR bundle with MANIFEST.MF (WAB
(WebApplication Bundle)) deployment to Karaf 3.0.0.  The version of Jetty is
the following:

karaf@root()> feature:list | grep jetty
cxf-http-jetty                | 3.0.0-milestone2 | x         |
cxf-3.0.0-milestone2    |                                                   
jetty                         | 8.1.9.v20130131  | x         |
standard-3.0.0          |                                                   
pax-jetty                     | 8.1.14.v20131031 | x         |
org.ops4j.pax.web-3.0.5 | Provide Jetty engine support  

I have tried ServletContext.getRealPath("");

I have also tried ServletContext.getRealPath("/");

Both code lines return null.

Is this expected for this version of Karaf/Jetty?  If yes, how can I
determine the real path.

Our scenario involves a properties file that may be installed in
karaf/config/foo directory.  We don't want to load/read the file from inside
the WAR (e.g. WEB-INF) b/c the customer may need to change the file.  



--
View this message in context:
http://karaf.922171.n3.nabble.com/unable-to-getRealPath-for-servlet-context-
tp4032109.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Reply via email to