@Override public void handle(Exception e) { if (!ExceptionHandler.isResetByPeer(e)) { var response = WebContext.response(); var request = WebContext.request(); if (e instanceof BladeException) { this.handleBladeException((BladeException) e, request, response); } else if (ValidatorException.class.isInstance(e)) { this.handleValidators(ValidatorException.class.cast(e), request, response); } else { this.handleException(e, request, response); } } }
@Override public void handle(Exception e) { if (!ExceptionHandler.isResetByPeer(e)) { var response = WebContext.response(); var request = WebContext.request(); if (e instanceof BladeException) { this.handleBladeException((BladeException) e, request, response); } else if (ValidatorException.class.isInstance(e)) { this.handleValidators(ValidatorException.class.cast(e), request, response); } else { this.handleException(e, request, response); } } }
@Override public void close() throws IOException { try { this.flush(); FileChannel file = new FileInputStream(this.file).getChannel(); long fileLength = file.size(); HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); httpResponse.headers().set(HttpConst.CONTENT_LENGTH, fileLength); httpResponse.headers().set(HttpConst.DATE, DateKit.gmtDate()); httpResponse.headers().set(HttpConst.SERVER, "blade/" + Const.VERSION); boolean keepAlive = WebContext.request().keepAlive(); if (keepAlive) { httpResponse.headers().set(HttpConst.CONNECTION, HttpConst.KEEP_ALIVE); } // Write the initial line and the header. ctx.write(httpResponse); ctx.write(new DefaultFileRegion(file, 0, fileLength), ctx.newProgressivePromise()); // Write the end marker. ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); } finally { if(null != outputStream){ outputStream.close(); } } }
@Override public void close() throws IOException { try { this.flush(); FileChannel file = new FileInputStream(this.file).getChannel(); long fileLength = file.size(); HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); httpResponse.headers().set(HttpConst.CONTENT_LENGTH, fileLength); httpResponse.headers().set(HttpConst.DATE, DateKit.gmtDate()); httpResponse.headers().set(HttpConst.SERVER, "blade/" + Const.VERSION); boolean keepAlive = WebContext.request().keepAlive(); if (keepAlive) { httpResponse.headers().set(HttpConst.CONNECTION, HttpConst.KEEP_ALIVE); } // Write the initial line and the header. ctx.write(httpResponse); ctx.write(new DefaultFileRegion(file, 0, fileLength), ctx.newProgressivePromise()); // Write the end marker. ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); } finally { if(null != outputStream){ outputStream.close(); } } }
Request request = WebContext.request();
Request request = WebContext.request();
/** * Render by json * * @param json json content */ default void json(String json) { if (null == json) return; if (null == contentType()) { if (Objects.requireNonNull(WebContext.request()).isIE()) { this.contentType(Const.CONTENT_TYPE_HTML); } else { this.contentType(Const.CONTENT_TYPE_JSON); } } this.body(json); }
/** * Render by json * * @param json json content */ default void json(String json) { if (null == json) return; if (null == contentType()) { if (Objects.requireNonNull(WebContext.request()).isIE()) { this.contentType(Const.CONTENT_TYPE_HTML); } else { this.contentType(Const.CONTENT_TYPE_JSON); } } this.body(json); }
private FullHttpResponse handleException(Throwable e) { Request request = WebContext.request(); Response response = WebContext.response(); String method = request.method(); String uri = request.uri(); Exception srcException = (Exception) e.getCause().getCause(); if (srcException instanceof BladeException) { } else { log500(log, method, uri); } if (null != WebContext.blade().exceptionHandler()) { WebContext.blade().exceptionHandler().handle(srcException); } else { log.error("", srcException); } return routeHandler.handleResponse( request, response, WebContext.get().getChannelHandlerContext() ); }
private FullHttpResponse handleException(Throwable e) { Request request = WebContext.request(); Response response = WebContext.response(); String method = request.method(); String uri = request.uri(); Exception srcException = (Exception) e.getCause().getCause(); if (srcException instanceof BladeException) { } else { log500(log, method, uri); } if (null != WebContext.blade().exceptionHandler()) { WebContext.blade().exceptionHandler().handle(srcException); } else { log.error("", srcException); } return routeHandler.handleResponse( request, response, WebContext.get().getChannelHandlerContext() ); }
/** * 返回当前登录用户 * * @return */ public static Users getLoginUser() { Session session = com.blade.mvc.WebContext.request().session(); if (null == session) { return null; } Users user = session.attribute(TaleConst.LOGIN_SESSION_KEY); return user; }
public static boolean isLogin() { return null != WebContext.request().session().attribute(Constant.LOGIN_SESSION_KEY); }
@Override public void handle(Exception e) { if (!ExceptionHandler.isResetByPeer(e)) { var response = WebContext.response(); var request = WebContext.request(); if (e instanceof BladeException) { this.handleBladeException((BladeException) e, request, response); } else if (ValidatorException.class.isInstance(e)) { this.handleValidators(ValidatorException.class.cast(e), request, response); } else { this.handleException(e, request, response); } } }
@Override public void close() throws IOException { try { this.flush(); FileChannel file = new FileInputStream(this.file).getChannel(); long fileLength = file.size(); HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); httpResponse.headers().set(HttpConst.CONTENT_LENGTH, fileLength); httpResponse.headers().set(HttpConst.DATE, DateKit.gmtDate()); httpResponse.headers().set(HttpConst.SERVER, "blade/" + Const.VERSION); boolean keepAlive = WebContext.request().keepAlive(); if (keepAlive) { httpResponse.headers().set(HttpConst.CONNECTION, HttpConst.KEEP_ALIVE); } // Write the initial line and the header. ctx.write(httpResponse); ctx.write(new DefaultFileRegion(file, 0, fileLength), ctx.newProgressivePromise()); // Write the end marker. ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); } finally { if(null != outputStream){ outputStream.close(); } } }
Request request = WebContext.request();
/** * Render by json * * @param json json content */ default void json(String json) { if (null == json) return; if (null == contentType()) { if (Objects.requireNonNull(WebContext.request()).isIE()) { this.contentType(Const.CONTENT_TYPE_HTML); } else { this.contentType(Const.CONTENT_TYPE_JSON); } } this.body(json); }
/** * 分页 * * @param limit * @return */ public static Page<Contents> articles(int limit) { Request request = WebContext.request(); Integer page = request.attribute("page_num"); page = null == page ? request.queryInt("page", 1) : page; page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page; Page<Contents> articles = new Contents().where("type", Types.ARTICLE).and("status", Types.PUBLISH).page(page, limit, "created desc"); request.attribute("articles", articles); if (page > 1) { WebContext.request().attribute("title", "第" + page + "页"); } request.attribute("is_home", true); request.attribute("page_prefix", "/page"); return articles; }
private FullHttpResponse handleException(Throwable e) { Request request = WebContext.request(); Response response = WebContext.response(); String method = request.method(); String uri = request.uri(); Exception srcException = (Exception) e.getCause().getCause(); if (srcException instanceof BladeException) { } else { log500(log, method, uri); } if (null != WebContext.blade().exceptionHandler()) { WebContext.blade().exceptionHandler().handle(srcException); } else { log.error("", srcException); } return routeHandler.handleResponse( request, response, WebContext.get().getChannelHandlerContext() ); }