Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve target connection error handling.
  • Loading branch information
sachithKay committed Mar 25, 2022
1 parent e8d889e commit 0ca4f2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Expand Up @@ -57,5 +57,4 @@ public class WebsocketConstants {
public static final String CONNECTION_TERMINATE = "connection.terminate";

public static final int WEBSOCKET_UPSTREAM_ERROR_SC = 1014;
public static final String WEBSOCKET_CONNECTION_ERROR = "could not connect to server.";
}
Expand Up @@ -47,6 +47,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringWriter;
import java.net.ConnectException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
Expand Down Expand Up @@ -223,21 +224,24 @@ public void sendMessage(MessageContext msgCtx, String targetEPR, OutTransportInf
}
} catch (URISyntaxException e) {
log.error("Error parsing the WS endpoint url", e);
} catch (IOException e) {
} catch (ConnectException e) {
handleClientConnectionError(responseSender, e);
} catch (IOException e) {
log.error("Error writing to the websocket channel", e);
} catch (InterruptedException e) {
handleClientConnectionError(responseSender, e);
log.error("Error writing to the websocket channel", e);
} catch (XMLStreamException e) {
handleException("Error while building message", e);
}
}

private void handleClientConnectionError(InboundResponseSender responseSender, Exception e) {

log.error("Error writing to the websocket channel", e);
// we will close the client connection and notify with close frame
InboundWebsocketSourceHandler sourceHandler = ((InboundWebsocketResponseSender) responseSender).getSourceHandler();
CloseWebSocketFrame closeWebSocketFrame = new CloseWebSocketFrame(WebsocketConstants.WEBSOCKET_UPSTREAM_ERROR_SC,
WebsocketConstants.WEBSOCKET_CONNECTION_ERROR);
e.getMessage());
try {
sourceHandler.handleClientWebsocketChannelTermination(closeWebSocketFrame);
} catch (AxisFault fault) {
Expand Down

0 comments on commit 0ca4f2e

Please sign in to comment.