- 论坛徽章:
- 0
|
本帖最后由 xphh2008 于 2016-02-02 17:56 编辑
最近使用netty开发webservice,想到springMVC的优势,也想做一个类似的框架,完全基于netty的,不使用tomcat做HTTP容器。
因为工作关系,大部分都是聚焦在REST接口开发上,所以其实对我来说,并不需要整个MVC框架,只需要一个controller框架就够了。
同时,要能和spring容器结合,便于注入,便于使用其他组件如数据库、缓存等等。
于是我就写了一个:https://github.com/xphh/happor
这里有文档说明:https://github.com/xphh/happor/wiki
目前happor框架支持以下特性:
- HTTP消息链式处理(根据URI路由)
- 支持同步handler,异步handler,转发handler
- 支持filter
- 支持URI自动解析注入
- 可与spring集成,提供自定义tag
- 支持注解开发
我知道用netty实现web框架的人应该也不少了 ,这个话题有兴趣的朋友也可以在这里一起讨论讨论哈。
附demo:
- @Controller(method="GET", uriPattern="^/test/(\\w+)")
- public class Test extends HttpNormalHandler {
- @UriSection(1)
- private String name;
- @Override
- protected void handle(FullHttpRequest request, FullHttpResponse response) {
- // TODO Auto-generated method stub
- String words = "hello " + name;
- response.content().writeBytes(words.getBytes());
- response.headers().set("Content-Type", "text/plain");
- response.headers().set("Content-Length", response.content().readableBytes());
- }
- @Override
- protected void atlast() {
- // TODO Auto-generated method stub
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- HapporAutomaticContext context = new HapporAutomaticContext();
- context.runServer();
- }
- }
复制代码 运行程序,在浏览器访问http://localhost/test/someone,显示hello someone。 |
|