/** * Default implementation to handle ExceptionHolder publishing. Pushes given ExceptionHolder on the stack. * Subclasses may override this to customize publishing. * * @param invocation The invocation to publish Exception for. * @param exceptionHolder The exceptionHolder wrapping the Exception to publish. */ protected void publishException(ActionInvocation invocation, ExceptionHolder exceptionHolder) { invocation.getStack().push(exceptionHolder); }
@Override public String intercept(ActionInvocation ai) throws Exception { ValueStack stack=ai.getStack(); Iterator it = stack.getRoot().iterator(); while( it.hasNext() ) { Object objecto = it.next(); //LoginUsuario is my action class if( objecto instanceof LoginUsuario ) { LoginUsuario usuario = (LoginUsuario)objecto; usuario.setUsername( usuario.getUsername().toUpperCase() ); usuario.setPassword( usuario.getPassword().toUpperCase() ); } } return ai.invoke(); }
@Override public void beforeResult(ActionInvocation invocation, String resultCode) { adapter.executePostProcessors(); invocation.getStack().getContext().put(StrutsScopeConstants.CONVERSATION_ID_MAP_STACK_KEY, adapter.getViewContext()); } });
@Override protected void doExecute(String view, ActionInvocation ai) throws Exception { final Map<String, Object> context = ai.getStack().getContext(); final HttpServletRequest request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST); final HttpServletResponse response = (HttpServletResponse) context.get(ServletActionContext.HTTP_RESPONSE); if (contentType != null) { response.setContentType(contentType); } engineManager.renderTemplate(view, Vars.of(PARAM_KEYS, new Object[]{ request, response, context, ai.getAction() }), response); } }
@Override public String intercept(ActionInvocation invocation) throws Exception { ValueStack stack = invocation.getStack(); boolean forceRefresh = false; Object v = stack.findValue("refreshConfiguration"); if (v != null) forceRefresh = Boolean.parseBoolean(v.toString()); HttpServletRequest request = ServletActionContext.getRequest(); Map<String, Object> configuration = _configurationService.getConfiguration(forceRefresh, request.getContextPath()); stack.setValue("#configuration", configuration); return invocation.invoke(); } }
protected void doExecute(String finalDestination, ActionInvocation actionInvocation) throws Exception { // No need to create a session for RSS ServletActionContext.getRequest().getSession(false); HttpServletResponse response = ServletActionContext.getResponse(); if (finalDestination.startsWith("rss")) response.setContentType("application/rss+xml; charset=" + DEFAULT_DEFAULT_ENCODING); else if (finalDestination.startsWith("atom")) response.setContentType("application/atom+xml; charset=" + DEFAULT_DEFAULT_ENCODING); else response.setContentType("text/xml; charset=" + DEFAULT_DEFAULT_ENCODING); SyndFeed feed = (SyndFeed) actionInvocation.getStack().findValue("syndFeed"); if (feed == null) throw new ServletException("Unable to find feed for this action"); WireFeed outFeed = feed.createWireFeed(finalDestination); outFeed.setEncoding(DEFAULT_DEFAULT_ENCODING); new WireFeedOutput().output(outFeed, response.getWriter()); try { response.flushBuffer(); } catch (IOException e) { log.info("Client aborted (closed the connection) before the rss feed could be returned."); if (log.isDebugEnabled()) { log.debug("Error sending rss result to client", e); } } } }
public void beforeResult(ActionInvocation invocation, String resultCode) { Map<Object, Object> fakie = (Map<Object, Object>) invocation.getInvocationContext().get(ORIGINAL_PROPERTY_OVERRIDE); if (fakie != null) { invocation.getStack().setExprOverrides(fakie); } } });
@Override public String intercept(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); Class<?> actionType = action.getClass(); AddToStack addToStackAnnotation = actionType.getAnnotation(AddToStack.class); if (addToStackAnnotation != null) { ValueStack stack = invocation.getStack(); List<Object> toPush = new ArrayList<Object>(); for (String name : addToStackAnnotation.value()) { Object value = stack.findValue(name); if (value != null) toPush.add(value); } /** * We push the values onto the stack after finding ALL the values first */ for (Object value : toPush) stack.push(value); } return invocation.invoke(); }
/** * Handles logging and UI messages for ConversationExceptions * * @param invocation * @param ce * @return */ protected String handleUnexpectedException(ActionInvocation invocation, ConversationException ce) { LOG.error("An unexpected exception occurred in Conversation Processing, returning result of " + CONVERSATION_EXCEPTION_KEY); Locale locale = invocation.getInvocationContext().getLocale(); String errorMessage = LocalizedTextUtil.findText(this.getClass(), CONVERSATION_EXCEPTION_KEY, locale, "An unexpected error occurred while processing you request. Please try again.", new Object[0]); if (LOG.isDebugEnabled()) { LOG.debug("Placing Conversation Error Message on stack (key={" + CONVERSATION_EXCEPTION_KEY + "}): " + errorMessage); } //Placing message on stack instead of in actionErrors for retrieval in UI invocation.getStack().getContext().put(CONVERSATION_EXCEPTION_KEY, errorMessage); this.handleConversationErrorAware(invocation.getProxy(), errorMessage); return CONVERSATION_EXCEPTION_KEY; }
String getMyActionUrl() throws Exception { ActionInvocation invocation = (ActionInvocation) ActionContext .getContext().get(ActionContext.ACTION_INVOCATION); org.apache.struts2.components.URL url = new org.apache.struts2.components.URL(invocation.getStack(), getServletRequest(), getServletResponse()); url.addParameter("parameterToBeDeleted", null); url.addParameter("newParam", newValue); url.setActionMapper(new DefaultActionMapper()); url.setUrlHelper(new DefaultUrlHelper()); String myUrl = url .getUrlProvider() .determineActionURL( "MyActionName", invocation.getProxy().getNamespace(), invocation.getProxy().getMethod(), getServletRequest(), getServletResponse(), getServletRequest().getParameterMap(), "http", true, true, false, false); return myUrl; }
@Override public String intercept(ActionInvocation invocation) throws Exception { ValueStack stack = invocation.getStack(); CompoundRoot root = stack.getRoot(); if (shouldCopyStack(invocation, root)) { copyStack(invocation, root); } return invocation.invoke(); }
@Override protected void doExecute(String finalLocation,ActionInvocation invocation) throws Exception { HttpServletResponse response = (HttpServletResponse) invocation.getInvocationContext().get(HTTP_RESPONSE); HttpServletRequest request = (HttpServletRequest) invocation.getInvocationContext().get(HTTP_REQUEST); String resultCodeAsLocation = invocation.getResultCode(); if(resultCodeAsLocation == null) { return; } //proecss with ONGL expression resultCodeAsLocation = TextParseUtil.translateVariables(resultCodeAsLocation,invocation.getStack()); if(resultCodeAsLocation.startsWith("!")) { doRedirect(invocation,request, response, resultCodeAsLocation.substring(1)); return; } if(resultCodeAsLocation.startsWith(REDIRECT_PREFIX)) { doRedirect(invocation,request, response, resultCodeAsLocation.substring(REDIRECT_PREFIX.length())); return; } if(resultCodeAsLocation.startsWith(FORWARD_PREFIX)) { doDispatcher(response, request, resultCodeAsLocation.substring(FORWARD_PREFIX.length())); return; } doDispatcher(response, request, resultCodeAsLocation); }
@Override protected void doExecute(String location, ActionInvocation ai) throws Exception { Map<String, Object> model = ai.getStack().getContext(); HttpServletRequest request = (HttpServletRequest) model.get(ServletActionContext.HTTP_REQUEST); HttpServletResponse response = (HttpServletResponse) model.get(ServletActionContext.HTTP_RESPONSE); JetEngine engine = JetWebEngine.getEngine(); if (engine == null) { ServletContext servletContext = (ServletContext) model.get(ServletActionContext.SERVLET_CONTEXT); engine = JetWebEngine.create(servletContext); } String charsetEncoding = engine.getConfig().getOutputEncoding().name(); response.setCharacterEncoding(charsetEncoding); if (response.getContentType() == null) { response.setContentType("text/html; charset=" + charsetEncoding); } JetWebContext context = new JetWebContext(request, response, null); context.put("action", ai.getAction()); context.put("valueStack", model); JetTemplate template = engine.getTemplate(location); template.render(context, response.getOutputStream()); } }
public void beforeResult(ActionInvocation invocation, String resultCode) { ValueStack stack = invocation.getStack(); CompoundRoot root = stack.getRoot(); boolean needsRefresh = true; Object newModel = action.getModel(); // Check to see if the new model instance is already on the stack for (Object item : root) { if (item.equals(newModel)) { needsRefresh = false; break; } } // Add the new model on the stack if (needsRefresh) { // Clear off the old model instance if (originalModel != null) { root.remove(originalModel); } if (newModel != null) { stack.push(newModel); } } } }
@Override public String intercept(ActionInvocation invocation) throws Exception { ValueStack stack = invocation.getStack(); CompoundRoot root = stack.getRoot(); if (root.size() >= this.compoundRootMinSize && isChainResult(invocation)) { List<CompoundRoot> list = new ArrayList<CompoundRoot>(root); list.remove(0); Collections.reverse(list); Map<String, Object> ctxMap = invocation.getInvocationContext().getContextMap(); Iterator<CompoundRoot> iterator = list.iterator(); int index = 1; // starts with 1, 0 has been removed while (iterator.hasNext()) { index = index + 1; Object o = iterator.next(); if (o != null) { if (!(o instanceof Unchainable)) { reflectionProvider.copy(o, invocation.getAction(), ctxMap, excludes, includes); } } else { LOG.warn("compound root element at index " + index + " is null"); } } } return invocation.invoke(); }
@Override protected void doExecute(String location, ActionInvocation ai) throws Exception { Map<String, Object> model = ai.getStack().getContext(); HttpServletRequest request = (HttpServletRequest) model.get(ServletActionContext.HTTP_REQUEST); HttpServletResponse response = (HttpServletResponse) model.get(ServletActionContext.HTTP_RESPONSE); if (JetWebEngineLoader.unavailable()) { ServletContext servletContext = (ServletContext) model.get(ServletActionContext.SERVLET_CONTEXT); JetWebEngineLoader.setServletContext(servletContext); } JetContext context = new JetWebContext(request, response, null); context.put("action", ai.getAction()); context.put("valueStack", model); JetTemplate template = JetWebEngineLoader.getJetEngine().getTemplate(location); template.render(context, response.getOutputStream()); } }
@Override public String intercept(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); if (action instanceof ModelDriven) { ModelDriven modelDriven = (ModelDriven) action; ValueStack stack = invocation.getStack(); Object model = modelDriven.getModel(); if (model != null) { stack.push(model); } if (refreshModelBeforeResult) { invocation.addPreResultListener(new RefreshModelBeforeResult(modelDriven, model)); } } return invocation.invoke(); }
@Override public String intercept(ActionInvocation invocation) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("intercept '#0/#1' {", invocation.getProxy().getNamespace(), invocation.getProxy().getActionName()); } LocaleFinder localeFinder = new LocaleFinder(invocation); Locale locale = getLocaleFromParam(localeFinder.getRequestedLocale()); locale = storeLocale(invocation, locale, localeFinder.getStorage()); saveLocale(invocation, locale); if (LOG.isDebugEnabled()) { LOG.debug("before Locale=#0", invocation.getStack().findValue("locale")); } final String result = invocation.invoke(); if (LOG.isDebugEnabled()) { LOG.debug("after Locale=#0", invocation.getStack().findValue("locale")); LOG.debug("intercept } "); } return result; }