简体   繁体   English

在Play的组合动作中流式传输HTTP响应! 框架2.1

[英]Streaming an http response within a composed action in Play! Framework 2.1

I'm creating an authentication action that wraps other actions, using the Play Zentasks sample app as a template. 我正在使用Play Zentasks示例应用程序作为模板创建一个包装其他操作的身份验证操作。 One of the things that this needs to be able to do, is hit a webservice in certain circumstances, in order to retrieve a user's details. 在某些情况下,需要执行的一项操作是访问Web服务,以检索用户的详细信息。 I want to do this in a non-blocking fashion, but I don't want to have to pass a future back to the action that I'm wrapping. 我想以一种非阻塞的方式进行此操作,但我不想将未来传递给我正在包装的操作。

The only way that I can think of doing this is by using Enumerator.fromStream() with an InputStream pulled from a URL object. 我能想到的唯一方法是将Enumerator.fromStream()与从URL对象提取的InputStream一起使用。 I'm guessing this isn't the best way though, since it seems like a duplication of efforts (considering the ws object). 我猜这不是最好的方法,因为这似乎是重复的工作(考虑ws对象)。 The async ws api (and underlying asynchttpclient) returns a Future for everything however. 然而,异步ws api(和底层的asynchttpclient)会返回Future。 I don't suppose anyone has tackled this issue before and could point me in another direction? 我认为没有人以前解决过这个问题,并且可以指出我的另一个方向吗? Is there something that I'm missing? 有什么我想念的吗? Also, would using a Enumerator.fromStream() as I've suggested definitely not block? 另外,使用我建议的Enumerator.fromStream()绝对不会阻塞吗?

Thanks in advance, 提前致谢,

Suche

You can use the async WS api. 您可以使用异步WS API。 When it returns a future, you can call map on that, and pass the value to the action you're wrapping. 当它返回未来时,您可以在其上调用map,并将值传递给您要包装的操作。 Now you have a future containing the result of your wrapped action. 现在,您将拥有包含打包操作结果的未来。 Turn that into an AsyncResult or just wrap the whole thing in an Async{} block and it should work. 将其转换为AsyncResult或将整个内容包装在Async {}块中,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM