You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vert.x WebClient调用PayPal API无响应,Handler未触发问题

Vert.x WebClient调用PayPal API已接收响应但Handler未触发问题

我尝试使用Vert.x WebClient调用PayPal API,从日志可见已接收响应,但onFailure、onSuccess、onComplete这些Handler均未触发。用Curl调用相同接口可正常返回200,说明API及凭证有效。

调用代码

WebClient.create(this.getVertx(), options)
                .get(this.environment.getPort(), this.environment.getHost(), "/v1/billing/subscriptions")
                .setQueryParam("id", subscriptionID)
                .bearerTokenAuthentication(accessToken.result())
                .putHeader("Content-Type", "application/json")
                .ssl(true)
                .timeout(1)
                .send()
                .onFailure(res -> {
                    System.out.println("This will not be called");
                })
                .onSuccess(res -> {
                    System.out.println("This will not be called");
                })
                .onComplete(res -> {
                    System.out.println("This will not be called");
                });

日志显示已完成READ操作

|000002c0| 61 79 70 61 6c 2e 63 6f 6d 2f 73 65 72 76 69 63 |aypal.com/servic|
|000002d0| 65 73 2f 73 75 62 73 63 72 69 70 74 69 6f 6e 73 |es/subscriptions|
|000002e0| 20 68 74 74 70 73 3a 2f 2f 75 72 69 2e 70 61 79 | https://uri.pay|
|000002f0| 70 61 6c 2e 63 6f 6d 2f 73 65 72 76 69 63 65 73 |pal.com/services|
|00000300| 2f 61 70 70 6c 69 63 61 74 69 6f 6e 73 2f 77 65 |/applications/we|
|00000310| 62 68 6f 6f 6b 73 22 2c 22 61 63 63 65 73 73 5f |bhooks","access_|
|00000320| 74 6f 6b 65 6e 22 3a 22 41 32 31 41 41 4b 6d 39 |token":"A21777m9|
|00000330| 55 34 7a 6d 75 4d 46 50 61 4a 6e 4d 78 66 65 72 |U4zmuMFP6666xfer|
|00000340| 7a 71 4f 46 56 63 5f 70 32 48 5a 6a 38 58 72 50 |zqOFVc_p2HZj8XrP|
|00000350| 6c 6d 5a 76 4e 59 7a 67 70 33 55 5a 47 34 51 55 |lmZvNY666666G4QU|
|00000360| 4a 43 65 6a 6e 4a 49 30 52 62 61 32 5a 5f 53 41 |JCejghfhRba2Z_SA|
|00000370| 56 4d 30 2d 69 71 4e 54 5a 67 79 34 59 5f 54 |VM0-iqNTZ6GY4Y_T|
|00000380| 70 36 4a 39 7a 46 41 53 51 22 2c 22 74 6f 6b 65 |p6J9zFASQ","toke|
|00000390| 6e 5f 74 79 70 65 22 3a 22 42 65 61 72 65 72 22 |n_type":"Bearer"|
|000003a0| 2c 22 61 70 70 5f 69 64 22 3a 22 41 50 50 2d 38 |,"app_id":"APP-8|
|000003b0| 30 57 32 38 34 34 38 35 50 35 31 39 35 34 33 54 |0W284ggfdfg9543T|
|000003c0| 22 2c 22 65 78 70 69 72 65 73 5f 69 6e 22 3a 33 |","expires_in":3|
|000003d0| 31 36 30 39 2c 22 6e 6f 6e 63 65 22 3a 22 32 30 |1609,"nonce":"20|
|000003e0| 32 33 2d 30 33 2d 31 36 54 31 36 3a 30 32 3a 31 |23-03-16T16:02:1|
|000003f0| 34 5a 69 39 72 35 79 70 73 68 4e 70 65 38 4a 36 |4Zi9rfffffbpe8J6|
|00000400| 52 59 42 59 57 6b 65 39 44 33 71 31 70 6e 6b 71 |RYBYvvv9D3q1pnkq|
|00000410| 79 42 4b 49 4f 49 73 48 46 73 31 49 30 22 7d    |yBKIOIsHFs1I0"} |
+--------+-------------------------------------------------+----------------+
2023.03.16 17:15:25.133 [DEBUG] io.netty.handler.logging.LoggingHandler: [id:  0x7dba3957, L:/192.168.178.22:64324 - R:api.sandbox.paypal.com/173.0.93.150:443] READ COMPLETE
Disconnected from the target VM, address: '127.0.0.1:64313', transport: 'socket'

Curl验证命令

curl -v -X GET https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-AGEG7AMDEFD \ 
-H "Content-Type: application/json" \
-H "Authorization: Bearer A21AAKujR2DggVYD0Feb4444K2S9L851WGdddxNffqsa0QxJ8xGZDxj8ASymp6W4_Mmr4176M9rV-jVJeHeMEx3BwPODBQ"

问题原因及解决方案

核心原因

代码中设置了.timeout(1),即超时时间仅1毫秒。PayPal API的响应流程(包括网络传输、服务端处理)不可能在1毫秒内完成,虽然日志显示最终收到了响应,但超时定时器已提前触发,导致请求对应的Future被取消,所有绑定的Handler都不会执行。

解决方案

  1. 调整超时时间:将.timeout(1)修改为合理值,比如30秒(.timeout(30000)),具体时长可根据实际网络情况和API响应速度调整。
  2. 检查事件循环状态:确保Vert.x的事件循环线程没有被阻塞(比如避免在事件循环中执行同步IO、耗时计算等操作),否则会影响Handler的调度执行。

内容的提问来源于stack exchange,提问作者Qeychon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 14:47:32