【问题标题】:How to avoid: "blockingToByteString is a blocking and unsafe operation"如何避免:“blockingToByteString 是一种阻塞且不安全的操作”
【发布时间】:2021-02-18 17:58:52
【问题描述】:

在我的 Play 项目中,我想获取从 REST 服务获取的文件的消息摘要。

服务调用:

ws.url("deployment/data/idResource").withMethod("GET").stream

从回复 (WSResponse) 中,我提取了以下内容:

response.bodyAsBytes.toByteBuffer.array()

这给了我这个警告:

p.a.l.w.a.StandaloneAhcWSClient$ - blockingToByteString is a blocking and unsafe operation!

有没有办法避免这个警告。

正如最后提到的,我需要一个 Array[Byte] 用于消息摘要。

【问题讨论】:

标签: scala playframework ws-client


【解决方案1】:

可能有点晚了,但我遇到了同样的问题,没有答案,所以这里是:

致电execute 而不是stream 喜欢

ws.url("deployment/data/idResource").withMethod("GET").execute

然后您可以将 WSResponse 读取为 json / string 等,而不会出现阻塞警告

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 2017-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多