diff --git a/undertow/src/main/java/com/baeldung/undertow/socket/SocketServer.java b/undertow/src/main/java/com/baeldung/undertow/socket/SocketServer.java index 9e0e065c3a..295586e16f 100644 --- a/undertow/src/main/java/com/baeldung/undertow/socket/SocketServer.java +++ b/undertow/src/main/java/com/baeldung/undertow/socket/SocketServer.java @@ -16,15 +16,7 @@ public class SocketServer { public static void main(String[] args) { Undertow server = Undertow.builder().addHttpListener(8080, "localhost") .setHandler(path().addPrefixPath("/baeldungApp", websocket((exchange, channel) -> { - channel.getReceiveSetter().set(new AbstractReceiveListener() { - @Override - protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) { - final String messageData = message.getData(); - for (WebSocketChannel session : channel.getPeerConnections()) { - WebSockets.sendText(messageData, session, null); - } - } - }); + channel.getReceiveSetter().set(getListener()); channel.resumeReceives(); })).addPrefixPath("/", resource(new ClassPathResourceManager(SocketServer.class.getClassLoader(), SocketServer.class.getPackage())).addWelcomeFiles("index.html"))) @@ -33,4 +25,16 @@ public class SocketServer { server.start(); } + private static AbstractReceiveListener getListener() { + return new AbstractReceiveListener() { + @Override + protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) { + final String messageData = message.getData(); + for (WebSocketChannel session : channel.getPeerConnections()) { + WebSockets.sendText(messageData, session, null); + } + } + }; + } + }