免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6973 | 回复: 0
打印 上一主题 下一主题

基于netty实现的web controller框架 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-02-02 17:54 |只看该作者 |倒序浏览
本帖最后由 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:

  1. @Controller(method="GET", uriPattern="^/test/(\\w+)")
  2. public class Test extends HttpNormalHandler {

  3.     @UriSection(1)
  4.     private String name;

  5.     @Override
  6.     protected void handle(FullHttpRequest request, FullHttpResponse response) {
  7.         // TODO Auto-generated method stub
  8.         String words = "hello " + name;
  9.         response.content().writeBytes(words.getBytes());
  10.         response.headers().set("Content-Type", "text/plain");
  11.         response.headers().set("Content-Length", response.content().readableBytes());
  12.     }

  13.     @Override
  14.     protected void atlast() {
  15.         // TODO Auto-generated method stub

  16.     }

  17.     public static void main(String[] args) {
  18.         // TODO Auto-generated method stub
  19.         HapporAutomaticContext context = new HapporAutomaticContext();
  20.         context.runServer();
  21.     }

  22. }
复制代码
运行程序,在浏览器访问http://localhost/test/someone,显示hello someone。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP