使用Jersey的Java异步REST Web服务? [英] Java Async REST web service using Jersey?

查看:167
本文介绍了使用Jersey的Java异步REST Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现一个Java REST Web服务(我们使用Jersey框架),它基本上可以

I need to implement a Java REST Web Service (we use Jersey framework) which can basically either

a。在返回响应
b之前阻止等待某个事件(或对事件进行轮询)。提供某种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/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.3

也许还要看几乎标准化的新HTTP大号用于此目的的墨水标题。

Maybe also look at the almost standardized new HTTP Link header for that purpose.

http://tools.ietf.org/html/draft-nottingham-http-link-header-03

Jan

这篇关于使用Jersey的Java异步REST Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆