使用 GWT Requestfactory 的 Http 状态代码
如果我使用 GWT Requestfactory,向客户端发送“404 未找到”或“401 未经授权”的推荐方式是什么?
问候安德烈亚斯
if I use the GWT Requestfactory, what is the recommended way to send a "404 not found" or "401 unauthorized" to the client?
Greetings Andreas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RequestFactory 是一种RPC 协议,而不是REST 协议。因此,首先,您不会发送“404 not found”:这意味着您的客户端应用程序甚至不知道如何与服务器通信。
至于“401 未经授权”,嗯,这取决于情况。
RequestFactoryServlet
的访问,那么在服务器端使用servlet过滤器来发送响应,并使用自定义的RequestTransport
(最简单的是简单地在客户端扩展DefaultRequestTransport
)来捕获响应并采取相应的操作。deleteThisThing
),那么您有多种选择,但在所有情况下如果用户未经授权,则不想从客户端应用程序调用这些方法(例如,如果用户不是管理员,则不显示删除此内容按钮):RequestFactoryServlet.getThreadLocalRequest().getUserPrincipal()
获取当前用户)ServiceLayerDecorator
在其中重写invoke
方法来进行检查(可能基于方法本身的某些注释)并调用report()< /code> 如果用户未获得授权
RequestFactory is an RPC kind of protocol, not a REST one. So, first, you won't send a "404 not found": that would mean your client app doesn't even know how to communicate with the server.
As for the "401 unauthorized", well, it depends.
RequestFactoryServlet
as a whole, then use a servlet filter on the server-side to send the response, and use a customRequestTransport
(easiest is to simply extendDefaultRequestTransport
) on the client side to catch the response and act accordingly.deleteThisThing
), then you have several choices, but in all cases you don't want to ever call these methods from the client app if the user is not authorized (e.g. don't display a delete this thing button if the user is not an administrator):RequestFactoryServlet.getThreadLocalRequest().getUserPrincipal()
to get the current user)ServiceLayerDecorator
where you override theinvoke
method to do the check (possibly based on some annotation on the method itself) and callreport()
in case the user is not authorized