/* * Copyright (C) The MX4J Contributors. * All rights reserved. * * This software is distributed under the terms of the MX4J License version 1.0. * See the terms of the MX4J License in the documentation provided with this software. */ package mx4j.tools.console.web; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.opensymphony.webwork.dispatcher.ServletDispatcher; import com.opensymphony.xwork.ActionContext; import com.opensymphony.xwork.ActionProxy; import com.opensymphony.xwork.ActionProxyFactory; import com.opensymphony.xwork.config.ConfigurationException; import com.opensymphony.xwork.util.OgnlValueStack; /** * @version $Revision$ */ public class DispatcherServlet extends ServletDispatcher { public void serviceAction(HttpServletRequest request, HttpServletResponse response, String namespace, String actionName, Map requestMap, Map parameterMap, Map sessionMap, Map applicationMap) { Object previousValueStack = request.getAttribute("webwork.valueStack"); try { HashMap extraContext = createContextMap(requestMap, parameterMap, sessionMap, applicationMap, request, response, getServletConfig()); extraContext.put(SERVLET_DISPATCHER, this); if (previousValueStack != null) extraContext.put(ActionContext.VALUE_STACK, previousValueStack); ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext); OgnlValueStack currentValueStack = proxy.getInvocation().getStack(); request.setAttribute("webwork.valueStack", currentValueStack); try { proxy.execute(); } finally { currentValueStack.pop(); } } catch (ConfigurationException e) { log.error("Could not find action", e); sendError(request, response, HttpServletResponse.SC_NOT_FOUND, e); } catch (Exception e) { log.error("Could not execute action", e); sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e); } finally { request.setAttribute("webwork.valueStack", previousValueStack); } } }