Register ServletRequestListener from OSGi Bundle

201 Views Asked by At

I have a JSR-356 (WebSocket API) code that is packaged in an OSGi bundle. The servlet loads the code via Apache Felix if needed.

I want to register a ServletRequestListener, which I would normally put in the web descriptor:

<listener>
  <listener-class>path.to.my.RequestListener</listener-class>
</listener>

but since the bundle is not in the classpath that wouldn't work.

How can I register the ServletRequestListener? I am thinking that maybe there would be a way with scanning for annotations but am not sure how to set that up. My other concern is that many users disable the scanning to improve startup time.

The listener's job is to initialize HttpSession so that I can retrieve the ServletContext in the WebSocket handshake. If there's a way to achieve that without the listener then that will work for me even better.

1

There are 1 best solutions below

1
On

Not sure if this can be solved completely with specs. Pax web has websocket support. So maybe this can help you:

See pax web websocket example