- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个查询来回答远程客户的标准请求。标准是指它不从服务器外部获取任何参数。每当任何人向 URL 提交请求,比如 http://www.example.com/query ,她/他在响应正文中获取 reply.xml
的内容,取决于当时数据库提供的内容。reply.xml
的内容只在服务器上的数据库内容中发生变化,而不会在任何外部发生变化比如谁做查询,在哪个输入上等等,因此不接受客户端的参数。我什至不检查任何身份验证——我们将一切都留给了防火墙。
所以我写了一个@POST
方法,比如query()
来调用发布到http://www.example.com/query 的请求。 , 并交付结果。我使用了 Jersey
并且一切正常,除了
请求应该是跨时间排他的。也就是说,一次应该处理一个请求——随后的用户点击应该收到一条 HTTP 状态为 309 的消息,除非服务器没有运行由我的方法 query()
调用的查询进程.
如何实现?我尝试让 query()
服务于 @PUT
而不是 @POST
响应,并得到了相同的结果。
也许是关于该主题的幼稚问题。不过对Restful服务不是很熟悉。
我可以通过在 token 上线程化来控制一次只运行一个查询并使同时请求接收 HTTP 309 来做到这一点。但是必须有更好、更简单的方法在服务器上实现这一点。
我使用的是 Tomcat 8,Jersey 1.19。
TIA。
注意:我读过PUT vs POST in REST在其他一些有用的讨论中。
//=====================
编辑:
哪个用户提交查询在任何时候都没有任何区别。
假设 userA
提交了一个查询。当该查询仍在运行时,即在 query()
将响应返回给 userA
之前,userB
提交了一个查询。 userB
应该得到一个 309——只是因为当时正在处理一个查询。
无论是 userA
= userB
还是 userA
<> userB
在这里都不重要,应该只返回 309因为在一个已经运行的时候有一个查询请求。这是用户唯一一次收到 309。
//=========================================== =
编辑-2:
我知道带有并发控制的解决方案。我猜有人在使用 Restful 功能。这是一个相当学术的问题。
最佳答案
@Koos Gadellaa 说客户端应该阻塞是正确的第二个请求直到响应到达。让我解释一下为什么这是最好的做法。 在架构上,它与关注点有关。服务器不知道为什么两个请求并行到达。因此,它依赖于带外知识来知道并行请求是不好的。任何带外知识都会产生耦合,这意味着如果您更改系统的一部分的工作方式,则必须更改另一部分。 RESTful 架构很受欢迎,因为它们减少了耦合。如果同一个用户登录到两个客户端,那么系统就会崩溃。您永远不想构建具有这种客户端-服务器耦合类型的系统。
关于服务器的责任,良好的编码实践开始发挥作用,最好的办法是确保服务不会受到来自用户的多个并行请求的阻碍。缓存可能是你的 friend 。根据查询参数,可以将响应写入磁盘上的缓存文件。客户端将始终使用 HTTP 303 重定向到缓存文件 URL。可以使用 304 Not Modified,这样客户端就不必下载两次答案。在这种情况下,唯一的带外知识是正确实现 HTTP 规范,该规范规范明确且稳健。
如果服务过载,相应的响应代码似乎是 503。
10.5.4 503 Service Unavailable
The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.
Note: The existence of the 503 status code does not imply that a
server must use it when becoming overloaded. Some servers may wish
to simply refuse the connection.
因为你从 my response here 引导我来到这里,看起来您想知道正确的 RESTful 方法。这将比上面的解决方案更复杂,我猜你不想走这条路,但就是这样。
If the server needs to communicate to the client that a request is being performed and when it completes, then resources need to be created for those concepts. This feels weird because they concepts exist in HTTP and it is odd to reimplement them at a higher level (architectural smell).
- The client would POST a
Request
orQuery
resource to the server. This resource would have aResponse
property that is empty and aStatus
property which is empty. The server would respond with a body that has theStatus
property set to "processing".- The client would then perform GETs to this resource (possibly use long-polling here) to check for updates.
- When the response has been created, the
Response
property would then link to a response resource or have the response embedded.
这种方法使用资源来传达正在发生的事情。因此,唯一的带外知识是资源的有效状态。
关于java - 如何忽略不耐烦用户的多次点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39057416/
在为 Web 应用程序用例图建模时,为用户可以拥有的每个角色创建一个角色是否更好?或拥有一个角色、用户和一个具有特权的矩阵? guest < 用户 < 版主 < 管理员 1: guest 、用户、版主
我无法使用 Elixir 连接到 Postgres: ** (Mix) The database for PhoenixChat.Repo couldn't be created: FATAL 28P
这个问题已经有答案了: Group by field name in Java (7 个回答) 已关闭 7 年前。 我必须编写一个需要 List 的方法并返回 Map> . User包含 Person
感谢您的帮助,首先我将显示代码: $dotaz = "Select * from customers JOIN contracts where customers.user_id ='".$_SESS
我只想向所有用户中的一个用户显示一个按钮。我尝试了 orderByKey() 但没有成功! 用户模型有 id 成员,我尝试使用 orderByChild("id") 但结果相同! 我什至尝试了以下技巧
我们在工作中从 MongoDB 切换到 Postgres,我正在建立一个 BDR 组。 在这一步,我正在考虑安全性并尽可能锁定。因此,我希望设置一个 replication 用户(角色)并让 BDR
export class UserListComponent implements OnInit{ users; constructor(private userService: UserS
我可以使用 Sonata User Bundle 将 FOS 包集成到 sonata Admin 包中。我的登录功能正常。现在我想添加 FOSUserBundle 中的更改密码等功能到 sonata
在 LinkedIn 中创建新应用程序时,我得到 4 个单独的代码: API key 秘钥 OAuth 用户 token OAuth 用户密码 我在 OAuth 流程中使用前两个。 的目的是什么?最后
所以..我几乎解决了所有问题。但现在我要处理另一个问题。我使用了这个连接字符串: SqlConnection con = new SqlConnection(@"Data Source=.\SQLEX
我有一组“用户”和一组“订单”。我想列出每个 user_id 的所有 order_id。 var users = { 0: { user_id: 111, us
我已经为我的Django应用创建了一个用户模型 class User(Model): """ The Authentication model. This contains the u
我被这个问题困住了,找不到解决方案。寻找一些方向。我正在用 laravel 开发一个新的项目,目前正致力于用户认证。我正在使用 Laravels 5.8 身份验证模块。 对密码恢复 View 做了一些
安装后我正在使用ansible配置几台计算机。 为此,我在机器上本地运行 ansible。安装中的“主要”用户通常具有不同的名称。我想将该用户用于诸如 become_user 之类的变量. “主要”用
我正在尝试制作一个运行 syncdb 的批处理文件来创建一个数据库文件,然后使用用户名“admin”和密码“admin”创建一个 super 用户。 到目前为止我的代码: python manage.
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 6 年前。 Improv
我已在 Azure 数据库服务器上设置异地复制。 服务器上运行的数据库之一具有我通过 SSMS 创建的登录名和用户: https://learn.microsoft.com/en-us/azure/s
我有一个 ionic 2 应用程序,正在使用 native FB Login 来检索名称/图片并将其保存到 NativeStorage。流程是我打开WelcomePage、登录并保存数据。从那里,na
这是我的用户身份验证方法: def user_login(request): if request.method == 'POST': username = request.P
我试图获取来自特定用户的所有推文,但是当我迭代在模板中抛出推文时,我得到“User”对象不可迭代 观看次数 tweets = User.objects.get(username__iexact='us
我是一名优秀的程序员,十分优秀!