Hi,

- My WebSocketServlet subclass is registered as an OSGi (Declarative Services) 
component, so it is instantiated, during OSGi framework startup.
- Since it has declared that it needs an instance of HttpService (implemented 
using Jetty in Equinox), it is first bound to such an instance.
- My WebSocketServlet then registers itself as a Servlet with this HttpService 
instance using the HttpService.registerServlet method.
- During the call to registerServlet the WebSocketServlet seems to be 
registered with the OSGi framework as a Servlet service, and so-called 
ServiceTrackers are notified.
- One of these ServiceTrackers finally call WebSocketServerFactory’s init 
method, and as you show, the ContextHandler’s getContextHandler method returns 
null, hence the 'Not running on Jetty, WebSocket support unavailable’ exception.
- At this point the stack is as follows:

at 
org.eclipse.jetty.websocket.server.WebSocketServerFactory.init(WebSocketServerFactory.java:373)

at 
org.eclipse.jetty.websocket.servlet.WebSocketServlet.init(WebSocketServlet.java:136)

at javax.servlet.GenericServlet.init(GenericServlet.java:244)

at 
org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl$LegacyServlet.init(HttpServiceRuntimeImpl.java:1215)

at 
org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.init(EndpointRegistration.java:95)

at 
org.eclipse.equinox.http.servlet.internal.context.ContextController.doAddServletRegistration(ContextController.java:563)

at 
org.eclipse.equinox.http.servlet.internal.context.ContextController.addServletRegistration(ContextController.java:449)

at 
org.eclipse.equinox.http.servlet.internal.customizer.ContextServletTrackerCustomizer.addingService(ContextServletTrackerCustomizer.java:55)

at 
org.eclipse.equinox.http.servlet.internal.customizer.ContextServletTrackerCustomizer.addingService(ContextServletTrackerCustomizer.java:1)

at 
org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)

at 
org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)

at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)

at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)

at 
org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)

at 
org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)

at 
org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:915)

at 
org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)

at 
org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)

at 
org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)

at 
org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)

at 
org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)

at 
org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)

at 
org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:464)

at 
org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:482)

at 
org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:999)

at 
org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl.registerHttpServiceServlet(HttpServiceRuntimeImpl.java:733)

at 
org.eclipse.equinox.http.servlet.internal.HttpServiceImpl$3.run(HttpServiceImpl.java:147)

at 
org.eclipse.equinox.http.servlet.internal.HttpServiceImpl$3.run(HttpServiceImpl.java:1)

at java.security.AccessController.doPrivileged(Native Method)

at 
org.eclipse.equinox.http.servlet.internal.HttpServiceImpl.registerServlet(HttpServiceImpl.java:144)

at 
no.hal.eclipsky.services.sourceeditor.SourceEditorServletImpl.activate(SourceEditorServletImpl.java:111)

I cannot say why there is no ContextHandler, but it may well be that the 
sequence of calls initiated by OSGi cause the problem.

I’m not sure if it’s relevant, but just before the call to registerServlet, I 
set the Thread’s context class loader to the the class loader used for the 
WebSocketServerFactory, as follows:

Thread.currentThread().setContextClassLoader(WebSocketServerFactory.class.getClassLoader());

If I don’t, I get a ClassNotFoundException for WebSocketServerFactory.

Hallvard
From: <[email protected]<mailto:[email protected]>> 
on behalf of Joakim Erdfelt <[email protected]<mailto:[email protected]>>
Reply-To: JETTY user mailing list 
<[email protected]<mailto:[email protected]>>
Date: Tuesday 8 March 2016 01:10
To: JETTY user mailing list 
<[email protected]<mailto:[email protected]>>
Subject: Re: [jetty-users] Using WebSockets in Equinox

The `Not running on Jetty, WebSocket support unavailable` is from the check 
here ...

https://github.com/eclipse/jetty.project/blob/jetty-9.3.7.v20160115/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerFactory.java#L375-L381

And ContextHandler.getContextHandler(context) is this code ...

https://github.com/eclipse/jetty.project/blob/jetty-9.3.7.v20160115/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java#L149-L157

Is there something special about OSGi which is getting in the way here?

Joakim Erdfelt / [email protected]<mailto:[email protected]>

On Mon, Mar 7, 2016 at 4:45 PM, Hallvard Trætteberg 
<[email protected]<mailto:[email protected]>> wrote:
Hi,

I’ve been using the WebSocket support of Jetty 8 within the Equinox OSGi 
framework for a while, but now have to upgrade to Jetty 9 and the newer API. 
Changing to using WebSocket annotations wasn’t difficult, but I have problems 
getting the system as a whole to run.

When developing, I install all the necessary Jetty bundles into Eclipse (the 
Neon M4), either install the Equinox target components or manually using the 
dropins folder. Then I launch a second Eclipse for testing. I managed to do 
this with Jetty 9.2.12, but ended up with class loading issues. I then upgraded 
to Jetty 9.3.5 only to get the message javax.servlet.ServletException: Not 
running on Jetty, WebSocket support unavailable.

According to 
http://www.eclipse.org/jetty/documentation/current/framework-jetty-osgi.html I 
should be able to get the Jetty container running with the Equinox container by 
using the org.eclipse.jetty.osgi.boot bundle. I add it to the dropins folder, 
but it never shows up in the Eclipse plugin view or can be selected as part of 
the plugins in the target or launch configuration for the runtime Eclipse 
instance. I’ve tried looking for it using the OSGi console, and all the other 
Jetty bundles show up, but not org.eclipse.jetty.osgi.boot. It’s fairly common 
to se a bundle hasn’t resolved or started, e.g. when a dependency isn’t 
satisfied, but this bundle doesn’t seem to be installed, even though it’s in 
the dropins folder, with the other Jetty WebSocket bundles. And I still get the 
"Not running on Jetty, WebSocket support unavailable” message.

I know I can revert to using the plain OSGi HttpService and using simple 
requests, but WebSockets should improve the performance, so I’d rather use them.

Any suggestions?

Regards,

Hallvard Trætteberg
---
Hallvard Trætteberg ([email protected]<mailto:[email protected]>)
Associate Professor, IS group, Dept. of Computer and Information Science at the
Norwegian Univ. of Science and Technology




_______________________________________________
jetty-users mailing list
[email protected]<mailto:[email protected]>
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to