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<https://github.com/eclipse/jetty.project/blob/jetty-9.1/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/JsrCreator.java>,
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!?
The support for JSR356 is added to the Jetty WebSocket API via the
EventDriverFactory
mechanism<https://github.com/eclipse/jetty.project/blob/jetty-9.1/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java#L52-L55>when
the javax.websocket.server.ServerContainer.

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.




--
Joakim Erdfelt <[email protected]>
webtide.com <http://www.webtide.com/> - intalio.com/jetty
Expert advice, services and support from from the Jetty & CometD experts
eclipse.org/jetty - cometd.org


On Fri, Nov 1, 2013 at 5:05 PM, Brandon Mintern <[email protected]> wrote:

> It surprised me that I could not return a javax.websocket.Endpoint from
> the WebSocketCreator.createWebSocket method. Where can I plug into Jetty in
> order to construct and return a custom Endpoint object that will manage my
> WebSocket interaction?
>
> Thanks,
> Brandon
>
> _______________________________________________
> jetty-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
>
_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to