Hello,
We are trying to use both SSE and HTTP/2.0 features of Undertow. The idea
is to open an SSE connection with HTTP/2.0 as protocol.
We've tried with the following piece of code:
____________________________________________
ServerSentEventHandler sseHandler;
sseHandler = new ServerSentEventHandler(new
SseConnectionCallback(source));
String bindAddress = System.getProperty("bind.address",
"localhost");
SSLContext sslContext =
createSSLContext(loadKeyStore("server.keystore"),
loadKeyStore("server.truststore"));
Undertow server = Undertow.builder()
.setServerOption(UndertowOptions.ENABLE_HTTP2, true)
.setServerOption(UndertowOptions.ENABLE_SPDY, true)
.addHttpsListener(8443, bindAddress, sslContext)
.setHandler(path().addPrefixPath("/sse",
sseHandler))
.build();
server.start();
____________________________________________
But when connecting to
https://localhost:8443/sse, nothing happens in the
client side while we are sending into the ServerSentEventConnection data
every 5 seconds
We think it is related to the HTTP/2.0 frame stuff but we are not sure
about this hypothesis.
On the other hand, we have modified the ServerSentEventConnection to expose
a flush() method that calls the underlying flush() of its sink.
____________________________________________
public class ServerSentEventConnection implements Channel, Attachable {
...
public boolean flush() throws IOException {
return this.sink.flush();
}
}
____________________________________________
And somewhere in our callback, we do:
____________________________________________
public class SseConnectionCallback implements
ServerSentEventConnectionCallback {
...
if (connection.isOpen()) {
connection.send(data, "data", UUID.randomUUID().toString(),
new ServerSentEventConnection.EventCallback() {
@Override
public void done(ServerSentEventConnection aConnection,
String aData, String aEvent, String aId) {
LOGGER.info("Sent!");
try {
connection.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void failed(ServerSentEventConnection
aConnection, String aData, String aEvent, String aId, IOException e) {
LOGGER.info("failed!");
}
});
}
____________________________________________
And we get the SSE events on the client side. So, we were wondering whether
our solution was right or whether there is another solution for our issue.
Thanks in advance!
Best regards,
Cédric.