AWS-使用@connections websocket回调URL从后端(单向)发送响应-API网关websocket协议

问题描述 投票:3回答:1

我一直在努力通过aws提供的回调URL(https://******.execute-api.us-east-1.amazonaws.com/test/@connections)向连接的客户端发送响应。

在我的后端中具有以下代码以发送响应,这是一种单向通信。

    AwsClientBuilder.EndpointConfiguration config =
            new AwsClientBuilder.EndpointConfiguration("https://*********.execute-api.us-east-1.amazonaws.com/test", "us-east-1");
    AmazonApiGatewayManagementApi client = AmazonApiGatewayManagementApiClientBuilder.standard()
            .withEndpointConfiguration(config).build();


    PostToConnectionRequest request = new PostToConnectionRequest();
    request.withConnectionId("bGYcWek5oAMCKwA=");
    Charset charset = Charset.forName("UTF-8");
    CharsetEncoder encoder = charset.newEncoder();
    ByteBuffer buff = null;
    try {
        buff = encoder.encode(CharBuffer.wrap("Hello from lambda"));
    } catch (CharacterCodingException e) {
        log.error("Error while encoding", e);
    }
    request.withData(buff);
    PostToConnectionResult result = client.postToConnection(request);
    log.info("Result of websocket send:\n" + result);

获取服务:AmazonApiGatewayManagementApi;状态码:403;错误代码:InvalidSignatureException异常。

注意:我已完成所有设置,如证书和AWS访问密钥。

如aws文档中所述,我已经尝试了正在运行的awscurl。我能够在websocket连接的客户端上看到响应。https://docs.amazonaws.cn/en_us/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html

java amazon-web-services websocket api-gateway
1个回答
0
投票

您是否找到了解决方案?完全一样的问题。

© www.soinside.com 2019 - 2024. All rights reserved.