Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » ServletContext real path in Jetty.
ServletContext real path in Jetty. [message #134643] Tue, 07 July 2009 11:57 Go to next message
Srijith is currently offline SrijithFriend
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 Go to previous messageGo to next message
Simon Kaegi is currently offline Simon KaegiFriend
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.
>
Re: ServletContext real path in Jetty. [message #134735 is a reply to message #134723] Wed, 08 July 2009 06:10 Go to previous message
Srijith is currently offline SrijithFriend
Messages: 6
Registered: July 2009
Junior Member
Hi Simon,

Thanks for your reply. I will certainly look at using that project.
In my case even if I can set the Servlet Context real path to any path on
the file system, my purpose would be served.

Was however just wondering, whether there is any discussion on
extending the HTTP Service specification to have API's for deploying web
applications. Considering that standalone Jetty already provides that
ability, it would not be too much of work to implement the same on
Equinox..

Once Again, thanks for your reply.

Thanks,
Srijith.
Previous Topic:RCP using declarative services (occasionally) hangs for 30 secs on start-up.
Next Topic:Update with p2 fails in RCP app
Goto Forum:
  


Current Time: Sat Apr 20 02:31:42 GMT 2024

Powered by FUDForum. Page generated in 0.02943 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top