ServletContext real path in Jetty. [message #134643] |
Tue, 07 July 2009 11:57 |
Srijith Messages: 6 Registered: July 2009 |
Junior Member |
|
|
Hi,
I am building an OSGi container to host an application that was
previously hosted on tomcat. Though I have the source code of the
application, I do not want to change it.
I have bundled the application and take their main servlet class and
register it with HttpService. Now the problem I am facing is that, the
application tries to read a config file, from a path. To construct the
path for the same, it does something like the following in it's servlet's
init method.
public void init (ServletConfig config) throws ServletException
{
ServletContext context = config.getServletContext();
String path = context.getRealPath("/");
..... }
Somehow in my case the getRealPath API always returns null. In a Tomcat
servlet container, I believe, this will retrieve the actual filesystem
path of the extracted war file. I have the config file which I could
bundle along with the jar, but not sure how I can get this to work.
I read another message on this newsgroup about deploying webapps in
equinox, where Simon had mentioned that the Servlet Context is created out
of the HttpContext that we create and pass to the registerServlet call. I
created the same and also registered a resource folder, but got a
namespace exception, and the original problem still remained the same.
Any help in this regard would be highly appreciated. Probably it would
work if I use Jetty outside OSGi, but I do badly want to get this done
within Equinox, for my other requirements.
Thanks,
Srijith.
|
|
|
Re: ServletContext real path in Jetty. [message #134723 is a reply to message #134643] |
Wed, 08 July 2009 05:24 |
Simon Kaegi Messages: 381 Registered: July 2009 |
Senior Member |
|
|
In an OSGi environment the ServletContext is manufactured to provide
resource access but not file path information as typically a web application
is not unzipped on disk and is instead in bundle form. You can manufacture
your own ServletContext to provide the appropriate resource paths etc. that
you expect however it's a bit of work. Take a look at the
org.eclipse.equinox.http.helper project in the incubator as although it does
not have a Servlet Context implementation that provides real path support
there are a number of working examples that you can start from.
ContextPathServletAdaptor would be a good place to start as you're making
RealPathServletAdaptor
CVS coordinates:
dev.eclipse.org
/cvsroot/rt
org.eclipse.equinox/incubator/server-side/bundles/org.eclips e.equinox.http.helper
HTH
-Simon
"Srijith " <ksrijith@novell.com> wrote in message
news:25f76f0f0ef51f07f3e227ed8adf43d1$1@www.eclipse.org...
> Hi,
>
> I am building an OSGi container to host an application that was
> previously hosted on tomcat. Though I have the source code of the
> application, I do not want to change it.
>
> I have bundled the application and take their main servlet class and
> register it with HttpService. Now the problem I am facing is that, the
> application tries to read a config file, from a path. To construct the
> path for the same, it does something like the following in it's servlet's
> init method.
>
> public void init (ServletConfig config) throws ServletException
> {
> ServletContext context = config.getServletContext();
> String path = context.getRealPath("/");
> ..... }
>
> Somehow in my case the getRealPath API always returns null. In a Tomcat
> servlet container, I believe, this will retrieve the actual filesystem
> path of the extracted war file. I have the config file which I could
> bundle along with the jar, but not sure how I can get this to work.
>
> I read another message on this newsgroup about deploying webapps in
> equinox, where Simon had mentioned that the Servlet Context is created out
> of the HttpContext that we create and pass to the registerServlet call. I
> created the same and also registered a resource folder, but got a
> namespace exception, and the original problem still remained the same.
>
> Any help in this regard would be highly appreciated. Probably it would
> work if I use Jetty outside OSGi, but I do badly want to get this done
> within Equinox, for my other requirements.
>
> Thanks,
> Srijith.
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.02943 seconds