- java.lang.Object
-
- org.redkale.net.Servlet<HttpContext,HttpRequest,HttpResponse>
-
- org.redkale.net.http.HttpServlet
-
- 直接已知子类:
HttpResourceServlet
,WatchServlet
,WebSocketServlet
public class HttpServlet extends Servlet<HttpContext,HttpRequest,HttpResponse>
HTTP版的Servlet, 执行顺序 execute --> preExecute --> authenticate --> HttpMapping对应的方法详情见: https://redkale.org
- 作者:
- zhangjx
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected static class
HttpServlet.ActionEntry
-
字段概要
-
从类继承的字段 org.redkale.net.Servlet
_nonBlocking
-
-
构造器概要
构造器 构造器 说明 HttpServlet()
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
authenticate(HttpRequest request, HttpResponse response)
用户登录或权限验证, 注解为@HttpMapping.auth == true 的方法会执行authenticate方法, 若验证成功则必须调用response.nextEvent();进行下一步操作, 例如:
void
execute(HttpRequest request, HttpResponse response)
protected void
finish404(HttpRequest request, HttpResponse response)
提供404状态码的可定制接口protected void
finish405(HttpRequest request, HttpResponse response)
提供405状态码的可定制接口void
postStart(HttpContext context, AnyValue config)
protected void
preExecute(HttpRequest request, HttpResponse response)
预执行方法,在execute方法之前运行,设置当前用户信息,或者加入常规统计和基础检测,例如 :
-
从类继承的方法 org.redkale.net.Servlet
destroy, init, isNonBlocking
-
-
-
-
方法详细资料
-
postStart
public void postStart(HttpContext context, AnyValue config)
-
finish404
protected void finish404(HttpRequest request, HttpResponse response) throws IOException
提供404状态码的可定制接口- 参数:
request
- HttpRequestresponse
- HttpResponse- 抛出:
IOException
- IOException- 从以下版本开始:
- 2.8.0
-
finish405
protected void finish405(HttpRequest request, HttpResponse response) throws IOException
提供405状态码的可定制接口- 参数:
request
- HttpRequestresponse
- HttpResponse- 抛出:
IOException
- IOException- 从以下版本开始:
- 2.8.0
-
preExecute
protected void preExecute(HttpRequest request, HttpResponse response) throws IOException
预执行方法,在execute方法之前运行,设置当前用户信息,或者加入常规统计和基础检测,例如 :
@Override public void preExecute(final HttpRequest request, final HttpResponse response) throws IOException { //设置当前用户信息 final String sessionid = request.getSessionid(false); if (sessionid != null) request.setCurrentUserid(userService.currentUserid(sessionid)); if (finer) response.recycleListener((req, resp) -> { //记录处理时间比较长的请求 long e = System.currentTimeMillis() - ((HttpRequest) req).getCreateTime(); if (e > 200) logger.finer("http-execute-cost-time: " + e + " ms. request = " + req); }); response.nextEvent(); }
- 参数:
request
- HttpRequestresponse
- HttpResponse- 抛出:
IOException
- IOException
-
authenticate
protected void authenticate(HttpRequest request, HttpResponse response) throws IOException
用户登录或权限验证, 注解为@HttpMapping.auth == true 的方法会执行authenticate方法, 若验证成功则必须调用response.nextEvent();进行下一步操作, 例如:
@Override public void authenticate(HttpRequest request, HttpResponse response) throws IOException { Serializable userid = request.currentUserid(); if (userid == null) { response.finishJson(RET_UNLOGIN); return; } response.nextEvent(); }
- 参数:
request
- HttpRequestresponse
- HttpResponse- 抛出:
IOException
- IOException
-
execute
public void execute(HttpRequest request, HttpResponse response) throws IOException
- 指定者:
execute
在类中Servlet<HttpContext,HttpRequest,HttpResponse>
- 抛出:
IOException
-
-