Hi, thanks for the sample, will see to it. regarding the comments/remarks, see my comments inline :)
Achim 2017-06-19 14:50 GMT+02:00 Eben Stewart <[email protected]>: > Attached is a working example, the smallest I could get it (project is > bndtools under Eclipse) > > A few points that threw me off, that did not seem clear at first (although > they make sense now) - a lot of it had to do with the whiteboard extensions > to get resources and jsp support - I am not aware if the OSGI spec even > handles those concepts (although the WAR/WAB is). I do like this way > better, as it doesn't make the bundle "special" in the way in handles > servlets, jsps and resources... they are all just services. > Just a bit of History, it might make the picture clearer for you. The Pax Web Whiteboard extender exists since the WAR/WAB part has been implemented, and at the time beeing that part also moved into the OSGi spec. If you take a look at it, Pax Web and the Pax Url war URL-Handler are part of the reference implementation for that part of the OSGi Spec. So actually the Pax Web Whiteboard extension mechanism is "pretty" old :) About 2 years ago an Whiteboard extender mechanism had been added to the OSGi spec, so we working on Pax Web tried to adapt the existing code to the new spec. > > 1) The use of HttpContextMapping > > - There is no default implementation of this, like JspMapping and > ResourceMapping, so also cannot use annotations to initialize? > - How to use HttpContextMapping, DefaultHttpContext (or shared), and > still be able to get to handleSecurity() > > You can retrieve a DefaultHttpContext Instance from the HttpService (or WebContainer Service), register it as your own HttpContext. Maybe that helps to what your are looking for? > 2) No DefaultHttpContext (that can be extended as an annotated Service) > > - DefaultHttpContext is package private, so there is no "automatic" > way to wire in a custom HttpContext (for the handleSecurity() method) > without doing a lot of boilerplate coding to get the service, create the > context, etc. Since the DefaultHttpContext handles the getResource() > correctly in this scenario, it would be nice to be able to extend this > class, and get it wired in via annotations. > - I think what I was expecting was to have something similar to > JspMapping or ResourceMapping that allowed me to specify path and contextID > as annotations, and have the default getResources() handler, while being > able to override the getSecurity() > > > Sounds like a new feature, this in itself it worthy a new Issue, oh and we do love contributions ;) > 3) Required use of "ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID" instead > of "HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT" in Servlets > > - Could not get the context selector to work - only the Extender > property correctly maps the servlet to the context, as created by > HttpContextMapping > > See above, about us trying to form the existing Whiteboard extender into the specified one by the OSGi Spec, so this could be a bug :) > 4) JspMapping and ResourceMapping cannot use annotations to initialize > > - Tried using the ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID > annotation property - won't work - had expected to use Whiteboard, or > Whiteboard-like annotations > - Initializing in the constructor does work > > Sounds like another feature request. > Hope all this makes sense - not sure how to translate this into a JIRA bug > or feature request. > Makes a lot of sense now, you could open different issues / feature requests for those. Oh and we do love contributions, if I didn't tell you that before :) > > In the end, I have a workaround, and a sample you might be able to use to > make the scenario more clear, so that it might help others. > yeah, thanks will form a sample out of it, so we can actually use it as a reference for the integration tests for those issues/bugs/feature request you'll create ;) > > On Saturday, June 17, 2017 at 3:42:51 PM UTC-4, Achim Nierbeck wrote: >> >> Hi, >> >> thanks, sounds like a good idea. >> Yep, that's a standard scenario, so it could be a bug you found, >> especially since the non OSGi spec whiteboard properties seem to work. >> >> regards, Achim >> >> >> 2017-06-17 17:17 GMT+02:00 Eben Stewart <[email protected]>: >> >>> Sure... let me get something stripped down to the essentials.... >>> >>> Maybe show how I got it to work, and how I would have expected it to >>> work, given the current docs? Esp if I can get it working with all >>> annotations (via annotations on JspMapping and ResourceMapping classes) - >>> no Activator class, >>> >>> I don't know if it's necessarily a bug, but rather a disconnect or >>> clarification (possibly just in documentation/samples). >>> >>> At a minimum, it might make a good basis for a sample? I can't be the >>> only one trying to do a Servlet->forward to JSP->Custom tags in jsp. >>> Pretty standard scenario. >>> >>> On Friday, June 16, 2017 at 4:27:52 PM UTC-4, Achim Nierbeck wrote: >>>> >>>> Ok, >>>> >>>> maybe you can provide a little test project, we could use it as a >>>> sample and as foundation for an integration test. >>>> Sounds like you have a special condition we don't have covered right >>>> now. >>>> So it might be a bug. >>>> >>>> regards, Achim >>>> >>>> >>>> 2017-06-16 22:06 GMT+02:00 Eben Stewart <[email protected]>: >>>> >>>>> I'm using 6.0.6.snapshot >>>>> >>>>> On Friday, June 16, 2017 at 3:10:56 PM UTC-4, Achim Nierbeck wrote: >>>>>> >>>>>> Hi >>>>>> >>>>>> are you looking for this? >>>>>> https://github.com/ops4j/org.ops4j.pax.web/blob/master/sampl >>>>>> es/whiteboard-ds/src/main/java/org/ops4j/pax/web/samples >>>>>> /whiteboard/ds/WhiteboardServletWithContext.java >>>>>> >>>>>> That should work, which version of Pax Web are you using? >>>>>> >>>>>> regards, Achim >>>>>> >>>>>> >>>>>> 2017-06-16 20:25 GMT+02:00 Eben Stewart <[email protected]>: >>>>>> >>>>>>> One step further.... >>>>>>> >>>>>>> This works: >>>>>>> >>>>>>> final HttpContextMapping httpContextMapping = new >>>>>>> HttpContextMapping() { >>>>>>> >>>>>>> static final String HTTP_CONTEXT_ID = "customContext"; >>>>>>> >>>>>>> @Override >>>>>>> public String getHttpContextId() { >>>>>>> return HTTP_CONTEXT_ID; >>>>>>> } >>>>>>> >>>>>>> @Override >>>>>>> public String getPath() { >>>>>>> return "customContext"; >>>>>>> } >>>>>>> >>>>>>> @Override >>>>>>> public Map<String, String> getParameters() { >>>>>>> return null; >>>>>>> } >>>>>>> >>>>>>> @Override >>>>>>> public HttpContext getHttpContext() { >>>>>>> return null; >>>>>>> } >>>>>>> }; >>>>>>> >>>>>>> >>>>>>> Adding that, as well as calling setHttpContextId("customContext") >>>>>>> on both the resourceMapping and jspMapping. >>>>>>> >>>>>>> A servlet also works, but only if I set >>>>>>> >>>>>>> ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID >>>>>>> >>>>>>> instead of >>>>>>> >>>>>>> HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT >>>>>>> >>>>>>> Is this expected behavior? >>>>>>> >>>>>>> On Friday, June 16, 2017 at 11:19:00 AM UTC-4, Eben Stewart wrote: >>>>>>>> >>>>>>>> Ok, still trying to narrow this down to just the JSP >>>>>>>> functionality.... >>>>>>>> >>>>>>>> >>>>>>>> What I am trying to accomplish: >>>>>>>> 1) As many DS-based classes, keeping to OSGI standard annotations >>>>>>>> as much as possible >>>>>>>> 2) use of @Component instead of @WebServlet, so that wiring to OSGI >>>>>>>> components can be done in the servlets using primarily annotations >>>>>>>> (since >>>>>>>> @WebServlet are not OSGI components, they are not included in the >>>>>>>> lifecycle >>>>>>>> - DS annotations do not work) >>>>>>>> 3) must be able to have separate web context roots for multiple >>>>>>>> applications on one server >>>>>>>> 4) and JSPs, preferably with custom tags (using on-the-fly >>>>>>>> compiling w/Jasper) >>>>>>>> >>>>>>>> Here's a real simple setup: a single jsp (/index.jsp) that >>>>>>>> references the tag "layout.tag" in /WEB-INF/tags - NOT tlds >>>>>>>> >>>>>>>> A single Activator class with this start() method: >>>>>>>> >>>>>>>> public void start(final BundleContext bundleContext) throws >>>>>>>> Exception { >>>>>>>> final DefaultResourceMapping rootResourceMapping = new >>>>>>>> DefaultResourceMapping(); >>>>>>>> rootResourceMapping.setAlias("/"); >>>>>>>> rootResourceMapping.setPath(""); >>>>>>>> rootResourceMappingRegistration = >>>>>>>> bundleContext.registerService(ResourceMapping.class, >>>>>>>> rootResourceMapping, null); >>>>>>>> >>>>>>>> final DefaultJspMapping jspMapping = new DefaultJspMapping(); >>>>>>>> jspMappingRegistration = >>>>>>>> bundleContext.registerService(JspMapping.class, >>>>>>>> jspMapping, null); >>>>>>>> } >>>>>>>> >>>>>>>> in root of bundle: >>>>>>>> >>>>>>>> - index.jsp >>>>>>>> - WEB-INF >>>>>>>> - tags >>>>>>>> layout.tag >>>>>>>> >>>>>>>> This all works as expected. localhost:8080/index.jsp properly >>>>>>>> shows the jsp page, including the proper use of the custom tag. >>>>>>>> >>>>>>>> I guess the real question is, how do you properly setup a custom >>>>>>>> context root via HttpContext, without the use of a war? >>>>>>>> >>>>>>>> What's the best practice for getting JSPs to work under a different >>>>>>>> ContextRoot (as this also affects session cookie paths)? How would I >>>>>>>> modify this start() to associate a context root so it works under >>>>>>>> http://localhost:8080/customcontext/index.jsp? >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On Friday, June 16, 2017 at 7:09:56 AM UTC-4, Achim Nierbeck wrote: >>>>>>>>> >>>>>>>>> Ahh .. I already thought you would be running a war project. >>>>>>>>> Good to know that that is actually working. >>>>>>>>> In your case you need to make sure you also have registered the >>>>>>>>> taglibs as resources to your project. >>>>>>>>> Take a look at [1], it should be similar. >>>>>>>>> If that still doesn't seem to work we might hit a bug or something >>>>>>>>> we didn't test yet fully. >>>>>>>>> >>>>>>>>> regards, Achim >>>>>>>>> >>>>>>>>> [1] - https://github.com/ops4j/org.ops4j.pax.web/tree/master/sam >>>>>>>>> ples/helloworld-jsp >>>>>>>>> >>>>>>>>> 2017-06-15 23:06 GMT+02:00 Eben Stewart <[email protected]>: >>>>>>>>> >>>>>>>>>> So it seems a little bit more narrow - it *does* work, but only >>>>>>>>>> when Web-ContextPath is specified in the Manifest (therefore acting >>>>>>>>>> as a >>>>>>>>>> war?) >>>>>>>>>> >>>>>>>>>> However, if using Whiteboard-DS, this is not used, instead a >>>>>>>>>> ServletContextHelper with a >>>>>>>>>> HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH >>>>>>>>>> set is used. It will compile the JSP just fine in the context path, >>>>>>>>>> but >>>>>>>>>> not find the .tag file in the tags directory. >>>>>>>>>> >>>>>>>>>> Or I am configuring/thinking about this the wrong way, which is >>>>>>>>>> certainly plausible. >>>>>>>>>> >>>>>>>>>> Would it be helpful to attach the project zip? >>>>>>>>>> >>>>>>>>>> On Thursday, June 15, 2017 at 2:06:44 PM UTC-4, Achim Nierbeck >>>>>>>>>> wrote: >>>>>>>>>>> >>>>>>>>>>> hmmm ... guess we need to take a closer look at it. >>>>>>>>>>> could you open an issue for that? >>>>>>>>>>> >>>>>>>>>>> regards, Achim >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> 2017-06-15 19:49 GMT+02:00 Eben Stewart <[email protected]>: >>>>>>>>>>> >>>>>>>>>>>> I tried that - Jasper compiler complains about the path not >>>>>>>>>>>> starting with /WEB-INF/ >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> On Thursday, June 15, 2017 at 11:20:48 AM UTC-4, Achim Nierbeck >>>>>>>>>>>> wrote: >>>>>>>>>>>>> >>>>>>>>>>>>> Hi, >>>>>>>>>>>>> >>>>>>>>>>>>> I'm not sure, the only thing that crosses my mind right now >>>>>>>>>>>>> would be the / before the WEB-INF, >>>>>>>>>>>>> could you give it a try without the slash? >>>>>>>>>>>>> >>>>>>>>>>>>> If that still doesn't work out, please open an issue at pax >>>>>>>>>>>>> web for that. >>>>>>>>>>>>> OTH might want to checkout how the jsf and the primefaces >>>>>>>>>>>>> samples are doing this. [1] >>>>>>>>>>>>> >>>>>>>>>>>>> regards, Achim >>>>>>>>>>>>> >>>>>>>>>>>>> [1] - https://github.com/ops4j/org >>>>>>>>>>>>> .ops4j.pax.web/tree/master/samples/war-jsf-primefaces >>>>>>>>>>>>> >>>>>>>>>>>>> 2017-06-14 20:57 GMT+02:00 Eben Stewart <[email protected] >>>>>>>>>>>>> >: >>>>>>>>>>>>> >>>>>>>>>>>>>> Very simple example... tried this under standard WAR/Tomcat >>>>>>>>>>>>>> environment, and it works fine. >>>>>>>>>>>>>> >>>>>>>>>>>>>> In pax-web, using extended DefaultJspMapping class for JSPs, >>>>>>>>>>>>>> directory structure of jar shows index.jsp in the root, and >>>>>>>>>>>>>> layout.tag >>>>>>>>>>>>>> in /WEB-INF/tags. It definitely sees the jsps (with the custom >>>>>>>>>>>>>> tag, they >>>>>>>>>>>>>> work fine) >>>>>>>>>>>>>> >>>>>>>>>>>>>> index.jsp: >>>>>>>>>>>>>> <!DOCTYPE html> >>>>>>>>>>>>>> <%@taglib prefix="my" tagdir="/WEB-INF/tags"%> >>>>>>>>>>>>>> >>>>>>>>>>>>>> <my:layout> >>>>>>>>>>>>>> <jsp:attribute name="body"> >>>>>>>>>>>>>> <div> >>>>>>>>>>>>>> Test >>>>>>>>>>>>>> </div> >>>>>>>>>>>>>> </jsp:attribute> >>>>>>>>>>>>>> </my:layout> >>>>>>>>>>>>>> >>>>>>>>>>>>>> /WEB-INF/tags/layout.tag: >>>>>>>>>>>>>> <!DOCTYPE html> >>>>>>>>>>>>>> <%@tag description="LayoutTemplate" pageEncoding="UTF-8"%> >>>>>>>>>>>>>> <%@attribute name="body" fragment="true" %> >>>>>>>>>>>>>> >>>>>>>>>>>>>> <html> >>>>>>>>>>>>>> <body> >>>>>>>>>>>>>> <jsp:invoke fragment="body"/> >>>>>>>>>>>>>> </body> >>>>>>>>>>>>>> </html> >>>>>>>>>>>>>> >>>>>>>>>>>>>> However, when I attempt to load the page: >>>>>>>>>>>>>> >>>>>>>>>>>>>> org.apache.jasper.JasperException: /index.jsp (line: 4, column: >>>>>>>>>>>>>> 0) No tag "layout" defined in tag library imported with prefix >>>>>>>>>>>>>> "my" >>>>>>>>>>>>>> >>>>>>>>>>>>>> >>>>>>>>>>>>>> Am I missing a directive somewhere? >>>>>>>>>>>>>> >>>>>>>>>>>>>> -- >>>>>>>>>>>>>> -- >>>>>>>>>>>>>> ------------------ >>>>>>>>>>>>>> OPS4J - http://www.ops4j.org - [email protected] >>>>>>>>>>>>>> >>>>>>>>>>>>>> --- >>>>>>>>>>>>>> You received this message because you are subscribed to the >>>>>>>>>>>>>> Google Groups "OPS4J" group. >>>>>>>>>>>>>> To unsubscribe from this group and stop receiving emails from >>>>>>>>>>>>>> it, send an email to [email protected]. >>>>>>>>>>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> -- >>>>>>>>>>>>> >>>>>>>>>>>>> Apache Member >>>>>>>>>>>>> Apache Karaf <http://karaf.apache.org/> Committer & PMC >>>>>>>>>>>>> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> >>>>>>>>>>>>> Committer & Project Lead >>>>>>>>>>>>> blog <http://notizblog.nierbeck.de/> >>>>>>>>>>>>> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS> >>>>>>>>>>>>> >>>>>>>>>>>>> Software Architect / Project Manager / Scrum Master >>>>>>>>>>>>> >>>>>>>>>>>>> -- >>>>>>>>>>>> -- >>>>>>>>>>>> ------------------ >>>>>>>>>>>> OPS4J - http://www.ops4j.org - [email protected] >>>>>>>>>>>> >>>>>>>>>>>> --- >>>>>>>>>>>> You received this message because you are subscribed to the >>>>>>>>>>>> Google Groups "OPS4J" group. >>>>>>>>>>>> To unsubscribe from this group and stop receiving emails from >>>>>>>>>>>> it, send an email to [email protected]. >>>>>>>>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> -- >>>>>>>>>>> >>>>>>>>>>> Apache Member >>>>>>>>>>> Apache Karaf <http://karaf.apache.org/> Committer & PMC >>>>>>>>>>> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> >>>>>>>>>>> Committer & Project Lead >>>>>>>>>>> blog <http://notizblog.nierbeck.de/> >>>>>>>>>>> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS> >>>>>>>>>>> >>>>>>>>>>> Software Architect / Project Manager / Scrum Master >>>>>>>>>>> >>>>>>>>>>> -- >>>>>>>>>> -- >>>>>>>>>> ------------------ >>>>>>>>>> OPS4J - http://www.ops4j.org - [email protected] >>>>>>>>>> >>>>>>>>>> --- >>>>>>>>>> You received this message because you are subscribed to the >>>>>>>>>> Google Groups "OPS4J" group. >>>>>>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>>>>>> send an email to [email protected]. >>>>>>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> -- >>>>>>>>> >>>>>>>>> Apache Member >>>>>>>>> Apache Karaf <http://karaf.apache.org/> Committer & PMC >>>>>>>>> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> >>>>>>>>> Committer & Project Lead >>>>>>>>> blog <http://notizblog.nierbeck.de/> >>>>>>>>> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS> >>>>>>>>> >>>>>>>>> Software Architect / Project Manager / Scrum Master >>>>>>>>> >>>>>>>>> -- >>>>>>> -- >>>>>>> ------------------ >>>>>>> OPS4J - http://www.ops4j.org - [email protected] >>>>>>> >>>>>>> --- >>>>>>> You received this message because you are subscribed to the Google >>>>>>> Groups "OPS4J" group. >>>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>>> send an email to [email protected]. >>>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> >>>>>> Apache Member >>>>>> Apache Karaf <http://karaf.apache.org/> Committer & PMC >>>>>> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> >>>>>> Committer & Project Lead >>>>>> blog <http://notizblog.nierbeck.de/> >>>>>> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS> >>>>>> >>>>>> Software Architect / Project Manager / Scrum Master >>>>>> >>>>>> -- >>>>> -- >>>>> ------------------ >>>>> OPS4J - http://www.ops4j.org - [email protected] >>>>> >>>>> --- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "OPS4J" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to [email protected]. >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> >>>> >>>> -- >>>> >>>> Apache Member >>>> Apache Karaf <http://karaf.apache.org/> Committer & PMC >>>> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> >>>> Committer & Project Lead >>>> blog <http://notizblog.nierbeck.de/> >>>> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS> >>>> >>>> Software Architect / Project Manager / Scrum Master >>>> >>>> -- >>> -- >>> ------------------ >>> OPS4J - http://www.ops4j.org - [email protected] >>> >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "OPS4J" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> >> Apache Member >> Apache Karaf <http://karaf.apache.org/> Committer & PMC >> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer >> & Project Lead >> blog <http://notizblog.nierbeck.de/> >> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS> >> >> Software Architect / Project Manager / Scrum Master >> >> -- > -- > ------------------ > OPS4J - http://www.ops4j.org - [email protected] > > --- > You received this message because you are subscribed to the Google Groups > "OPS4J" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- Apache Member Apache Karaf <http://karaf.apache.org/> Committer & PMC OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer & Project Lead blog <http://notizblog.nierbeck.de/> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS> Software Architect / Project Manager / Scrum Master -- -- ------------------ OPS4J - http://www.ops4j.org - [email protected] --- You received this message because you are subscribed to the Google Groups "OPS4J" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
