410 error when posting message by websocket in JAVA

0

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()
                .withEndpointConfiguration(endpointConfiguration).build();
        PostToConnectionRequest request = new PostToConnectionRequest();
        String connectionId = "myconnectionId";
        request.withConnectionId(connectionId);
        request.withData(ByteBuffer.wrap("tset".getBytes()));
        api.postToConnection(request);

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.

已提問 5 年前檢視次數 1637 次
5 個答案
1

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.

AWS
已回答 5 年前
1

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.

AWS
已回答 4 年前
0

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.

已回答 5 年前
0

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.

AustinK
已回答 4 年前
0

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

AustinK
已回答 4 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南