I found a solution, so I answer my own question:
The WebsocketContainer can be configured with an ClientEndpointConfig. This allows to set a custom SSLContext. Then client certificate must be attached to the SSLContext. Code:
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
container.setDefaultMaxTextMessageBufferSize(BUFFER_SIZE);
container.connectToServer(new PojoEndpointClient(this, new ArrayList<>()), createClientConfig(), endpointURI);
And the ClientEndpointConfig can be constructed like this:
private ClientEndpointConfig createClientConfig() throws KeyManagementException, UnrecoverableKeyException,
NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
ClientEndpointConfig config = builder.decoders(new ArrayList<>()).encoders(new ArrayList<>())
.preferredSubprotocols(new ArrayList<>()).build();
SSLContext sslContext = SSLContexts.custom().loadKeyMaterial(clientCert.toFile(), clientCertPassword,
clientCertPassword, (aliases, socket) -> aliases.keySet().iterator().next()).build();
config.getUserProperties().put(Constants.SSL_CONTEXT_PROPERTY, sslContext);
return config;
}
This will present the client certificate to the server when establishing the websocket connection.