From f210f25c36d986139cb14707e96795b3b2589e94 Mon Sep 17 00:00:00 2001 From: Vladimir Orany Date: Fri, 24 May 2019 11:32:25 +0200 Subject: [PATCH] added WebSocketClientGoneException when client is gone --- gradle.properties | 2 +- .../apigateway/ws/DefaultMessageSender.java | 3 +++ .../ws/WebSocketClientGoneException.java | 19 +++++++++++++++++++ .../apigateway/ws/MessageSenderSpec.groovy | 14 ++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 micronaut-aws-sdk/src/main/groovy/com/agorapulse/micronaut/aws/apigateway/ws/WebSocketClientGoneException.java diff --git a/gradle.properties b/gradle.properties index 36c2ee3..4a6fa59 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version = 1.1.0 +version = 1.1.0.1 micronautVersion = 1.1.0 gruVersion = 0.8.0 druVersion = 0.6.0 diff --git a/micronaut-aws-sdk/src/main/groovy/com/agorapulse/micronaut/aws/apigateway/ws/DefaultMessageSender.java b/micronaut-aws-sdk/src/main/groovy/com/agorapulse/micronaut/aws/apigateway/ws/DefaultMessageSender.java index 88aa889..312dde1 100644 --- a/micronaut-aws-sdk/src/main/groovy/com/agorapulse/micronaut/aws/apigateway/ws/DefaultMessageSender.java +++ b/micronaut-aws-sdk/src/main/groovy/com/agorapulse/micronaut/aws/apigateway/ws/DefaultMessageSender.java @@ -63,6 +63,9 @@ public void send(String connectionId, InputStream payload) { .errorResponseHandler(new HttpResponseHandler() { @Override public AmazonClientException handle(HttpResponse response) throws Exception { + if (response.getStatusCode() == 410) { + return new WebSocketClientGoneException("WebSocket client with id " + connectionId + " is already gone"); + } return new AmazonClientException("Exception publishing messages to WS endpoint " + " POST " + url + " " + response.getStatusCode() + ": " diff --git a/micronaut-aws-sdk/src/main/groovy/com/agorapulse/micronaut/aws/apigateway/ws/WebSocketClientGoneException.java b/micronaut-aws-sdk/src/main/groovy/com/agorapulse/micronaut/aws/apigateway/ws/WebSocketClientGoneException.java new file mode 100644 index 0000000..3418fed --- /dev/null +++ b/micronaut-aws-sdk/src/main/groovy/com/agorapulse/micronaut/aws/apigateway/ws/WebSocketClientGoneException.java @@ -0,0 +1,19 @@ +package com.agorapulse.micronaut.aws.apigateway.ws; + +import com.amazonaws.AmazonClientException; + +public class WebSocketClientGoneException extends AmazonClientException { + + public WebSocketClientGoneException(String message, Throwable t) { + super(message, t); + } + + public WebSocketClientGoneException(String message) { + super(message); + } + + public WebSocketClientGoneException(Throwable t) { + super(t); + } + +} diff --git a/micronaut-aws-sdk/src/test/groovy/com/agorapulse/micronaut/aws/apigateway/ws/MessageSenderSpec.groovy b/micronaut-aws-sdk/src/test/groovy/com/agorapulse/micronaut/aws/apigateway/ws/MessageSenderSpec.groovy index 77e1402..2a4e478 100644 --- a/micronaut-aws-sdk/src/test/groovy/com/agorapulse/micronaut/aws/apigateway/ws/MessageSenderSpec.groovy +++ b/micronaut-aws-sdk/src/test/groovy/com/agorapulse/micronaut/aws/apigateway/ws/MessageSenderSpec.groovy @@ -57,6 +57,20 @@ class MessageSenderSpec extends Specification { MessageSender defaultSender = ctx.getBean(MessageSender) when: defaultSender.send(CONNECTION_ID, PAYLOAD) + then: + thrown(WebSocketClientGoneException) + } + + void 'test forbidden'() { + given: + prepareServerAndContext { + header('Authorization', Matchers.iterableWithSize(1)) + called(1) + responds().code(403).body('Forbidden', ContentType.TEXT_PLAIN) + } + MessageSender defaultSender = ctx.getBean(MessageSender) + when: + defaultSender.send(CONNECTION_ID, PAYLOAD) then: thrown(AmazonClientException) }