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)

If you are using jakarta.websocket you can use the new method ...
void jakarta.websocket.server.ServerContainer.upgradeHttpToWebSocket(Object httpServletRequest, Object httpServletResponse, 
    ServerEndpointConfig sec, Map<String, String> pathParameters) throws IOException, DeploymentException

If you are using the Jetty WebSocket API ...

The endpoint is created with a registered org.eclipse.jetty.ee10.websocket.server.JettyWebSocketCreator.

First, ask yourself what kind of information do you need from the HttpServletRequest / HttpServletResponse that requires you to go through an HttpServlet?
If it can be handled via a JettyWebSocketCreator, use that.
Note that you do have access to the HttpServletRequest in that class.

Otherwise you'll have to implement your own custom version of the JettyWebSocketServlet.
https://github.com/jetty/jetty.project/blob/jetty-12.0.x/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jetty-server/src/main/java/org/eclipse/jetty/ee10/websocket/server/JettyWebSocketServlet.java

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,

Silvio

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users

Back to the top