Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Handle websocket upgrade request from inside Servlet#service (Jetty 12)

Thanks Joakim for the response.

Very interesting, this is about the exact same code I was using in Jetty11 and which I got to compile with Jetty12 by just changing some imports and the type for the endpoint.

But then I am back with some issues I had earlier on. I was assuming this was because I was using some deprecated stuff and had to convert to the code in the documentation examples.

The first issue is that the call to socketContainer.upgrade(socketCreator,request,response)

logs a

2023-10-19 13:03:04.628:WARN :oeju.Blocker:qtp1582071873-35: Blocking.Callback incomplete

for every request that is not an upgrade request. The second problem is that when the upgrade request does come in and the endpoint object (which now extends Session.Listener) the next exception occurs:

org.eclipse.jetty.websocket.api.exceptions.InvalidWebSocketException: Cannot replace previously assigned [TEXT Handler] at MethodHandle(ObjectSocketAdapter,String,boolean)void with public void nl.idfix.scriptlet.scripts.handlers.ScriptHandler$ObjectSocketAdapter.onWebSocketText(java.lang.String)
    at org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerMetadata.assertNotSet(
    at org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerMetadata.setTextHandle(
    at org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerFactory.createListenerMetadata(
    at org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerFactory.createMetadata(
    at org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerFactory.getMetadata(
    at org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerFactory.newJettyFrameHandler(
    at org.eclipse.jetty.ee10.websocket.server.internal.JettyServerFrameHandlerFactory.newFrameHandler(
    at org.eclipse.jetty.websocket.core.server.internal.CreatorNegotiator.negotiate(
    at org.eclipse.jetty.websocket.core.server.internal.AbstractHandshaker.upgradeRequest(
    at org.eclipse.jetty.websocket.core.server.internal.HandshakerSelector.upgradeRequest(
    at org.eclipse.jetty.websocket.core.server.WebSocketMappings.upgrade(
    at org.eclipse.jetty.ee10.websocket.server.JettyWebSocketServerContainer.upgrade(
Earlier on I posted this and you then asked me

Does your `_socketCreator = new SocketCreator` return an Endpoint 100% of the time?

and the answer to that is yes.

The class extending JettySocketCreator implements createWebSocket by passing the underlying jettyServerUpgradeRequest.httpServletRequest to application level code which then is expected to return an EndPoint. In this case this application level code does return an object that implements Session.Listener just before the exception occurs.

Thanks very much for all the help.



On 16-10-2023 17:19, Joakim Erdfelt wrote:
Also, for Jetty WebSocket API on EE10 take a look at this test class for inspiration.

Joakim Erdfelt / joakim@xxxxxxxxxxx

On Mon, Oct 16, 2023 at 10:01 AM Silvio Bierman via jetty-users <jetty-users@xxxxxxxxxxx> wrote:
Hallo all,

I am porting an existing embedded Jetty application from Jetty11 to
Jetty12. Since 12.0.2 everything seems to be working perfectly except
for one thing I have not yet been able to port: our applications usage
of the Jetty WebSocket API.

The Jetty12 WebSocket API documentation shows the upgrade being done
inside the Handler#handle method using the
org.eclipse.jetty.server.Request / org.eclipse.jetty.server.Response
objects available there. However, in our application code the
information required to create the endpoint object is only known inside
the Servlet instance. In the Jetty11 API we where able to upgrade the
request from inside the Servlet#service method because the
JettyWebSocketServerContainer#upgrade took
HttpServletRequest/HttpServletResponse parameters. In the Jetty12
WebSocket API ServerWebSocketContainer#upgrade these have been replaced
by above mentioned Request/Response objects.

Is there a way around this?

Kind regards,


jetty-users mailing list
To unsubscribe from this list, visit

Back to the top