在服务器上使用没有状态的Spring Web Flow [英] Use Spring Web Flow without state on the server

查看:151
本文介绍了在服务器上使用没有状态的Spring Web Flow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读Pro Spring MVC一书中的Spring Web Flow一章。不幸的是,没有明确的信息,流程执行期间的状态是持久的。我假设它保存在JVM堆中并与会话相关联。

I'm reading the Spring Web Flow chapter in the book Pro Spring MVC. Unfortunately there's no explicit information, where the state during a flow execution is persisted. I assume it is saved in the JVM Heap and associated with the session.

现在HTTP是无状态协议(REST ...)我想使用Spring Web Flow没有在服务器上保存状态(除了可以验证会话的唯一状态)。

Now HTTP is a stateless protocol (REST...) and I'd like to use Spring Web Flow without saving state on the server (besides the one and only state that a session might be authenticated).

一种策略是发送整个流的所有参数流的每个HTTP请求(隐藏输入),从而累积所有必要的参数,直到流完成。

One strategy is to send all parameters of the entire flow with every HTTP request of the flow (hidden input) and thus accumulating all necessary parameters until the flow has finished.

通过签名可以避免重新验证参数的开销已经验证的参数。

The overhead of re-validating parameters can be avoided with signatures over already validated parameters.

您知道吗,是否有可能以这种方式使用Spring Web Flow?有人已经这样做了吗?

Do you know, whether it might be possible to use Spring Web Flow in this way? Has anybody already done this?

更新:为什么?

坚持状态是不仅违反了作为无状态协议的HTTP原则,而且还存在实际问题:

Persisting state is not only a violation of the principles of HTTP as a stateless protocol but has practical problems too:


  • 如果用户浏览多个浏览器标签然后这可能导致状态,竞争条件或数据丢失不一致。

  • 在服务器上存储状态会使多台服务器上的负载平衡变得更加复杂。

  • 测试并且调试变得更加复杂,因为请求不能单独测试或分析,而只能在先前请求的上下文中进行测试。

  • 必须启用Cookie才能将服务器会话与请求相关联。

  • 服务器需要同步访问服务器端状态。

  • 同样取决于服务器状态的请求的url不包含所有必需的信息将流中的状态加入书签或在错误报告中理解它。

  • If the user browses with multiple browser tabs then this can lead to inconsistent state, race conditions or data loss.
  • Storing state on the server makes load balancing over several servers more complicate.
  • Testing and debugging becomes more complicate, because requests can not be tested or analyzed in isolation but only in the context of previous requests.
  • Cookies must be enabled to correlate servers sessions to requests.
  • The server needs to synchronize access to the server-side state.
  • The url of a request that also depends on server state does not contain all information necessary to bookmark the state inside a flow or to make sense of it in a bug report.

我还没有看过Web Flow的细节,但我相信一个人可以拥有相同的编程经验,并且仍然将所有信息保存在请求参数中。

I've not yet looked at the details of Web Flow but I'm confident that one could have the same programming experience and still keep all information in the request parameters.

更新:我现在知道我所要求的流程处理方式有一个名称: Continuations 。术语延续,是在函数式编程更常见,但它显然并不少见,以适应想法HTTP交互。

Update: I've now learned that my requested style of flow handling has a name: Continuations. The term continuation is more common in functional programming but it's apparently not uncommon to adapt the idea to HTTP interactions.

推荐答案

您可能有兴趣检查我的bean流FSM项目(restflow):
https://github.com/alfonso -presa / restflow

You might be interested in checking my bean flow FSM project (restflow): https://github.com/alfonso-presa/restflow

虽然它不使用Spring WebFlow,但我认为它可能有助于回答问题的精神,因为它允许实现无状态服务器协调流程。我开始这个项目是因为我希望使用Spring WebFlow几乎和你一样,但我发现它不可能因为状态存储在会话中(并且还没有内置REST / json序列化)。

Although it doesn't use Spring WebFlow, I think it may help answering the spirit of the question, as it allows the implementation of a stateless server orchestrated flow. I started this project because I wanted to make almost the same as you with spring WebFlow but I found it was not possible as state is stored in session (and also REST/json serialization is not built in).

它的主要目的是创建一个状态机(就像WebFlow一样),但它的状态存储在bean中,你可以将其存放在分布式存储中,或者轻松签名或加密并发送回客户端作为下一个请求的延续。

It's main purpose is making an state-machine (just like WebFlow does) but with it's state stored in a bean, which you can persist in a distributed store, or easily sign or encrypt and send back to the client as continuation for next requests.

我希望你觉得它很有用。

I hope you find it useful.

编辑:我创建了一个这里展示的项目: https://github.com/alfonso-presa/restflow-spring -web-sample

edit: I created a showcase project here: https://github.com/alfonso-presa/restflow-spring-web-sample

这篇关于在服务器上使用没有状态的Spring Web Flow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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