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/samples/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.