New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[8.0.x] Another TCCL issue about servlet bundles #1760
Comments
I can not reopen the old issue, so create a new. |
Let me try to explain why I think it looks fine ;) about TCCL containing demo-pax1 and demo-pax2 bundles: You've installed two bundles into the same context so effectively the context runs servlets from different sources/bundles/origins that's why the only option is to see both bundles. Otherwise the Jetty (or Tomcat or Undertow) servlet handler which manages servlets for given context would have to set up a TCCL with a bundle for target servlet. But how about filters? They may come from different bundles as well - same for forward and include requests. That's why I believe it's now the developer's responsibility to not include the same servlet class in two different bundles. It's like WAR with JARs in about TCCL being different than While TCCL is set up according to the above, servlet context's classloader is set according to Whiteboard specification - https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#d0e119708:
Pax Web explicitly creates such ServletConfig and request wrappers, so their ServletContext overrides I found a bit more such vague places in Whiteboard/HttpService/WebApplications OSGi CMPN specifications and I had to make some compromises so Servlet API specification is still not (much) violated. I hope you understand my design decisions. And thank you very much for detailed analysis ;) |
@grgrzybek Thank you for your explanation. Now I understand it. So may be it is just fine to set the TCCL the same as servletContext.getClassLoader(). Could you please reconsider it? |
It depends what you're trying to do there ;) All the filters I tested (including 3rd party ones from Jolokia, Hawtio, MyFaces, PrimeFaces, Spring, ...) worked fine. Simply
But you tested the example with: public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().println("<h1>it worked</h1>");
try {
Thread.currentThread().getContextClassLoader().loadClass(MyServlet.class.getName());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
} ? |
No, it does not work. It is what your new patch fixes. |
As I said - it's not defined at all in Whiteboard (and entire OSGi CMPN) specification, so we have to make some sacrifices. I don't see an easy way to ensure that... Even in WAB scenario, part of Pax Web processing is inclusion of all reachable bundles. The reachability covers:
Eventually, the reachable bundles/jars constitute a "class space", so potential conflicts should be resolved by the developer... If you have time, please create a PR and add a sample (samples) to https://github.com/ops4j/org.ops4j.pax.web/tree/main/samples/samples-whiteboard showing what you would like to achieve and we'll think what can be done. |
Do we both agree that TCCL should include the servlet bundle requested, but need not and should not include other servlet/filter bundles? If so, I would take some time to figure out how to accomplish that.
I don't think it is the same scenario as whiteboard. The reachability is acceptable as it follows the osgi specification . And the WAB must has a unique context path to run, so WABs will not share the same servlet context. |
But Whiteboard specification says that each filter/servlet should get own bundle's classloader, so in scenario like:
each of these may get different
yes
not necessarily ;) My (at least for now) impression is that servlets/filters/listeners run in some environment, and the closest one is the containing "servlet context" and because this servlet context is almost like normal WAR/WebApplication, we shouldn't force separation of the bundles that contribute web elements into the given context... |
I thought that there is no jsp-support in whiteboard. And the specification states that ServletContext.getJspConfigDescriptor() returns null. |
Pax Web always supported JSP - it's kind of added value over the specification ;) (same as websockets, welcome files, SCIs, jetty handlers, ...) ;) |
Yes, Pax Web supports JSP, but only for WAB(I have tested it), not in pax web http whiteboard. At last, we do not need to support jsp in whiteboard, so set TCCL the same as servlet context cl could do no harm. |
There's Whiteboard/Blueprint JSP configuration example here: https://github.com/ops4j/org.ops4j.pax.web/blob/web-8.0.9/samples/samples-whiteboard/whiteboard-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml#L33-L42
Yes, but you can map this scenario to WAB case and TCCL there is correct. If you really need to use ClassLoader at all in But still - if you have real world examples where TCCL should be setup for each step (instead of once) in |
Anyway - new release is approaching, because I saw new Jetty versions today (9.4.49 and 10.0.12) - so we can think of something ;) |
yes, I mentioned chapter 10.7.2 in #1759 (comment) But it's about Web Applications, so WABs ;) and it's fine there. As you can see, I'm a bit hesitant.
How about ... giving you a configuration option? |
I think that's great! :) |
Give me some time - I'll check on Monday then. |
@qianwch I'm working on a fix. For now it'll be new PID property called
What do you think? |
… for servlet/filter service methods
Hi, I think that's great! |
The fix is pushed. Mind that there's no option for you to get a classloader reaching to more bundles without bundles of _other_servlets - you either get all with |
I have tested version 8.0.9. Still has problem.
Here are the two bundles that will demo the class space collision problem:
demo1.zip
demo2.zip
And it is the TCCL:
Originally posted by @qianwch in #1759 (comment)
The text was updated successfully, but these errors were encountered: