在java中通过web服务维护多个会话请求
我想使用 Java Web Services
实现以下解决方案(在图像中描述) 当用户使用 Web 服务请求有效凭证时,就会在服务器上创建一个会话,并且该服务器(接收请求的服务器)会创建与其他服务器(即 Meta Trader 的服务器)的连接。
这里每个用户都有一个不同的会话来维护他们与元交易服务器的连接和状态。
注意: 目前,当用户请求时,我不维护任何会话,而是将连接对象保存在 a 中
@javax.ws.rs.core.Context
ServletContext servletContext;
MyApplication application = new MyApplication();
servletContext.setAttribute("application", application);
,但此解决方案自然不能为多个用户提供服务。因此,请任何人知道如何解决为多个客户提供服务的问题,然后请回复。
我正在使用 Glassfish 和 JAX-RS (Jersery 1.1)、JAXB
I want to implement following solution (described in a image) using Java Web Services
When ever a user request with a valid credentials using web services , a session is created over server and that server (who receives the request ) creates a connection with the other server i.e. Meta Trader's Server.
Here each user has a different session to maintain their connection and a state with meta trader server.
Note:
Currently i am not maintaining any session when a user request instead i am saving the connection object in a
@javax.ws.rs.core.Context
ServletContext servletContext;
MyApplication application = new MyApplication();
servletContext.setAttribute("application", application);
But this solution doesn't serve multiple users naturally. so please anyone has an idea how to solve the issue of serving multiple clients then please reply.
I am using Glassfish and JAX-RS ( Jersery 1.1 ) , JAXB
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用注释 @javax.ws.rs.core.Context 即可获取 HttpServletRequest 并在部署 Jersey 的容器中使用其会话。
下面的代码是球衣资源的简单示例,它获取会话对象并将值存储在会话中,并在后续调用中检索它们。
但您不应该像这样使用 RESTful API。它意味着用作无状态的 Web 服务,而不是 Web 应用程序。检查以下答案,我从中得到了示例和建议
(球衣安全和会话管理)
https://stackoverflow.com/a/922058
https://stackoverflow.com/a/7752250
(如何管理 JAX-RS 中的状态?)
https://stackoverflow.com/a/36713305
(在 JAX-RS 资源中获取 ServletContext)
https://stackoverflow.com/a/1814788
Simply use the annotation @javax.ws.rs.core.Context to get the HttpServletRequest and use its session within the container in which Jersey is deployed.
The code below is a simple example of a jersey resource that gets the session object and stores values in the session and retrieves them on subsequent calls.
But you should NOT use RESTful API like this. It meant to be used as web service which is stateless, not web application. Check the following answers which I got the example and advice from
(jersey security and session management)
https://stackoverflow.com/a/922058
https://stackoverflow.com/a/7752250
(How to manage state in JAX-RS?)
https://stackoverflow.com/a/36713305
(Get ServletContext in JAX-RS resource)
https://stackoverflow.com/a/1814788