Questions about contexts [message #90173] |
Mon, 11 June 2007 17:19  |
Eclipse User |
|
|
|
Originally posted by: roide.gmx.de
Hi @all,
I'm trying to get a small sample web app running based on jetty embedded in equinox.
My webcontent is distributed in several bundles.
Each bundle registers it resources via a service like this:
HttpContext commonContext = new BundleEntryHttpContext(tempBundle);
httpService.registerResources(service.getResourceAlias(), service.getPathToResources(), commonContext);
Servlet adaptedJspServlet = new ContextPathServletAdaptor(new JspServlet(service.getContext().getBundle(), service.getPathToServlets()), service.getServletContextPath());
httpService.registerServlet(service.getServletAlias(), adaptedJspServlet, null, commonContext);
This solution is working fine. I can access all resources and jsp's.
Q1: So in every BundleContex I create a HttpContext where Resources are registerd and a ServletContext can be created.
Is that correct so?
Q3: I've tried to include jsp's from a bundle via <jsp:include page="/contextA/content.jsp"/> that doesn't work.
Is it possible to include jsp's into a bundle from another bundle? Does anyone have a example?
Q4: Is it possible to register servlets and resources from different bundles within the same HttpContext?
Q5: Am I totally wrong? ;-)
Thx in advance.
|
|
|
Re: Questions about contexts [message #90224 is a reply to message #90173] |
Mon, 11 June 2007 22:34  |
Eclipse User |
|
|
|
"Mat Halter" <roide@gmx.de> wrote in message
news:464729434.11251181596794558.JavaMail.root@cp9.dzone.com...
> Hi @all,
>
> I'm trying to get a small sample web app running based on jetty embedded
> in equinox.
>
> My webcontent is distributed in several bundles.
>
> Each bundle registers it resources via a service like this:
>
> HttpContext commonContext = new BundleEntryHttpContext(tempBundle);
> httpService.registerResources(service.getResourceAlias(),
> service.getPathToResources(), commonContext);
>
> Servlet adaptedJspServlet = new ContextPathServletAdaptor(new
> JspServlet(service.getContext().getBundle(), service.getPathToServlets()),
> service.getServletContextPath());
>
I see you're using the ContextPathServletAdaptor. The jsp-examples requires
this because the generated pages uses absolute URLs. It's a better idea to
generate pages relative URLs if you can. e.g. I'd use the
ContextPathServletAdaptor only if you really have to. It also has an impact
on RequestDispatching -- see below.
> httpService.registerServlet(service.getServletAlias(), adaptedJspServlet,
> null, commonContext);
>
>
> This solution is working fine. I can access all resources and jsp's.
>
great.
> Q1: So in every BundleContex I create a HttpContext where Resources are
> registerd and a ServletContext can be created.
> Is that correct so?
Yes... I suspect you mean in every Activator... You might also want to look
at doing this automatically using the extension point in
org.eclipse.equinox.http.
This is what the Help/UA component is doing in eclipse3.3 -- see
org.eclipse.help.webapp
What happened to Q2? :)
>
> Q3: I've tried to include jsp's from a bundle via <jsp:include
> page="/contextA/content.jsp"/> that doesn't work.
> Is it possible to include jsp's into a bundle from another bundle? Does
> anyone have a example?
Definitely possible. This is done all over the place in Help and several
other commercial apps I'm aware of.
I suspect you're running into problems related to your use of
ContextPathServletAdaptor. When you use this adaptor you are scoping the URL
space that your servlet is aware of. This is similar to the behaviour you
have in a regular webapp's ServletContext and the problem's you'd have if
you were trying cross-context request dispatching.
>
> Q4: Is it possible to register servlets and resources from different
> bundles within the same HttpContext?
Sure. Although you'll have to come up with your own mechanism to share that
HttpContext instance.
>
> Q5: Am I totally wrong? ;-)
My best guess is that my use of ContextPathServletAdaptor in the jsp
examples has led to confusion.I'll try and put together some more
straight-forward examples as I update the web site.
>
> Thx in advance.
|
|
|
Powered by
FUDForum. Page generated in 0.04106 seconds