>>>>> Steinar Bang <[email protected]>:

>> [2] - 
>> https://github.com/ops4j/org.ops4j.pax.web/blob/master/pax-web-itest/pax-web-itest-container/pax-web-itest-container-jetty/src/test/java/org/ops4j/pax/web/itest/jetty/WhiteboardServletAnnotatedIntegrationTest.java

> I'm currently in the process of transforming my eaxample webapp from war
> to jar.
>  https://github.com/steinarb/ukelonn/tree/using-vaadin/ukelonn.bundle

> Ie. making the webapp bundle a regular OSGi bundle with a regular
> internal layout, not a WAR-type layout.

> The regular bundle will register the servlet by having the activator
> listen for the WebContainer service and registering the servlet on
> that.

This turned out to be quite easy
 
https://github.com/steinarb/ukelonn/blob/scratch/using-vaadin-jar-with-webcontainer-injection/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/impl/UkelonnServiceProvider.java#L80

> Once I've got that approach up and working I will look into reversing
> the approach, ie. try to expose a service like in [2] above.

This, on the other hand has turned out to be not so easy...:-)

What I did, was:
 - Expose the shiro EventLoaderListener as an OSGi service
 - Expose the shiro filter as an OSGi service
 - Expose the servlet as an OSGi service

This worked, as far as having all of the services start and be picked up
by the pax whiteboard extender, e.g. like so:
 karaf@root()> bundle:capabilities 72
 no.priv.bang.ukelonn [72] provides:
 -----------------------------------
 osgi.wiring.bundle; no.priv.bang.ukelonn 1.0.0.SNAPSHOT [UNUSED]
 osgi.wiring.host; no.priv.bang.ukelonn 1.0.0.SNAPSHOT [UNUSED]
 osgi.identity; no.priv.bang.ukelonn 1.0.0.SNAPSHOT [UNUSED]
 service; [java.util.EventListener] with properties:
    service.bundleid = 72
    service.id = 173
    service.scope = singleton
    Used by:
       org.ops4j.pax.web.pax-web-extender-whiteboard [114]
 service; [javax.servlet.Filter] with properties:
    httpContext.path = /ukelonn
    service.bundleid = 72
    service.id = 176
    service.scope = singleton
    servletNames = ukelonn
    urlPatterns = [/*]
    Used by:
       org.ops4j.pax.web.pax-web-extender-whiteboard [114]
 service; [javax.servlet.Servlet] with properties:
    alias = /
    httpContext.path = /ukelonn
    service.bundleid = 72
    service.id = 177
    service.scope = singleton
    servletNames = ukelonn
    Used by:
       org.ops4j.pax.web.pax-web-extender-whiteboard [114]

However, it didn't actually work.

The problem is that the EventloaderListener has to be started first, and
that it needs to receive an actual event, before the filter can be
created.  If not, I see this message in the karaf.log (as well as having
nothing actually working):
 2017-06-30T14:18:12,760 | ERROR | Thread-49        | WebApplication            
       | 114 - org.ops4j.pax.web.pax-web-extender-whiteboard - 6.0.3 | 
Registration skipped for [FilterWebElement{mapping=DefaultFilterMapping 
[httpContextId=null, filter=org.ops4j.pax.web.service.spi.model.FilterModel-23, 
urlPatterns=[/*], servletNames=[ukelonn], initParams={service.id=179, 
servletNames=ukelonn, urlPatterns=[Ljava.lang.String;@14304ee, 
httpContext.path=/ukelonn, objectClass=[Ljava.lang.String;@6db98b5, 
service.scope=singleton, service.bundleid=72}, asyncSupported=false]}] due to 
error during registration
 java.lang.RuntimeException: javax.servlet.ServletException: 
java.lang.IllegalStateException: No WebEnvironment found: no 
EnvironmentLoaderListener registered?

I tried putting an dependency for the EnvironmentLoaderListener OSGi
service in the filter service, but that has two problems:
 1. The EnvironmentLoaderListener is registered as an EventListener OSGi
    service and that injection could potentially be satisfied by a
    different EventListener
 2. Even if the EnvironmentLoaderListener is the actual EventLoader
    injected (and it has been when I have been debugging this) having
    the service up and running doesn't necessarily mean that a
    WebEnvironment can be found, because the WebEnvironment is created
    when the EnviromentLoaderListener receives a ServletContextEvent

I've been scratching my head for a while figuring out how to best
accomplish this, and haven't come up with something that works yet.

All hints and tips are appreciated.

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