Skip to content

Conversation

@decebals
Copy link
Member

@decebals decebals commented Sep 28, 2017

This PR contains a functional POC (prof of concept) for #395.
The code works but need some adjustment.

For Undertow:

addWebSocket("/ws/chat/{room}", (webSocketContext, message) -> {
    WebSocketConnection connection = webSocketContext.getConnection();
    // cast WebSocketConnection to UndertowWebSocketConnection
    UndertowWebSocketConnection undertowConnection = (UndertowWebSocketConnection) connection;
    String remoteAddress = undertowConnection.getRemoteAddress().toString();
    System.out.println("remoteAddress = " + remoteAddress);
    WebSocketHttpExchange exchange = undertowConnection.getExchange();
    String query = exchange.getQueryString();
    System.out.println("query = " + query);
});

For Jetty the code is similar with the code presented in #360 (comment).

Also this PR comes with a hidden nice feature, UriMatcher with DefaultUriMatcher. So, the DefaultRouter was spitted in two parts. It's more easy to implement a custom router with uri matcher (maybe some one wants another notation for path parameters or supply a more fast uri matching algorithm).

In WebSocketContext you will can access the parameters value (I have already these information), similar with the approach used in Request. Also, WebSocketContext will contain other information like session, request header.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 18.838% when pulling 7034579 on websocket_improve into aefdfe9 on master.

@kant111
Copy link

kant111 commented Oct 1, 2017

How to access the value for "room" in the above url? Can we have annotations similar to the HTTP route handling in pippo.

@decebals
Copy link
Member Author

decebals commented Oct 2, 2017

How to access the value for "room" in the above url?

The path parameters are available in WebSocketMatch. The easy mode to expose these parameters is via WebSocketContext (add a method, eventually use ParameterValue as wrapper - to have conversion methods - similar with Request class)

Can we have annotations similar to the HTTP route handling in pippo.

Do you talk about pippo-controller?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 19.153% when pulling 96824ef on websocket_improve into aefdfe9 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 19.126% when pulling 9c98d5a on websocket_improve into aefdfe9 on master.

@decebals
Copy link
Member Author

@kant111

How to access the value for "room" in the above url?

You can use WebSocketContext.getPathParameter(String name).

My work on this feature is done. If everything is OK, I will merge this PR and I will release a new version.

@kant111
Copy link

kant111 commented Nov 10, 2017

@decebals Thanks much! I went with another framework because of deadlines but appreciate your effort! will try to consider Pippo next time when I get an opportunity!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants