目录netty 实现tomcat自定义基础类netty 服务端使用测试
netty 实现tomcat
自定义基础类
TomcatServlet
public abstract class TomcatServlet {
public void service(ServletRequest request, ServletResponse response){
if (“GET”.equalsIgnoreCase(request.getMethod())){
doGet(request, response);
}else if (“POST”.equalsIgnoreCase(request.getMethod())){
doPost(request, response);
}else {
doResponse(response, “暂不支持其它请求方法”);
}
}
public abstract void doGet(ServletRequest request, ServletResponse response);
public abstract void doPost(ServletRequest request, ServletResponse response);
public void doResponse(ServletResponse response, String message){
response.write(message);
}
}
ServletRequest
@Data
public class ServletRequest {
private ChannelHandlerContext context;
private HttpRequest httpRequest;
public ServletRequest(){
}
public ServletRequest(ChannelHandlerContext context, HttpRequest httpRequest){
this.context = context;
this.httpRequest = httpRequest;
}
public String getMethod(){
return httpRequest.method().name();
}
public HttpHeaders getHeaders(){
return httpRequest.headers();
}
public Map
暂无评论内容