Well ...
Pure Jetty WebSocket API Use
WebSocketCreator is a Jetty WebSocket API (predates the javax.websocket standard)
If you want to use WebSocketCreator, then you should return an object that either
- implements org.eclipse.jetty.websocket.api.WebSocketListener
- is annotated with org.eclipse.jetty.websocket.api.annotations.WebSocket
Pure javax.websocket API Use
However, if you want to use the javax.websocket standard (aka JSR-356), you have a different approach you can use.
Start by creating an object that implements javax.websocket.server.ServerEndpointConfig.Configurator.
eg:
public class MyCreator implements ServerEndpointConfig.Configurator
Be careful to implement the following methods.
- checkOrigin(String originHeader)
- modifyHandshake(ServerEndpointConfig sec, HandshakeRequest req, HandshakeResponse resp)
- getEndpointInstance(Class endpointClass)
Then on your annotated websocket reference this custom configurator.
@ServerEndpoint(value="/path", configurator=MyCreator.class)
The Deep Dark Underbelly of WebSocket in Jetty
Internally to Jetty, the entire javax.websocket support layer is built on top of the Pure Jetty WebSocket API.
Just to prove this point,
here's the JsrCreator, the implementation of WebSocketCreator that does all of the work necessary to support the javax.websocket API.
But you might be asking, how can you return a javax.websocket from that!?
As you can see, it is possible to use the WebSocketCreator pattern to make javax.websocket Endpoints, however, it requires a lot more work to wire up the JSR specifics.