Skip to content

How to use path parameters encoded in WebSocket url ? #395

Description

@kant111

currently there seems to be no way to specify path parameters in the WebSocket URL in undertow or jetty. I currently use undertow.

My use case is I have list of names and I would like to create a generic route that will take "name" as a path parameter so I can just have one handler for the whole list of names I got.

For example I want to be able to do something like below:

addWebSocket("/hello/{name}", (webSocketContext, message) -> {
    try {
        somehow get the value that is passed in for ":name" here
        webSocketContext.sendMessage(message);
    } catch (IOException e) {
        e.printStackTrace();
    }
});

To elaborate even further, I am trying to broadcast a messages for all the clients that are listening on specific endpoint. so if I have something like below I wan to be able to broadcast all messages that have a connection opened on "/hello/foo" endpoint. so here my "{name}" = "foo" but I can pass anything from the list of names I have in which case I want to be able to pass name as path parameter.

addWebSocket("/hello/foo", (webSocketContext, message) -> {
    try {
        so ":name" = "foo" here
        webSocketContext.sendMessage(message);
    } catch (IOException e) {
        e.printStackTrace();
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions