我如何管理混合Ruby / GWT系统中的会话? [英] How do I manage sessions in a hybrid Ruby/GWT system?

查看:152
本文介绍了我如何管理混合Ruby / GWT系统中的会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个Ruby on Rails系统,并且有计划将它移植到GWT。在我们这样做之前,需要用GWT编写部分站点的概念证明来证明GWT可以使用并显示当前内容。系统的GWT部分中的数据流如下:

I currently have a Ruby on Rails system, and there are plans to port it to GWT. Before we do this, the powers that be want to have a proof of concept with part of the site being written in GWT to show that GWT can use and display the current content. The flow of data in the GWT portion of the system is as follows:


  1. 客户端向GWT服务器发送RPC调用

  2. 服务器接收RPC调用,然后向Rails系统发出等效的Ajax请求。
  3. 服务器根据Ajax请求的结果生成一个Java对象,并将其传递回客户端

我现在遇到的问题是跨两个系统管理用户会话数据。我们只有1个Tomcat实例,并且有它自己的会话类型,然后我们的Ruby系统使用ActiveRecordStore将会话数据存储在数据库中。

The issue I'm running into now is managing user session data across both systems. We only have 1 Tomcat instance, and that has its own type of sessions, and then our Ruby system uses ActiveRecordStore to store session data in the database.

这里的问题是当Tomcat系统与Ruby系统对话时,如果GWT客户端发出登录请求,则最后一个从GWT系统登录的用户将在Rails系统中执行所有传出的Ajax请求,就好像它们是当前用户一样因为Tomcat系统看起来像一个Rails客户端。

The problem here is that when the Tomcat system talks with the Ruby system, if the GWT client has made a login request, the last user to log in from the GWT system has all outgoing Ajax requests being performed in the Rails system as if they're the current user since the Tomcat system looks like a single client to Rails.

无论如何,我该如何做到这一点,如果用户开始与Tomcat系统进行会话,Ruby系统会知道这一点,并有一个等效的会话,以便即使Tomcat服务器是一个单一的客户端,Rails系统意识到许多不同的用户正在从单个客户端与它通信。

Anyways, how can I make it such that if a user begins a session with the Tomcat system, the Ruby system will be aware of this and have an equivalent session so that even though the Tomcat server is a single client to it, the Rails system is aware of the fact that many different users are communicating with it from that single client.

推荐答案

我认为解决这个问题的最好方法是使用cookies而不是数据库来存储会话。 Rails本身支持这个,实际上它是默认的一段时间的cookie存储。 cookie本身由服务器密码签名以防止用户篡改。我认为Rails实现使用Ruby封送处理来转储/加载数据,因此您可能必须使用Java实现它,或者您可以使用相同的想法在双方实现您自己的Cookie管理器。

I think the best way to solve this would be to use cookies instead of a database to store the session. Rails supports this natively, actually it's the default cookie store for some time now. The cookie itself is signed by a server secret to prevent user tampering. I think the Rails implementation uses Ruby marshaling to dump/load the data so you might have to implement it in Java, or you can implement your own cookie manager on both sides using the same idea.

也可以在Java应用程序中使用JRuby中的Ruby代码。

It is also possible to just use the Ruby code from JRuby in your Java application.

这篇关于我如何管理混合Ruby / GWT系统中的会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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