Java Async REST web service using Jersey?(使用 Jersey 的 Java Async REST Web 服务?)
问题描述
我需要实现一个 Java REST Web 服务(我们使用 Jersey 框架),基本上可以
I need to implement a Java REST Web Service (we use Jersey framework) which can basically either
一个.在返回响应之前阻塞等待某个事件(或轮询事件)湾.提供某种 aysnc 行为以在请求已处理时通知客户端.
a. block waiting for some event (or poll for the event), before returning the response b. provide some kind of aysnc behaviour to notify the client when the request has been processed.
我正在考虑返回一个 transationID,并有一个/status 端点,客户端应该轮询该端点以确定请求是否已处理并获得特定结果.
I was thinking of returning a transationID, and having a /status endpoint which the client should poll to determine if the request was processed and get a specific result.
有什么想法吗?
推荐答案
Alan,正确的做法是使用 HTTP 的 202 Accepted 返回码,并在响应正文中包含一个链接,该链接指向客户端可以轮询以检查请求状态的页面.
Alan, the right thing to do is to use HTTP's 202 Accepted return code and include in the response body a link that points to a page the client can poll to check the status of the request.
在 machine2machine 上下文中,您需要为这些响应设计媒体类型(或微格式等),以便机器客户端可以理解"它们.
In a machine2machine context you will need to design your media type (or microformat etc.) for those responses so a machine client can 'understand' them.
参见 http://www.w3.org/协议/rfc2616/rfc2616-sec10.html#sec10.2.3
也许还为此目的查看几乎标准化的新 HTTP Link 标头.
Maybe also look at the almost standardized new HTTP Link header for that purpose.
https://datatracker.ietf.org/doc/html/draft-nottingham-http-link-header-03
一月
这篇关于使用 Jersey 的 Java Async REST Web 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Jersey 的 Java Async REST Web 服务?


- Jersey REST 客户端:发布多部分数据 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01