如何处理 REST 中完成某件事所需的时间?
使用 Jersey/JAX-RS 我有一个获取处理程序,其中包含将大文件复制到另一个位置的代码。我希望能够访问 URL 并能够查看复制的当前状态(即经过的时间)。我该如何实现这个目标?
Using Jersey/JAX-RS I have a get handler that contains code to copy a large file to another location. I want to be able to go to a URL and be able to see the current state of the copying (i.e. time elapsed). How do I accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在哪一边?发送者还是接收者?
发送者可以公开链接或其他内容作为请求的一部分。
您可以对 URI 接收器/foo/1 执行类似
POST 接收器/foo/传入
接收器可能会“201 创建”或“303 查看其他”发送器的操作
此时,
,而GET 接收器/foo/1
可能只是返回提供的状态链接,或将其嵌入表示中:
GET sender/foo/abc/status
此时可能会返回“待处理”或“已排队”或类似的内容。
...
然后,发送方可以自由地
PUT 接收方/foo/1
在 PUT 期间,对服务的异步 GET 仍然可以从源服务获取状态,该状态现在可能正在“传输”或包括字节/总数等。
On which side? The sender or the receiver?
The sender could expose a link or something, as part of the request.
You could arguably do something like
POST receiver/foo/incoming
receiver might '201 Created' or '303 See Other' sender to the URI receiver/foo/1
at this time, a
GET receiver/foo/1
might simply return the provided status link, or embed it in the representation:
GET sender/foo/abc/status
Might return, at this time, "pending" or "queued" or something like that.
...
Then, sender is free to
PUT receiver/foo/1
During the PUT, async GET to the services can still GET the status from the origin service, which might now be "transmitting" or include the bytes/total, etc.
如果我理解正确的话,我会假设,因为这是一个长时间运行的操作,所以让初始 POST 返回 202,并在内容正文中添加 Location 标头或指向复制操作状态页面的链接将是一个好方法。然后,客户端可以定期获取状态 URL,并且当服务器完成复制时,GET 可以使用 303 或某种机制返回一个链接来定位新创建的文件。
希望有帮助!
If I understand you correctly, I would assume since it is a long running operation, having the initial POST return a 202, with the Location header or a link in the content body to the status page of the copy operation would be a good approach. The client can then GET the status URL periodically and, when the server completes the copy, the GET can return a link using a 303 or some mechanism to locate the newly created file.
Hope that helps!