Hello

Sorry for late answer. There's testListenersWithHttpContext() test here:
https://github.com/ops4j/org.ops4j.pax.web/blob/pax-web-7.2.x/pax-web-itest/pax-web-itest-common/src/main/java/org/ops4j/pax/web/itest/common/AbstractWhiteboardR6IntegrationTest.java#L289

It does exactly what you're trying to achieve, but without SCR - only by
registering relevant services. You can run the test from within any of
three container itest projects:

mvn clean verify -f
pax-web-itest/pax-web-itest-container/pax-web-itest-container-jetty/
-Dit.test=WhiteboardR6IntegrationTest#testListenersWithHttpContext
mvn clean verify -f
pax-web-itest/pax-web-itest-container/pax-web-itest-container-tomcat/
-Dit.test=WhiteboardR6IntegrationTest#testListenersWithHttpContext
mvn clean verify -f
pax-web-itest/pax-web-itest-container/pax-web-itest-container-undertow/
-Dit.test=WhiteboardR6IntegrationTest#testListenersWithHttpContext

I'm not sure what may be your problem (maybe you'll share your maven
project via github?) - but this may be related to some other bundles you
have installed in your runtime (pure Equinox? pax-exam test? Karaf based on
Equinox?) - which may cause problems with finding services you register by
pax-web-extender-whiteboard.

best regards
Grzegorz Grzybek

pon., 24 wrz 2018 o 22:13 Nhut Thai Le <[email protected]> napisaƂ(a):

> Hello,
>
> I tried to hook a servletContextListener to my custom ServletContextHelper
> but the contextInitialized method is not called.
> -------------------Here is my ServletContextHelper:------------
> @Component(
> service = ServletContextHelper.class,
> property = {
> "osgi.http.whiteboard.context.name=ZkComponentsServletContextHelper",
> "osgi.http.whiteboard.context.path=/components"
> }
> )
> public class ZkComponentsServletContextHelper extends ServletContextHelper
> {...}
> --------------------------------My ServletContextListener----------
> @Component(
> name="ZkListener",
> service= {
> ServletContextListener.class
> },
> property= {
> "osgi.http.whiteboard.listener=true",
> "osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name
> =ZkComponentsServletContextHelper)"
> }
> )
> public final class ZkSessionListener implements ServletContextListener {
> private WebManager webManager;
>
> @Override
> public void contextInitialized(ServletContextEvent sce) {
> final ServletContext ctx = sce.getServletContext();
> if (WebManager.getWebManagerIfAny(ctx) == null) {
> webManager = new WebManager(ctx, "/zkau");
> } else {
> throw new IllegalStateException("ZK WebManager already exists. Could not
> initialize via Spring Boot configuration.");
> }
> }
> ------------------------------Finally, my simple servlet-------------
> @Component(
> service = Servlet.class,
> property= {
> "osgi.http.whiteboard.servlet.pattern=*.zul",
> "osgi.http.whiteboard.servlet.pattern=*.zhtml",
> "osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name
> =ZkComponentsServletContextHelper)"
> }
> )
> public class ZulExtensionServlet extends HttpServlet{..}
> ---------------------equinox bundle info-------------
> {org.osgi.service.http.context.ServletContextHelper}={service.id=95,
> osgi.http.whiteboard.context.name=ZkComponentsServletContextHelper,
> service.bundleid=59, service.scope=bundle, 
> component.name=com.castortech.iris.zk.components.ZkComponentsServletContextHelper,
> osgi.http.whiteboard.context.path=/components, component.id=3}
>
> {javax.servlet.Servlet}={service.id=97, service.bundleid=59,
> service.scope=bundle, osgi.http.whiteboard.servlet.pattern=[*.zul,*.zhtml],
> osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=ZkComponentsServletContextHelper),
> component.name=com.castortech.iris.zk.components.ZulExtensionServlet,
> component.id=5}
>
> {javax.servlet.ServletContextListener}={service.id=98,
> service.bundleid=59, service.scope=bundle,
> osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=ZkComponentsServletContextHelper),
> osgi.http.whiteboard.listener=true, component.name=ZkListener,
> component.id=6}
>
> {javax.servlet.ServletContext}={osgi.web.version=1.0.0.qualifier,
> osgi.web.contextpath=/components, service.id=124,
> osgi.web.symbolicname=com.castortech.iris.zk.components,
> service.bundleid=59, service.scope=singleton,
> osgi.web.contextname=ZkComponentsServletContextHelper}
>
>
> As you can see, both the ServletContextListener and the servlet are bound
> to the same ServletContextHelper and there is a ServletContext created from
> the ServletContextHelper, however, the contextInitialized method was never
> called. Am I missing anything?
>
> Thai
>
> --
> --
> ------------------
> 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.
>

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

Reply via email to