@Override public ActionConfig getConfig() { return this.parentProxy.getConfig(); }
protected void createInterceptors(ActionProxy proxy) { // get a new List so we don't get problems with the iterator if someone changes the list List<InterceptorMapping> interceptorList = new ArrayList<InterceptorMapping>(proxy.getConfig().getInterceptors()); interceptors = interceptorList.iterator(); }
public String invokeActionOnly() throws Exception { return invokeAction(getAction(), proxy.getConfig()); }
ActionInvocation invocation = ActionContext.getContext().getActionInvocation(); ActionProxy proxy = invocation.getProxy(); ActionConfig config = proxy.getConfig(); Map<String, ResultConfig> results = config.getResults(); ResultConfig resultConfig = results.get(Action.SUCCESS); String lastFinalLocation = null; Map<String, String> params = resultConfig.getParams(); if (resultConfig.getClassName().equals("org.apache.struts2.dispatcher.ServletDispatcherResult")) { lastFinalLocation = params.get("location"); } System.out.println("location: " + lastFinalLocation);
private String makeStackKey(ActionProxy proxy) { String methodName = proxy.getConfig().getMethodName(); if (methodName == null) methodName = "execute"; String actionClazz = ProfilingUtils.getJustClassName(proxy.getConfig().getClassName()); return "XW Interceptor: " + (location != null ? location + ": " : "") + proxy.getNamespace() + "/" + proxy.getActionName() + ".action (" + actionClazz + "." + methodName + "())"; }
/** * @param ac The action context * @return the parameters from the action mapping in the context. If none found, returns * an empty map. */ protected Map<String, String> retrieveParameters(ActionContext ac) { ActionConfig config = ac.getActionInvocation().getProxy().getConfig(); if (config != null) { return config.getParams(); } else { return Collections.emptyMap(); } }
public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); // the object to pass parameters Map<String, Object> templateParameterMap = new HashMap<String, Object>(); String resultCode = invocation.getResultCode(); if (resultCode != null) { ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get( resultCode); Map<String, String> resultConfigParams = resultConfig.getParams(); for (Iterator<Entry<String, String>> i = resultConfigParams.entrySet().iterator(); i.hasNext(); ) { Map.Entry<String, String> e = i.next(); if (! predefinedResultParam.contains(e.getKey())) { templateParameterMap.put(e.getKey().toString(), e.getValue() == null ? "": conditionalParse(e.getValue().toString(), invocation)); } } } StdrUtil.getParameters(request).putAll(templateParameterMap); super.doExecute(finalLocation, invocation); }
private String getDetails(ActionInvocation invocation) { ActionProxy proxy = invocation.getProxy(); String methodName = proxy.getConfig().getMethodName(); if (methodName == null) methodName = "execute"; String actionClazz = ProfilingUtils.getJustClassName(proxy.getConfig().getClassName()); return proxy.getNamespace() + "/" + proxy.getActionName() + ".action (" + actionClazz + "." + methodName + "())"; }
invocationContext, proxy.getActionName(), proxy.getConfig(), resultCode); ResultConfig resultConfig = this.proxy.getConfig().getResults().get(defaultErrorResultName); if (resultConfig != null) { this.result = objectFactory.buildResult(resultConfig, invocationContext.getContextMap()); throw new ConfigurationException("No result defined for action " + getAction().getClass().getName() + " and result " + getResultCode(), proxy.getConfig());
protected void createAction(Map<String, Object> contextMap) { // load action String timerKey = "actionCreate: " + proxy.getActionName(); try { UtilTimerStack.push(timerKey); action = objectFactory.buildAction(proxy.getActionName(), proxy.getNamespace(), proxy.getConfig(), contextMap); } catch (InstantiationException e) { throw new XWorkException("Unable to intantiate Action!", e, proxy.getConfig()); } catch (IllegalAccessException e) { throw new XWorkException("Illegal access to constructor, is it public?", e, proxy.getConfig()); } catch (Exception e) { String gripe; if (proxy == null) { gripe = "Whoa! No ActionProxy instance found in current ActionInvocation. This is bad ... very bad"; } else if (proxy.getConfig() == null) { gripe = "Sheesh. Where'd that ActionProxy get to? I can't find it in the current ActionInvocation!?"; } else if (proxy.getConfig().getClassName() == null) { gripe = "No Action defined for '" + proxy.getActionName() + "' in namespace '" + proxy.getNamespace() + "'"; } else { gripe = "Unable to instantiate Action, " + proxy.getConfig().getClassName() + ", defined for '" + proxy.getActionName() + "' in namespace '" + proxy.getNamespace() + "'"; } gripe += (((" -- " + e.getMessage()) != null) ? e.getMessage() : " [no message in exception]"); throw new XWorkException(gripe, e, proxy.getConfig()); } finally { UtilTimerStack.pop(timerKey); } if (actionEventListener != null) { action = actionEventListener.prepare(action, stack); } }
/** * Determines if this action mapping will be have a JSF view * * @param inv * The action invocation * @return True if the JSF interceptors should fire */ protected boolean isFacesAction(ActionInvocation inv) { ActionConfig config = inv.getProxy().getConfig(); if (config != null) { ResultConfig resultConfig = config.getResults().get(Action.SUCCESS); Class resClass = null; try { resClass = Class.forName(resultConfig.getClassName()); } catch (ClassNotFoundException ex) { log.warn( "Can't find result class, ignoring as a faces request", ex); } if (resClass != null) { if (resClass.isAssignableFrom(FacesResult.class)) { return true; } } } return false; }
/** * Uses getResult to get the final Result and executes it * * @throws ConfigurationException If not result can be found with the returned code */ private void executeResult() throws Exception { result = createResult(); String timerKey = "executeResult: " + getResultCode(); try { UtilTimerStack.push(timerKey); if (result != null) { result.execute(this); } else if (resultCode != null && !Action.NONE.equals(resultCode)) { throw new ConfigurationException("No result defined for action " + getAction().getClass().getName() + " and result " + getResultCode(), proxy.getConfig()); } else { if (LOG.isDebugEnabled()) { LOG.debug("No result returned for action " + getAction().getClass().getName() + " at " + proxy.getConfig().getLocation()); } } } finally { UtilTimerStack.pop(timerKey); } }
@Override public String intercept(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); if (action instanceof ScopedModelDriven) { ScopedModelDriven modelDriven = (ScopedModelDriven) action; if (modelDriven.getModel() == null) { ActionContext ctx = ActionContext.getContext(); ActionConfig config = invocation.getProxy().getConfig(); String cName = className; if (cName == null) { try { Method method = action.getClass().getMethod(GET_MODEL, EMPTY_CLASS_ARRAY); Class cls = method.getReturnType(); cName = cls.getName(); } catch (NoSuchMethodException e) { throw new XWorkException("The " + GET_MODEL + "() is not defined in action " + action.getClass() + "", config); } } String modelName = name; if (modelName == null) { modelName = cName; } Object model = resolveModel(objectFactory, ctx, cName, scope, modelName); modelDriven.setModel(model); modelDriven.setScopeKey(modelName); } } return invocation.invoke(); }
/** * Execute the current result. If it is an error and no result is selected load * the default error result (default-error). */ private void executeResult() throws Exception { // Get handler by representation ContentTypeHandler handler = handlerSelector.getHandlerForResponse( ServletActionContext.getRequest(), ServletActionContext.getResponse()); // get the result this.result = createResult(); if (this.result instanceof HttpHeaderResult) { // execute the result to apply headers and status in every representations this.result.execute(this); updateStatusFromResult(); } if (handler != null && !(handler instanceof HtmlHandler)) { // Specific representation (json, xml...) resultCode = handlerSelector.handleResult(this, httpHeaders, target); } else { // Normal struts execution (html o other struts result) findResult(); if (result != null) { this.result.execute(this); } else { if (LOG.isDebugEnabled()) { LOG.debug("No result returned for action {} at {}", getAction().getClass().getName(), proxy.getConfig().getLocation()); } } } }
public String intercept(ActionInvocation invocation) throws Exception { Method invocationMethod = versionSupport.extractMethod(invocation); String configParam = (String) invocation.getProxy().getConfig().getParams().get(CONFIG_PARAM_NAME); RequireSecurityToken annotation = invocationMethod.getAnnotation(RequireSecurityToken.class); boolean isProtected = methodRequiresProtection(configParam, annotation); String token = ServletActionContext.getRequest().getParameter(REQUEST_PARAM_NAME); boolean validToken = tokenGenerator.validateToken(ServletActionContext.getRequest(), token); if (isProtected && !validToken) { if (token == null) { addInvalidTokenError(versionSupport.extractAction(invocation), SECURITY_TOKEN_REQUIRED_ERROR_KEY); } else { addInvalidTokenError(versionSupport.extractAction(invocation), VALIDATION_FAILED_ERROR_KEY); } ServletActionContext.getResponse().setStatus(403); return ActionSupport.INPUT; } return invocation.invoke(); }
@Override public String intercept(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); if (action instanceof ScopedModelDriven) { ScopedModelDriven modelDriven = (ScopedModelDriven) action; Object model = modelDriven.getModel(); if (model != null && model instanceof ActionForm) { Struts1Factory factory = new Struts1Factory(configuration); ActionMapping mapping = factory.createActionMapping(invocation.getProxy().getConfig()); HttpServletRequest req = ServletActionContext.getRequest(); ((ActionForm)model).reset(mapping, req); } } return invocation.invoke(); } }
HttpServletRequest req = ServletActionContext.getRequest(); Struts1Factory strutsFactory = new Struts1Factory(configuration); ActionMapping mapping = strutsFactory.createActionMapping(invocation.getProxy().getConfig()); ModuleConfig moduleConfig = strutsFactory.createModuleConfig(invocation.getProxy().getConfig().getPackageName()); req.setAttribute(Globals.MODULE_KEY, moduleConfig); req.setAttribute(Globals.MESSAGES_KEY, new WrapperMessageResources((TextProvider)invocation.getAction()));
@Override public String intercept(ActionInvocation invocation) throws Exception { String result; try { result = invocation.invoke(); } catch (Exception e) { if (isLogEnabled()) { handleLogging(e); } List<ExceptionMappingConfig> exceptionMappings = invocation.getProxy().getConfig().getExceptionMappings(); ExceptionMappingConfig mappingConfig = this.findMappingFromExceptions(exceptionMappings, e); if (mappingConfig != null && mappingConfig.getResult()!=null) { Map parameterMap = mappingConfig.getParams(); // create a mutable HashMap since some interceptors will remove parameters, and parameterMap is immutable invocation.getInvocationContext().setParameters(new HashMap<String, Object>(parameterMap)); result = mappingConfig.getResult(); publishException(invocation, new ExceptionHolder(e)); } else { throw e; } } return result; }
public String execute() throws Exception { ActionContext ctx = ActionContext.getContext(); ActionConfig actionConfig = ctx.getActionInvocation().getProxy().getConfig(); Action action = null; try {
/** * Creates the faces context for other phases. * * @param invocation * The action invocation */ public String intercept(ActionInvocation invocation) throws Exception { if (facesContextFactory != null) { if (isFacesAction(invocation)) { invocation.getInvocationContext().put( FacesInterceptor.FACES_ENABLED, Boolean.TRUE); FacesContext facesContext = facesContextFactory .getFacesContext(ServletActionContext .getServletContext(), ServletActionContext .getRequest(), ServletActionContext .getResponse(), lifecycle); setLifecycle(lifecycle); try { return invocation.invoke(); } finally { facesContext.release(); } } } else { throw new StrutsException( "Unable to initialize jsf interceptors probably due missing JSF implementation libraries", invocation.getProxy().getConfig()); } return invocation.invoke(); }