Skip to content

Commit

Permalink
enables reconnect including REST GET for abnormally closed websockets
Browse files Browse the repository at this point in the history
Enables the use of the re-connector code for abnormally closed websocket
connections. The (re-)connector searches for Subscription resources,
downloads existing Task and QuestionnaireResponse resources before
establishing the Task and QuestionnaireResponse websocket connections.

Fixes #233
  • Loading branch information
hhund committed Oct 7, 2024
1 parent ef240cb commit 5ee060b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.dsf.fhir.client;

import java.util.EnumSet;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand Down Expand Up @@ -80,7 +81,8 @@ public void onClose(Session session, CloseReason closeReason)
logger.warn("Websocket closed, session {}: {} - {}", session.getId(), closeReason.getCloseCode().getCode(),
closeReason.getReasonPhrase());

if (CloseReason.CloseCodes.CANNOT_ACCEPT.equals(closeReason.getCloseCode()))
if (EnumSet.of(CloseReason.CloseCodes.CANNOT_ACCEPT, CloseReason.CloseCodes.CLOSED_ABNORMALLY)
.contains(closeReason.getCloseCode()))
{
logger.info("Trying to reconnect websocket");
reconnector.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public boolean onDisconnect(CloseReason closeReason)
private final String userAgentValue;
private final ClientEndpoint endpoint;

private ClientManager manager;
private Session connection;
private volatile ClientManager manager;
private volatile Session connection;
private volatile boolean closed;

public WebsocketClientTyrus(Runnable reconnector, URI wsUri, KeyStore trustStore, KeyStore keyStore,
Expand Down Expand Up @@ -131,6 +131,8 @@ public void connect()
if (manager != null)
throw new IllegalStateException("Allready connecting/connected");

closed = false;

manager = ClientManager.createClient();
manager.getProperties().put(ClientProperties.RECONNECT_HANDLER, reconnectHandler);
manager.getProperties().put(ClientProperties.SSL_ENGINE_CONFIGURATOR, new SslEngineConfigurator(sslContext));
Expand Down

0 comments on commit 5ee060b

Please sign in to comment.