netty 实现tomcat的示例代码

本站所有内容来自互联网收集,仅供学习和交流,请勿用于商业用途。如有侵权、不妥之处,请第一时间联系我们删除!Q群:迪思分享
免费资源网 – https://freexyz.cn/

目录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


© 版权声明
THE END
★喜欢这篇文章吗?喜欢的话,麻烦动动手指支持一下!★
点赞7 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容