List of usage examples for org.apache.commons.chain.web.servlet ServletWebContext getRequest
public HttpServletRequest getRequest()
From source file:com.liulangf.pattern.gof.behavioral.chain.jakarta.simple.ForwardCommand.java
/** * <p>Execute the command.</p> * * @param context The {@link Context} we are operating on * @return <code>false</code> so that processng will continue * @throws Exception If an error occurs during execution. *//*from w w w. j a v a 2 s .c o m*/ public boolean execute(Context context) throws Exception { String uri = getForward(context); if (uri != null) { if (log.isDebugEnabled()) { log.debug("Forwarding to " + uri); } ServletWebContext swcontext = (ServletWebContext) context; RequestDispatcher rd = swcontext.getContext().getRequestDispatcher(uri); rd.forward(swcontext.getRequest(), swcontext.getResponse()); return true; } else { if (log.isDebugEnabled()) { log.debug("No forward found"); } return false; } }
From source file:org.apache.struts.chain.servlet.AuthorizeAction.java
protected boolean isAuthorized(Context context, String[] roles, ActionConfig mapping) throws Exception { // Identify the HTTP request object ServletWebContext swcontext = (ServletWebContext) context; HttpServletRequest request = swcontext.getRequest(); // Check the current user against the list of required roles for (int i = 0; i < roles.length; i++) { if (request.isUserInRole(roles[i])) { return (true); }/* ww w . ja v a 2 s.c o m*/ } // Default to unauthorized return (false); }
From source file:org.apache.struts.chain.servlet.ExceptionHandler.java
protected ForwardConfig handle(Context context, Exception exception, ExceptionConfig exceptionConfig, ActionConfig actionConfig, ModuleConfig moduleConfig) throws Exception { // Look up the remaining properties needed for this handler ServletWebContext swcontext = (ServletWebContext) context; ActionForm actionForm = (ActionForm) swcontext.get(getActionFormKey()); HttpServletRequest request = swcontext.getRequest(); HttpServletResponse response = swcontext.getResponse(); // Handle this exception org.apache.struts.action.ExceptionHandler handler = (org.apache.struts.action.ExceptionHandler) ClassUtils .getApplicationInstance(exceptionConfig.getHandler()); return (handler.execute(exception, exceptionConfig, (ActionMapping) actionConfig, actionForm, request, response));//from w ww . ja va 2 s. c om }
From source file:org.apache.struts.chain.servlet.ExecuteAction.java
/** * <p>Execute the specified <code>Action</code>, and return the resulting * <code>ActionForward</code>.</p> * * @param context The <code>Context</code> for this request * @param action The <code>Action</code> to be executed * @param actionConfig The <code>ActionConfig</code> defining this action * @param actionForm The <code>ActionForm</code> (if any) for * this action/*from ww w.j a v a2s . c o m*/ * * @exception Exception if thrown by the <code>Action</code> */ protected ForwardConfig execute(Context context, Action action, ActionConfig actionConfig, ActionForm actionForm) throws Exception { ServletWebContext swcontext = (ServletWebContext) context; return (action.execute((ActionMapping) actionConfig, actionForm, swcontext.getRequest(), swcontext.getResponse())); }
From source file:org.apache.struts.chain.servlet.PerformForward.java
/** * <p>Perform the appropriate processing on the specified * <code>ForwardConfig</code>.</p> * * @param context The context for this request * @param forwardConfig The forward to be performed *///w w w . j a v a 2s .com protected void perform(Context context, ForwardConfig forwardConfig) throws Exception { ServletWebContext swcontext = (ServletWebContext) context; String forwardPath = forwardConfig.getPath(); String uri = null; ModuleConfig moduleConfig = (ModuleConfig) context.get(getModuleConfigKey()); // Resolve module-relative paths if (forwardPath.startsWith("/")) { uri = RequestUtils.forwardURL(swcontext.getRequest(), forwardConfig, moduleConfig); } else { uri = forwardPath; } // Get the underlying request in the case of a multipart wrapper HttpServletRequest request = swcontext.getRequest(); if (request instanceof MultipartRequestWrapper) { request = ((MultipartRequestWrapper) request).getRequest(); } // Perform redirect or forward if (forwardConfig.getRedirect()) { if (uri.startsWith("/")) { uri = request.getContextPath() + uri; } swcontext.getResponse().sendRedirect(swcontext.getResponse().encodeRedirectURL(uri)); } else { RequestDispatcher rd = swcontext.getContext().getRequestDispatcher(uri); rd.forward(request, swcontext.getResponse()); } }
From source file:org.apache.struts.chain.servlet.PerformInclude.java
/** * <p>Perform the appropriate processing on the specified * include uri.</p>/*from w ww .j a v a2s . c om*/ * * @param context The context for this request * @param uri The uri to be included */ protected void perform(Context context, String uri) throws Exception { ServletWebContext swcontext = (ServletWebContext) context; // Get the underlying request in the case of a multipart wrapper HttpServletRequest request = swcontext.getRequest(); if (request instanceof MultipartRequestWrapper) { request = ((MultipartRequestWrapper) request).getRequest(); } RequestDispatcher rd = swcontext.getContext().getRequestDispatcher(uri); rd.forward(request, swcontext.getResponse()); }
From source file:org.apache.struts.chain.servlet.PopulateActionForm.java
protected void populate(Context context, ActionConfig actionConfig, ActionForm actionForm) throws Exception { ServletWebContext swcontext = (ServletWebContext) context; RequestUtils.populate(actionForm, actionConfig.getPrefix(), actionConfig.getSuffix(), swcontext.getRequest()); }
From source file:org.apache.struts.chain.servlet.PopulateActionForm.java
protected void reset(Context context, ActionConfig actionConfig, ActionForm actionForm) { ServletWebContext swcontext = (ServletWebContext) context; actionForm.reset((ActionMapping) actionConfig, swcontext.getRequest()); // Set the multipart class if (actionConfig.getMultipartClass() != null) { swcontext.getRequestScope().put(Globals.MULTIPART_KEY, actionConfig.getMultipartClass()); }/*w w w . j a va2 s . co m*/ }
From source file:org.apache.struts.chain.servlet.SelectAction.java
protected String getPath(Context context) { ServletWebContext swcontext = (ServletWebContext) context; HttpServletRequest request = swcontext.getRequest(); String path = null;/*w w w . ja va2 s.c om*/ boolean extension = false; // For prefix matching, match on the path info path = (String) request.getAttribute(Constants.INCLUDE_PATH_INFO); if (path == null) { path = request.getPathInfo(); } // For extension matching, match on the servlet path if (path == null) { path = (String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH); if (path == null) { path = request.getServletPath(); } if (path == null) { throw new IllegalArgumentException("No path information in request"); } extension = true; } // Strip the module prefix and extension (if any) ModuleConfig moduleConfig = (ModuleConfig) swcontext.get(getModuleConfigKey()); String prefix = moduleConfig.getPrefix(); if (!path.startsWith(prefix)) { throw new IllegalArgumentException("Path does not start with '" + prefix + "'"); } path = path.substring(prefix.length()); if (extension) { int slash = path.lastIndexOf("/"); int period = path.lastIndexOf("."); if ((period >= 0) && (period > slash)) { path = path.substring(0, period); } } return (path); }
From source file:org.apache.struts.chain.servlet.SelectLocale.java
/** * <p>Return the <code>Locale</code> to be used for this request.</p> * * @param context The <code>Context</code> for this request */// w w w .ja va2 s . c o m protected Locale getLocale(Context context) { ServletWebContext swcontext = (ServletWebContext) context; // Has a Locale already been selected? HttpSession session = swcontext.getRequest().getSession(); Locale locale = (Locale) session.getAttribute(Globals.LOCALE_KEY); if (locale != null) { return (locale); } // Select and cache the Locale to be used locale = swcontext.getRequest().getLocale(); if (locale == null) { locale = Locale.getDefault(); } session.setAttribute(Globals.LOCALE_KEY, locale); return (locale); }