反向 AJAX (Comet) 和 Spring MVC 与 Scala/LIFT 对比?

发布于 2024-09-06 23:14:31 字数 377 浏览 3 评论 0原文

有一个 IBM 的演示,展示了反向操作是多么简单AJAX 可以与 DWR 2 一起使用。另一方面,Scala/LIFT 具有内置的反向 AJAX 功能。

  1. 问题:如果这与 Spring MVC 配合良好,有什么经验吗?

  2. 问题:如果您从头开始,相比 DWR/Spring MVC,Scala/LIFT 的优点和缺点是什么

  3. 问题:在 Scala/LIFT 中,安全处理是否与 Spring Security 中一样复杂?

There is a demo by IBM that shows how easy Reverse AJAX can be used with DWR 2. On the other hand, Scala/LIFT comes with built-in Reverse AJAX capability.

  1. Question: Any experience if this works fine with Spring MVC?

  2. Question: If you'd start from scratch, what are the pros and cons for preferring Scala/LIFT over DWR/Spring MVC

  3. Question: In Scala/LIFT, is the security handling as sophisticated as in Spring Security?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁吢 2024-09-13 23:14:32
  1. 从我的角度来看,Spring MVC 是构建 AJAXed/COMETed RIA 的一个非常糟糕的选择。 ModelAndView 组件旨在处理 HTML 表单并立即渲染整个页面,标签库、验证例程都更适合基于 JSP 和模板的老式开发。对我来说,将 AJAX/COMET 插入 Spring MVC 始终是一种黑客行为。但是,如果您要使用 @MVC 构建 RESTful 服务(将 JSON 与您的 javascript UI 交换),它可能会起作用(尽管我更喜欢 Jersey/JAXB 来处理这些问题)。
  2. LIFT 最初设计是为了与 COMET 配合使用,因此它将是一个更好的选择。尽管我会选择比 LIFT 更轻量级、更少模板的东西(对于我来说,它也患有 Spring MVC 所患的同样的疾病)。
  3. 这两个安全系统仅涵盖基本场景,并且需要大量定制才能在实际项目中使用。

    这就是我在 Scala 中构建 COMETed RIA 时所用的:

    • Jersey(通过 HTTP/JSON 与 JS UI 进行通信的轻量级 RESTful 服务)+ Atmosphere(用于构建 COMETed 应用程序的可扩展解决方案)+任何 JS 框架(jquery、YUI、ext js...) 。您还应该看看 Akka Framework,它与 Jersey 和 Atmosphere 集成,并允许您使用惯用的 Scala 构建 RIA Web 应用程序。这是 Akka 中的 pub-sub COMET 示例
    • Vaadin + ICEPush。如果您不想接触 JS,那么这对您来说将是一个非常舒适的组合(尽管 ICEpush 还不是企业级解决方案)。
  1. From my point of view, Spring MVC is a very bad choice to build AJAXed/COMETed RIA. ModelAndView component aimed to work with HTML forms and render the entire page at once, tag libraries, validation routines are all better suited for old-fashioned development, based on JSPs and templates. For me, plugging AJAX/COMET into Spring MVC will always be a kind of a hack. However, if you're going to build RESTful services using @MVC (interchanging JSON with your javascript UI), it may work (though I would prefer Jersey/JAXB for those matters).
  2. LIFT was originally designed to work with COMET, so it will be a better choice. Though I would choose something much more lightweight and template-less, than LIFT (as for me, it suffers from the same disease Spring MVC does).
  3. The both security systems cover just basic scenarios, and require a lot of customization to be used in real-world projects.

    That's what I would use for building COMETed RIA in Scala:

    • Jersey (lightweight RESTful services to communicate with JS UI over HTTP/JSON) + Atmosphere (scalable solution for building COMETed applications) + any JS framework (jquery, YUI, ext js, ...). You should also have a look at Akka Framework, which is integrated with the both Jersey and Atmosphere, and allows you building RIA web-apps in idiomatic Scala. Here's a pub-sub COMET example in Akka.
    • Vaadin + ICEPush. It will be much comfortable combination for you, if you don't want to get your hand dirty with JS (though ICEpush is not an enterprise-ready solution yet).
So要识趣 2024-09-13 23:14:32

另一种替代方案,以纯 Java(或任何其他 JVM 语言,包括 Scala)为中心,是 ItsNat Comet

Another alternative, pure Java (or with any other JVM language including Scala) centric is ItsNat Comet.

赤濁 2024-09-13 23:14:31

Novell 在评估了多种不同的技术后,选择 Lift 的 Comet 架构为其 Pulse 产品提供支持。

Lift 的 Comet 实现使用单个 HTTP 连接来轮询页面上任意数量的组件的更改。每个组件都有一个版本号。长轮询包括版本号和组件 GUID。在服务器端,侦听器附加到长轮询请求中列出的所有 GUID。如果任何组件具有更高的版本号(或者在长轮询期间版本号增加),则增量(描述每个版本的更改的一组 JavaScript)将被发送到客户端。应用增量并将客户端上的版本号设置为更改集的最高版本号。

Lift 将长轮询与会话管理集成在一起,这样,如果在长轮询期间请求进入同一 URL 会导致连接匮乏,则长轮询将终止以避免连接匮乏(某些浏览器每个命名服务器最多有 2 个 HTTP 连接,其他最多为 6)。 Lift 还支持用于长轮询请求的 DNS 通配符服务器,这样浏览器中的每个选项卡都可以针对不同的 DNS 通配符服务器进行长轮询。这避免了连接匮乏的问题。

Lift 动态检测 Servlet 在 Jetty 6 和 Jetty 上运行的容器。 7 和(很快)Glassfish,Lift 将使用平台的“延续”实现来避免在长轮询期间使用线程。

Lift 的 JavaScript 可以位于 jQuery 和 YUI 之上(也可以位于 Prototype/Scriptaculous 之上。)实际的轮询代码包括连接失败时的回退以及处理瞬时连接失败的其他“优雅”方式。

我研究过 Atmosphere、CometD、Akka(所有面向 JVM 的 Comet 技术)。没有一个(在我评估它们时)支持每页多个组件或避免连接匮乏。

Novell 从头开始​​,出于一些非常充分的理由选择 Lift 来支持 Pulse。

在安全性方面,Lift 轻而易举地击败了 Spring + Spring Security。请参阅 http://www.mail-archive.com/[email protected]/msg13020.html

基本上,Lift 的安全性已融入您的应用程序中。默认情况下,Lift 应用程序可以抵抗常见问题(跨站点脚本、重放攻击、跨站点请求伪造)。默认情况下,Lift 应用程序可以防止参数篡改。 Lift 的站点地图定义了站点导航和访问控制规则。这意味着您永远不会有别人无法点击的链接。您不需要拥有必须独立于应用程序进行配置的外部过滤器(例如 Spring Security)(哎呀...移动了页面,但忘记确保 Spring Security XML 文件已更新。)

哦。 ..如果您不想使用模板语言,这里有一个完整的 Lift Comet 聊天组件:

class Chat extends CometActor with CometListener {
  private var msgs: List[String] = Nil

  def registerWith = ChatServer

  override def lowPriority = {
    case m: List[String] => msgs = m; reRender(false)
  }

  def render = {
    <div>
    <ul>
    {
      msgs.reverse.map(m => <li>{m}</li>)
    }
    </ul>
    <lift:form>
    {
      SHtml.text("", s => ChatServer ! s)
    }
    <input type="submit" value="Chat"/>
    </lift:form>
    </div>
  }
}

并将其插入页面:

Lift's Comet Architecture which was selected by Novell to power their Pulse product after they evaluated a number of different technologies.

Lift's Comet implementation uses a single HTTP connection to poll for changes to an arbitrary number of components on the page. Each component has a version number. The long poll includes the version number and the component GUID. On the server side, a listener is attached to all of the GUIDs listed in the long poll requests. If any of the components has a higher version number (or the version number increases during the period of the long poll), the deltas (a set of JavaScript describing the change from each version) is sent to the client. The deltas are applied and the version number on the client is set to the highest version number for the change set.

Lift integrates long polling with session management so that if a request comes into the same URL during a long poll that would cause connection starvation, the long poll is terminated to avoid connection starvation (some browsers have a maximum of 2 HTTP connections per named server, others have a max of 6). Lift also supports DNS wild-carded servers for long poll requests such that each tab in the browser can do long polling against a different DNS wildcarded server. This avoids the connection starvation issues.

Lift dynamically detects the container the Servlet is running in and on Jetty 6 & 7 and (soon) Glassfish, Lift will use the platform's "continuations" implementation to avoid using a thread during the long poll.

Lift's JavaScript can sit on top of jQuery and YUI (and could sit on top of Prototype/Scriptaculous as well.) The actual polling code includes back-off on connection failures and other "graceful" ways of dealing with transient connection failures.

I've looked at Atmosphere, CometD, Akka (all JVM-oriented Comet technologies). None had (at the time I evaluated them) support for multiple components per page or connection starvation avoidance.

Novell started from scratch and chose Lift to power Pulse for some very good reasons.

In terms of security, Lift beats Spring + Spring Security hands down. See http://www.mail-archive.com/[email protected]/msg13020.html

Basically, Lift's security is baked into your application. Lift apps are resistant to common problems (cross site scripting, replay attacks, cross site request forgeries) by default. Lift apps are resistant to parameter tampering by default. Lift's sitemap defines site navigation and access control rules. This means you never have a link that someone can't click on. You don't need to have an external filter (e.g., Spring Security) that you have to configure independently from you app (whoops... moved a page, but forgot to make sure the Spring Security XML file was updated.)

Oh... and if you don't want to use a templating language, here's a complete Lift Comet chat component:

class Chat extends CometActor with CometListener {
  private var msgs: List[String] = Nil

  def registerWith = ChatServer

  override def lowPriority = {
    case m: List[String] => msgs = m; reRender(false)
  }

  def render = {
    <div>
    <ul>
    {
      msgs.reverse.map(m => <li>{m}</li>)
    }
    </ul>
    <lift:form>
    {
      SHtml.text("", s => ChatServer ! s)
    }
    <input type="submit" value="Chat"/>
    </lift:form>
    </div>
  }
}

And to insert this into a page: <lift:comet type="Chat"/>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文