Skip to content

Instantly share code, notes, and snippets.

@danielkec
Last active May 31, 2022 09:39
Show Gist options
  • Save danielkec/51675ec9e564a67a2f990b1e874a02da to your computer and use it in GitHub Desktop.
Save danielkec/51675ec9e564a67a2f990b1e874a02da to your computer and use it in GitHub Desktop.
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