servletPath = aRequest.getServletPath();
//logger.info("servletPath:" + servletPath);
String actionName = getActionName(servletPath);
GenericDispatcher gd = new GenericDispatcher(actionName, false);
ActionContext context = gd.prepareContext();
//logger.info("actionName:" + actionName);
InfoGluePrincipal principal = (InfoGluePrincipal)aRequest.getSession().getAttribute("infogluePrincipal");
if(principal != null)
aRequest.setAttribute("infoglueRemoteUser", principal.getName());
aRequest.setAttribute("webwork.request_url", aRequest.getRequestURL());
ServletActionContext.setContext(aRequest, aResponse, getServletContext(), actionName);
gd.prepareValueStack();
ActionResult ar = null;
try
{
gd.executeAction();
ar = gd.finish();
}
catch (Throwable e)
{
log.warn("Could not execute action:" + e.getMessage());
try
{
aResponse.sendError(404, "Could not execute action [" + actionName + "]:" + e.getMessage() + getHTMLErrorMessage(e));
}
catch (IOException e1)
{
}
}
if (ar != null && ar.getActionException() != null)
{
log.warn("Could not execute action:" + ar.getActionException().getMessage());
//log.error("Could not execute action", ar.getActionException());
try
{
aResponse.sendError(500, ar.getActionException().getMessage() + getHTMLErrorMessage(ar.getActionException()));
}
catch (IOException e1)
{
}
}
// check if no view exists
if (ar != null && ar.getResult() != null && ar.getView() == null && !ar.getResult().equals(Action.NONE)) {
try
{
aResponse.sendError(404, "No view for result [" + ar.getResult() + "] exists for action [" + actionName + "]");
}
catch (IOException e)
{
}
}
if (ar != null && ar.getView() != null && ar.getActionException() == null)
{
String view = ar.getView().toString();
log.debug("Result:" + view);
RequestDispatcher dispatcher = null;
try
{
dispatcher = aRequest.getRequestDispatcher(view);
}
catch (Throwable e)
{
// Ignore
}
if (dispatcher == null)
throw new ServletException("No presentation file with name '" + view + "' found!");
try
{
// If we're included, then include the view
// Otherwise do forward
// This allow the page to, for example, set content type
if (aRequest.getAttribute("javax.servlet.include.servlet_path") == null)
{
aRequest.setAttribute("webwork.view_uri", view);
aRequest.setAttribute("webwork.request_uri", aRequest.getRequestURI());
aRequest.setAttribute("webwork.request_url", aRequest.getRequestURL());
//aRequest.setAttribute("webwork.contextPath",aRequest.getContextPath());
dispatcher.forward(aRequest, aResponse);
}
else
{
//aRequest.setAttribute("webwork.request_uri",aRequest.getAttribute("javax.servlet.include.request_uri"));
//aRequest.setAttribute("webwork.contextPath",aRequest.getAttribute("javax.servlet.include.context_path"));
dispatcher.include(aRequest, aResponse);
}
}
catch (IOException e)
{
e.printStackTrace();
throw new ServletException(e);
}
catch (Exception e)
{
e.printStackTrace();
throw new ServletException(e);
}
finally
{
// Get last action from stack and and store it in request attribute STACK_HEAD
// It is then popped from the stack.
aRequest.setAttribute(STACK_HEAD, ServletValueStack.getStack(aRequest).popValue());
}
}
gd.finalizeContext();
}