将数据(对象)添加到 Jersey(Restful) 对 POST 的响应?

发布于 2024-12-24 02:02:34 字数 221 浏览 2 评论 0原文

我想获取一个依赖于客户端发送的另一个对象的对象。因此,在正常情况下,我应该首先 POST 初始对象,然后检索它以构造最终对象并使用 GET 方法获取它。我怎样才能在没有会话的情况下做到这一点? (我们处于 RESTful 应用程序中)。

是否可以使用 Jersey 在对 POST 请求的响应中添加对象(XmlElement)? 我想避免执行 2 个操作(POST,然后 GET)。 与HTTP协议是否矛盾?

I want to GET an object that depend on another one sent by the client. So in normal scenario i should first POST the initial Object, then retrieve it to construct the final object and get it with GET method. How can i do it without a session? (We are in a RESTful Application ).

Is it possible to add an Object(XmlElement) in the Response to a POST request using Jersey?
I want to avoid having to do 2 operations (POST, then GET).
Is it in contradiction with HTTP Protocol?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独﹏钓一江月 2024-12-31 02:02:34

使用 POST,您可以获取输入文档并生成输出文档,并且不需要任何类型的会话。 POST 动词实际上只是意味着“用这个做某事”;它的含义比 GET、PUT 或 DELETE 更不具体。但是,如果处理操作可能需要“很长时间”(这是一个模糊的概念),那么您最好创建一个资源来响应跟踪处理的 POST 并将客户端重定向到该资源;这样,一旦结果可用,他们就可以获取结果。是否使用会话来管理资源的存在取决于您,但我根本不推荐它;访问控制应该由用户身份进行,无论是否涉及会话,并且处理资源应该可供任何提出请求(并获得授权)的人使用。您可能需要仔细考虑管理半瞬态资源(例如数据库和过期策略)所涉及的内容,并在考虑这些因素的情况下仔细设计整个应用程序。

With POST you can take an input document and produce an output document, and it doesn't require any kind of session. The POST verb really just means “do something with this”; it's much less specific in meaning than GET, PUT or DELETE. However, if the processing operation is likely to take a “long time” (which is a fuzzy concept) then you are better off creating a resource in response to the POST that tracks the processing and redirecting the client to that resource; like that, they can pick up the results once they're available. It's up to you whether you use a session to manage the resource existence, but I don't really recommend it at all; access control should be by the users identity whether or not there's a session involved, and the processing resource should be available to anyone who asks (and is authorized). You may well need to consider carefully what's involved in managing semi-transient resources (e.g., a database and expiry policy) and design your whole application carefully with those things in mind.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文