利用netty自己手寫一個tomcat
基於javaee基礎上執行的一個web容器
http 伺服器
socktet上支援 TCP/IP HTTP FTP
接受客戶端的一個http url請求,對應後臺有一個servlet
netty屬於協議層,底層框架。
request response
4.0版本
public class DNTomcat{
public void start(int port){
Event LoopGroup bossGroup=new NioEventLoopGroup();
EventLoopGroup workGroup=new NioEventLoopGroup();
ServerBootstrap b=new ServerBootstrap();
b.group(bossGroup,workGroup).channel(NioServerSocketChannel.class).
childHandler(new ChannelInitializer<SocketChannel> (){
protected void initChannel(SocketChannel args0) throws Excepton{
sc.pipeline().addLast(new HttpResponseEncoder());
sc.pipeline().addLast(new HttpRequestDecoder());
sc.pipeline().addLast(new DNTomcatHandler());
}})
.option(ChannelOption.SO_+BACKLOG,128)
.childOption(ChannelOption.SO_KEEPALIVE,true);
ChannelFutrue f=b.bind(port).sync();
f.channel
}
}
public class DNResponseP
}
public class DNTomcatHandler
web.xml
<server-mapping>
</server-mapping>
name
className
private static final Map<Pattern,Class<?>>
Pattern=pattern.replacAll("\\.",*");
String className=CustomConfig.getString("servlet");
if(!ServletMapping.containsKey(pattern)
servletMapping.put())
static{
for(String key:CustomConfig.getKeys()){
if(key.startWith("servlet")){
String name=key.replaceFirst("servlet","");
else{
continue;
String pattern=CustomConig.getString("servlet"+name+"urlPattern");
String className=CustomConfig.getString("Servlet.");
for(Entry<Pattern,Clas<?> entry:servletMapping.entrySet()){
if(entry.getKey().matcher(uri).matches()){
DNServlet serlet (DNServlet)entry.getValue().newInstancse();
if("get".equesIgnoreCase(method)){
servlet.doGet(request,response);
}else{
servlet.doPost(request,response);
}?
if(!hasPattern){
String out=String.format("404not Found,URL:%S,method:%S",uri,method);
}
serlvet.fist.urlPattern=/first/quey*