use of org.eweb4j.mvc.action.ActionExecution in project eweb4j-framework by laiweiwei.
the class EWebServlet method doGet.
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
Context context = null;
try {
// 2
String err = EWeb4JConfig.start(ConfigConstant.START_FILE_NAME);
// 启动eweb4j
if (err != null) {
this.printHtml(err, response.getWriter());
return;
}
// 1 初始化环境
context = this.initContext(request, response);
// 最主要的还是提供给 org.eweb4j.i18n.Lang.java 类使用
MVC.getThreadLocal().set(context);
// 设置国际化语言
Lang.change(request.getLocale());
// 3.URI解析
String uri = this.parseURL(request);
context.setUri(uri);
// 拿到BaseURL
parseBaseUrl(context);
// HTTP Method 解析
String reqMethod = this.parseMethod(request);
context.setHttpMethod(reqMethod);
// 4.外部前置拦截器
InterExecution before_interExe = new InterExecution("before", context);
if (before_interExe.findAndExecuteInter()) {
before_interExe.showErr();
return;
}
// method + uri,用来判断是否有Action与之绑定
ActionExecution actionExe = new ActionExecution(uri, reqMethod, context);
if (actionExe.findAction()) {
// 5.execute the action
actionExe.execute();
return;
}
// log
this.normalReqLog(uri);
} catch (Exception e) {
e.printStackTrace();
String info = CommonUtil.getExceptionString(e);
LogFactory.getMVCLogger(EWebFilter.class).error(info);
this.printHtml(info, response.getWriter());
} finally {
// 清空临时文件
if (context != null && !context.getUploadMap().isEmpty())
for (Iterator<Entry<String, List<UploadFile>>> it = context.getUploadMap().entrySet().iterator(); it.hasNext(); ) {
Entry<String, List<UploadFile>> en = it.next();
if (en.getValue() == null)
continue;
for (UploadFile f : en.getValue()) {
FileUtil.deleteFile(f.getTmpFile());
}
}
}
}
use of org.eweb4j.mvc.action.ActionExecution in project eweb4j-framework by laiweiwei.
the class EWebFilter method doFilter.
/**
* 执行Filter
*/
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
Context context = null;
try {
// 2
String err = EWeb4JConfig.start(ConfigConstant.START_FILE_NAME);
// 启动eweb4j
if (err != null) {
this.printHtml(err, res.getWriter());
return;
}
// 1 初始化环境
context = this.initContext(request, response);
// 最主要的还是提供给 org.eweb4j.i18n.Lang.java 类使用
MVC.getThreadLocal().set(context);
// 设置国际化语言
Lang.change(request.getLocale());
// 3.URI解析
String uri = this.parseURL(request);
context.setUri(uri);
// 拿到BaseURL
parseBaseUrl(context);
// HTTP Method 解析
String reqMethod = this.parseMethod(request);
context.setHttpMethod(reqMethod);
// 4.外部前置拦截器
InterExecution before_interExe = new InterExecution("before", context);
if (before_interExe.findAndExecuteInter()) {
before_interExe.showErr();
return;
}
// method + uri,用来判断是否有Action与之绑定
ActionExecution actionExe = new ActionExecution(uri, reqMethod, context);
if (actionExe.findAction()) {
// 5.execute the action
actionExe.execute();
return;
}
// log
this.normalReqLog(uri);
// chain
chain.doFilter(req, res);
} catch (Exception e) {
e.printStackTrace();
String info = CommonUtil.getExceptionString(e);
LogFactory.getMVCLogger(EWebFilter.class).error(info);
this.printHtml(info, res.getWriter());
} finally {
// 清空临时文件
if (context != null && !context.getUploadMap().isEmpty())
for (Iterator<Entry<String, List<UploadFile>>> it = context.getUploadMap().entrySet().iterator(); it.hasNext(); ) {
Entry<String, List<UploadFile>> en = it.next();
if (en.getValue() == null)
continue;
for (UploadFile f : en.getValue()) {
FileUtil.deleteFile(f.getTmpFile());
}
}
}
}
Aggregations