📄 webportalservlet.java~10~
字号:
System.out.println("reqUrl=======" + reqUrl);
//if(reqUrl.indexOf("?")>0)
// reqUrl = reqUrl.substring(0,reqUrl.indexOf("?"));
String servletpath = request.getServletPath();
String action = reqUrl.substring(reqUrl.indexOf(servletpath)+servletpath.length() + 1);
System.out.println("reqUrl=======" + reqUrl);
System.out.println("ServletPath = " + servletpath);
System.out.println("Action = " + action);
if (logWriter.isDebugEnabled())
{
logWriter.debug("ReqURL = " + reqUrl);
logWriter.debug("ServletPath = " + servletpath);
logWriter.debug("Action = " + action);
}
String queryStr = request.getQueryString();
if((queryStr == null)||(queryStr.length() == 0))
queryStr = servletpath+"/"+action;
else
queryStr = servletpath+"/"+action+"?"+queryStr;
if (logWriter.isDebugEnabled())
logWriter.debug("Try to execute the action: " + action);
RequestContext context = new RequestContext(request, response);
context.config = confRepository;
PresentManager presentMgr = confRepository.getPresentMgr();
PresentHandler handler = null;
//get the module name to decide if need record the action log
String modulename = "";
if(action.indexOf("/")>0)
modulename = action.substring(0,action.indexOf("/"));
Module module = null;
HttpSession session = request.getSession(false);
if (session == null && logWriter.isInfoEnabled())
logWriter.info("Can not retrieve the session now");
// User wp = (User)context.getUser();
try
{
ActionDef actionDef = (ActionDef)confRepository.getAction(action);
if (actionDef == null)
{
logWriter.error("Action [" + action + "] can not been found");
throw new NoSuchActionException(action);
}
String filterIPs = actionDef.getFilterIPs();
if (filterIPs != null)
{
String remoteIP = request.getRemoteAddr();
if (logWriter.isDebugEnabled())
{
logWriter.debug("Now check whether the remote IP is allowed:" + filterIPs + "/" +remoteIP);
}
if (!allowAccessFromIP(remoteIP , filterIPs))
throw new AccessDeniedException();
}
/**
User principal = (User)context.getUser();
String principalNeed = actionDef.getPrincipal();
if (principalNeed != null && principalNeed.length() > 0)
{
if (principal == null)
{
context.getResponse().setHeader("Cache-Control","no-cache");
throw new NullPrincipalException();
}
else
{
if (logWriter.isDebugEnabled())
{
StringBuffer debugText = new StringBuffer(1024);
debugText.append("need principal name: ");
debugText.append(principalNeed);
logWriter.debug(debugText);
}
logWriter.info("principal status: -->" + principal.getStatus());
if ((principal.getStatus() != 1)||(!principal.hasRight(principalNeed)))
{
if (logWriter.isInfoEnabled())
{
StringBuffer out = new StringBuffer("Current user with principle [");
out.append(principal.getName());
out.append("] don't have right to access the action [").append(action).append(']');
logWriter.info(out);
}
throw new AccessDeniedException();
}
}
}
*/
//check if it needs safety thinking,if yes ,then forward to the safety
switch(actionDef.getProtocol() )
{
case ActionDef.REQUEST_TYPE_FREEPKI:
{
if(!context.ifMemberNeedPKI())
break;
}
case ActionDef.REQUEST_TYPE_SIGNED:
{
if(session == null) return;
String clientCert = (String)session.getAttribute("clientCert");
if(clientCert == null)
{
String oldURL = reqUrl.substring(reqUrl.indexOf(servletpath)+1);
if(request.getQueryString() != null)
oldURL = oldURL +"?"+ request.getQueryString();
if(logWriter.isDebugEnabled())
logWriter.debug("set attribute oldURL: "+oldURL+" and give the control to PKI Servlet");
request.setAttribute("oldURL",oldURL);
logWriter.info("oldURL to PKI:["+oldURL+"]");
throw new NeedPKIException();
}
}
break;
}
context.action = actionDef;
context.prepareParams();
//TransactionManager transMgr = context.getTransManager();
BizObject bizObject = new BizObject();
//得到Command对象映射,执行相关的逻辑
CommandMap aMap = actionDef.getFirstCommandMap();
while(aMap != null)
{
String cmdName = aMap.getName();
//context.curCommand = cmdName;
Command aCommand = aMap.getCommand();
PresentManager cmdPresent = aMap.getPresentManager();
CmdResult result = null;
try
{
long timebeforecmd = System.currentTimeMillis();
result = aCommand.execute(context, aMap);
session = request.getSession(false);
long timeused =System.currentTimeMillis()-timebeforecmd;
if (logWriter.isInfoEnabled())
logWriter.info(new StringBuffer(cmdName).append(" used time(ms):[ ").append(timeused).append(']'));
//如果需要传递参数则需要将结果合并到context中
bizObject.setBizComp(result.getBizComp());
bizObject.setCode(result.getCode());
if(aMap.isResultnext())
context.mergeBizComp(result.getBizComp());
if (logWriter.isDebugEnabled())
logWriter.debug("command [" + cmdName + "] return :" + result.getCode());
if (cmdPresent != null)
{
if (logWriter.isDebugEnabled())
logWriter.debug("Dumping current present manager:" + cmdPresent.getHashHandlers());
handler = cmdPresent.getHandler(result.getCode());
}
else
{
if (logWriter.isDebugEnabled())
logWriter.debug("Can not find the present manager for command [" + cmdName + ']');
}
if(handler != null)
{
if (logWriter.isDebugEnabled())
{
logWriter.debug("Find a present handler and break the loop >>>>>>>>>");
logWriter.debug("Command Name = " + cmdName);
logWriter.debug("Return Code = " + result.getCode());
logWriter.debug("Handler Name = " + handler.handler);
}
break;
}
else
{
logWriter.debug("Can't get corresponding handler for command: " + cmdName);
}
}
catch(Exception e)
{
//lookup error handler for the exception
context.getRequest().setAttribute(REQ_ERROR_KEY ,e);
if (cmdPresent != null)
handler = cmdPresent.getHandler(e);
if (handler == null)
throw e;
else
{
logWriter.error("Catch an exception in the main servlet:");
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
e.printStackTrace(new PrintStream(out));
logWriter.error(out.toString());
break;
}
}
aMap = context.goNextStep();
if (logWriter.isDebugEnabled())
{
logWriter.debug("Goto next command >>>>>>>>>>>>>");
logWriter.debug("Current CMD = " + cmdName);
logWriter.debug("Next Mapper = " + aMap);
}
}
if(session != null)
{
String key = actionDef.getSessionkey();
if(key != null){
if(actionDef.isFinalstep()){
session.removeAttribute(key);
}
else if(actionDef.getMultistep() == 0)
{
String sOldUrl = (String)session.getAttribute(SESS_PREV_URL);
String sOldKey = (String)session.getAttribute(SESS_PREV_KEY);
if(!sOldUrl.equalsIgnoreCase(reqUrl) && sOldKey != null){
session.removeAttribute(sOldKey);
}
}
}
session.setAttribute(SESS_PREV_URL , reqUrl);
if(key != null)
session.setAttribute(SESS_PREV_KEY , key);
}
/*
if (logWriter.isDebugEnabled())
{
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
bizObject.dump(new PrintStream(out));
logWriter.debug(out.toString());
}
*/
request.setAttribute(CmdResult.RESULT_KEY , bizObject);
}
catch(Exception e)
{
logWriter.warn("Catch an exception in the main servlet:");
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
e.printStackTrace(new PrintStream(out));
logWriter.error(out.toString());
context.getRequest().setAttribute(REQ_ERROR_KEY , e);
handler = presentMgr.getHandler(e);
if (handler == null)
logWriter.error("But the main servlet can't find the handler to handle this exception");
}
catch(Throwable t)
{
logWriter.warn("Catch an Throwable in the main servlet:");
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
t.printStackTrace(new PrintStream(out));
logWriter.error(out.toString());
}
finally
{
context.cleanup();
}
long timeUsedInServlet = 0;
if (logWriter.isInfoEnabled())
{
timeUsedInServlet =System.currentTimeMillis() - timeStartServlet;
logWriter.info(new StringBuffer( "Total Servlet used:(ms):[ " ).append(timeUsedInServlet).append("]"));
}
if (handler == null)
{
logWriter.info("Using the default handler to handle the response page");
handler = presentMgr.getHandler(handler.HANDLER_DEF_ID);
}
if (handler != null)
handler.present(context , confRepository);
if (logWriter.isInfoEnabled())
{
long timeUsedInJSP = System.currentTimeMillis() - timeUsedInServlet - timeStartServlet;
logWriter.info(new StringBuffer("Time used in JSP used:(ms)[").append(timeUsedInJSP).append("]"));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -