java 使用 Netty 的 Servlet API 实现

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7439955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:58:45  来源:igfitidea点击:

Servlet API implementation using Netty

javaservletsnionetty

提问by Adam Gent

Has anyone made a Servlet API implementation built on top of Netty? I'm tempted to build my own as I can't google an implementation.

有没有人在 Netty 之上构建了一个 Servlet API 实现?我很想建立自己的,因为我无法谷歌实现。

Basically I'm looking to support just enough to get jersey working (hopefully jersey is not doing any threadlocal stuff).

基本上,我希望支持足以让 jersey 工作(希望 jersey 没有做任何线程本地的东西)。

采纳答案by Martin Matula

Jersey does not require servlet - runs fine even with the lightweight http server included in JDK or even runs with Grizzly NIO framework (which is similar to Netty - see grizzly.java.net). To see what it takes to make it run with Netty, you may want to look at jersey-grizzly2 module in Jersey workspace - would be nice if you would be willing to develop that and contribute to the Jersey project. Now, to disappoint you, Jersey does use ThreadLocals. We have been planning to introduce support for non-blocking async calls, but that requires a fair amount of refactoring, so will only come with 2.0 version (implementing JAX-RS 2.0 once that's final). Anyway, apart from the non-blocking stuff, it is still useful to run it on Grizzly-like framework such as Netty for its "light-weightness".

Jersey 不需要 servlet - 即使使用 JDK 中包含的轻量级 http 服务器也能正常运行,甚至可以使用 Grizzly NIO 框架(类似于 Netty - 请参阅 grizzly.java.net)。要了解让它与 Netty 一起运行需要什么,您可能需要查看 Jersey 工作区中的 jersey-grizzly2 模块 - 如果您愿意开发它并为 Jersey 项目做出贡献,那就太好了。现在,让您失望的是,Jersey 确实使用了 ThreadLocals。我们一直在计划引入对非阻塞异步调用的支持,但这需要大量的重构,所以只有 2.0 版本(一旦最终版本实现 JAX-RS 2.0)。不管怎样,除了非阻塞的东西,在类似 Grizzly 的框架上运行它仍然很有用,比如 Netty,因为它的“轻量级”。

回答by Bob Stiles

If you want use Jerseywith Netty, you probably need to be safe and use org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory

如果你想使用Jerseywith Netty,你可能需要安全并使用org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory

not,

不是,

org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory

This will allow the ThreadLocalstuff work correctly under load.

这将使这些ThreadLocal东西在负载下正常工作。

Of course, when Jerseyupgrades to not use ThreadLocal, but ChannelLocal, this will not longer be needed.

当然,当Jersey升级到不使用ThreadLocal,但是ChannelLocal,这将不再需要。

回答by cgbystrom

If you want to get Jersey working with Netty you can use the bindings available at https://github.com/cgbystrom/jersey-netty

如果你想让 Jersey 与 Netty 一起工作,你可以使用https://github.com/cgbystrom/jersey-netty 上提供的绑定

回答by Anton Bessonov

Do you looking for Netty-Servlet-bridge?

您在寻找Netty-Servlet-bridge吗?

This project provides a Servlet API implementation for Netty.IO framework (http://netty.io/).

Netty Servlet Bridge allows integration of existing Servlet API based web-applications into the Netty-backed infrastructure.

该项目为 Netty.IO 框架(http://netty.io/)提供了一个 Servlet API 实现。

Netty Servlet Bridge 允许将现有的基于 Servlet API 的 Web 应用程序集成到 Netty 支持的基础设施中。