410 error when posting message by websocket in JAVA


Since websocket is a new feature provided by api gateway, it is difficult for me to find documentation or examples about using it in JAVA. I can only refer to the nodejs example, looking for similar apis in aws sdk for java. Finally, I can make connection and the server(a lambda function) can also receive the message from client. But I encountered problems when I tried to post message to client from server.

The code is like below:

EndpointConfiguration endpointConfiguration = new EndpointConfiguration(
                "myendpoint.execute-api.ap-southeast-1.amazonaws.com/develop/", "ap-southeast-1");
        AmazonApiGatewayManagementApi api = AmazonApiGatewayManagementApiClientBuilder.standard()
        PostToConnectionRequest request = new PostToConnectionRequest();
        String connectionId = "myconnectionId";

And the error info:

Exception in thread "main" com.amazonaws.AmazonServiceException: Unable to unmarshall exception response with the unmarshallers provided (Service: AmazonApiGatewayManagementApi; Status Code: 410; Error Code: null; Request ID: 66ef081c-70c5-11e9-9319-c18364b84c32)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1712)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1367)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1113)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:770)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:744)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:726)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:686)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:668)
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:532)
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:512)
	at com.amazonaws.services.apigatewaymanagementapi.AmazonApiGatewayManagementApiClient.doInvoke(AmazonApiGatewayManagementApiClient.java:273)
	at com.amazonaws.services.apigatewaymanagementapi.AmazonApiGatewayManagementApiClient.invoke(AmazonApiGatewayManagementApiClient.java:240)
	at com.amazonaws.services.apigatewaymanagementapi.AmazonApiGatewayManagementApiClient.invoke(AmazonApiGatewayManagementApiClient.java:229)
	at com.amazonaws.services.apigatewaymanagementapi.AmazonApiGatewayManagementApiClient.executePostToConnection(AmazonApiGatewayManagementApiClient.java:195)
	at com.amazonaws.services.apigatewaymanagementapi.AmazonApiGatewayManagementApiClient.postToConnection(AmazonApiGatewayManagementApiClient.java:167)
	at com.worksap.company.hue.inquiry.api.handler.WebsocketTestHandler.main(WebsocketTestHandler.java:114)

The error points to "api.postToConnection(request);"
Maybe my code has some problems, please help me or give me some sample documentation reference.

asked 5 years ago1685 views
5 Answers

410 Gone means the connection is already gone (=the client is disconnected) or the connection is not established yet.

Are you trying to call postToConnection in $connect route integration? In the case, the connection is being established (which means not established yet), so you can't use postToConnection.

answered 5 years ago

As long as you invoke postToConnection to other available connections, it should not be a problem. $connect/$disconnect only affect the specific connection. You may need to check you are passing correct connectionIds.

answered 4 years ago

Thank you for your help. I guess the truth is that I call postToConnection in connect handler and in this handler the connection has not been established. Then I separated the postToConnection code into the default handler and called it manually that worked eventually.

answered 5 years ago

Sorry to revive an old thread, but what about when the $disconnect route is called. When a user disconnects, I'm iterating over my list of other connections and attempting to send a message to all other users that someone has disconnected, but I get the SerializationError: 410 Gone error for all connections, and I know the others haven't disconnected.

answered 4 years ago

Cool. Thank you. Your response made me dig a little deeper and it did end up being an issue on my end.

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions