Last active
May 31, 2022 09:39
-
-
Save danielkec/51675ec9e564a67a2f990b1e874a02da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
WebServer.builder( | |
Routing.builder() | |
.register("/ws", TyrusSupport.builder() | |
.register(ServerEndpointConfig.Builder.create(WsEndpoint.class, "/echo").build()) | |
.build() | |
) | |
) | |
.port(8080) | |
.tls(WebServerTls.builder() | |
.privateKey(KeyConfig.keystoreBuilder() | |
.keystorePassphrase("password") | |
.keystore(Resource.create("server.p12")) | |
.build())) | |
.build() | |
.start(); | |
} | |
public static class WsEndpoint extends Endpoint { | |
@Override | |
public void onOpen(Session session, EndpointConfig config) { | |
var remote = session.getBasicRemote(); | |
session.addMessageHandler(new MessageHandler.Partial<String>() { | |
@Override | |
public void onMessage(String message, boolean last) { | |
try { | |
remote.sendText("Did you say " + message + "?"); | |
remote.flushBatch(); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment