Wicket Native WebSocketsPage added by Martin GrigorovWicket Native WebSocketsWhat ?Since version 6.0 Wicket provides an experimental module that provides integration with WebSocket support in the web containers like Jetty and Tomcat. How it works ?Each of the integrations provide a custom implementation of org.apache.wicket.protocol.http.WicketFilter that first checks whether the current web request needs to upgrade its protocol from HTTP to WebSocket. This is done by checking the request headers for the special header with name "Upgrade". If the request is an upgrade then the filter registers an endpoint for the web socket connection. Later this endpoint is used to read/write messages from/to the client. How to use it ?Add org.apache.wicket.protocol.ws.api.WebSocketBehavior to the page that will use web socket communication: MyPage.java public class MyPage extends WebPage { public MyPage() { add(new WebSocketBehavior() { @Override protected void onMessage(WebSocketRequestHandler handler, TextMessage message) { } }); } } Use message.getText() to read the message sent by the client and use the passed handler.push(String) to push a text message to the connected client. Additionally you can use handler.add(Component...) to add Wicket components for re-render, handler#prependJavaScript(CharSequence) and handler#appendJavaScript(CharSequence) as you do with AjaxRequestTarget. Differences with Wicket-Atmosphere module.Wicket-Atmosphere provides integration with Atmosphere and let it handle the inconsistencies in WebSocket protocol support in different browsers and web containers. If either the browser or the web container do not support WebSockets then Atmosphere will downgrade (depending on the configuration) to either long-polling, streaming, server-side events, jsonp, ... to simulate the long running connection. Wicket Native WebSocket uses only WebSocket connections, so it wont work for browsers and web containers which do not support WebSockets. There are no plans to add such support in future. Use it only if you really know that you will run your application in an environment that supports WebSockets. Currently supported web containers are Jetty 7.5+ and Tomcat 7.0.27+.
Change Notification Preferences
View Online
|
Add Comment
|
