Search in sources :

Example 21 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class AbstractExceptionHandler method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Invoke the appropriate <code>Action</code> for this request, and
     * cache the returned <code>ActionForward</code>.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> if a <code>ForwardConfig</code> is returned,
     *         else <code>true</code> to complete processing
     * @throws Exception if thrown by the Action class and not declared by an
     *                   Exception Handler
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Look up the exception that was thrown
    Exception exception = actionCtx.getException();
    if (exception == null) {
        LOG.warn("No Exception found in ActionContext");
        return (true);
    }
    // Look up the local or global exception handler configuration
    ExceptionConfig exceptionConfig = null;
    ActionConfig actionConfig = actionCtx.getActionConfig();
    ModuleConfig moduleConfig = actionCtx.getModuleConfig();
    if (actionConfig != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("See if actionConfig " + actionConfig + " has an exceptionConfig for " + exception.getClass().getName());
        }
        exceptionConfig = actionConfig.findException(exception.getClass());
    } else if (moduleConfig != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No action yet, see if moduleConfig " + moduleConfig + " has an exceptionConfig " + exception.getClass().getName());
        }
        exceptionConfig = moduleConfig.findException(exception.getClass());
    }
    // Handle the exception in the configured manner
    if (exceptionConfig == null) {
        LOG.warn("Unhandled exception", exception);
        throw exception;
    }
    ForwardConfig forwardConfig = handle(actionCtx, exception, exceptionConfig, actionConfig, moduleConfig);
    if (forwardConfig != null) {
        actionCtx.setForwardConfig(forwardConfig);
        return (false);
    } else {
        return (true);
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) ModuleConfig(org.apache.struts.config.ModuleConfig) ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 22 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class CommonsMultipartRequestHandler method handleRequest.

/**
     * <p> Parses the input stream and partitions the parsed items into a set
     * of form fields and a set of file items. In the process, the parsed
     * items are translated from Commons FileUpload <code>FileItem</code>
     * instances to Struts <code>FormFile</code> instances. </p>
     *
     * @param request The multipart request to be processed.
     * @throws ServletException if an unrecoverable error occurs.
     */
public void handleRequest(HttpServletRequest request) throws ServletException {
    // Get the app config for the current request.
    ModuleConfig ac = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
    // Create and configure a DIskFileUpload instance.
    DiskFileUpload upload = new DiskFileUpload();
    // The following line is to support an "EncodingFilter"
    // see http://issues.apache.org/bugzilla/show_bug.cgi?id=23255
    upload.setHeaderEncoding(request.getCharacterEncoding());
    // Set the maximum size before a FileUploadException will be thrown.
    upload.setSizeMax(getSizeMax(ac));
    // Set the maximum size that will be stored in memory.
    upload.setSizeThreshold((int) getSizeThreshold(ac));
    // Set the the location for saving data on disk.
    upload.setRepositoryPath(getRepositoryPath(ac));
    // Create the hash tables to be populated.
    elementsText = new Hashtable();
    elementsFile = new Hashtable();
    elementsAll = new Hashtable();
    // Parse the request into file items.
    List items = null;
    try {
        items = upload.parseRequest(request);
    } catch (DiskFileUpload.SizeLimitExceededException e) {
        // Special handling for uploads that are too big.
        request.setAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED, Boolean.TRUE);
        return;
    } catch (FileUploadException e) {
        log.error("Failed to parse multipart request", e);
        throw new ServletException(e);
    }
    // Partition the items into form fields and files.
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();
        if (item.isFormField()) {
            addTextParameter(request, item);
        } else {
            addFileParameter(item);
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) FileItem(org.apache.commons.fileupload.FileItem) DiskFileItem(org.apache.commons.fileupload.disk.DiskFileItem) DiskFileUpload(org.apache.commons.fileupload.DiskFileUpload) Hashtable(java.util.Hashtable) Iterator(java.util.Iterator) ModuleConfig(org.apache.struts.config.ModuleConfig) ArrayList(java.util.ArrayList) List(java.util.List) FileUploadException(org.apache.commons.fileupload.FileUploadException)

Example 23 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class ModuleUtils method getModuleConfig.

/**
     * Return the ModuleConfig object is it exists, null otherwise.
     *
     * @param request The servlet request we are processing
     * @param context The ServletContext for this web application
     * @return the ModuleConfig object
     */
public ModuleConfig getModuleConfig(HttpServletRequest request, ServletContext context) {
    ModuleConfig moduleConfig = this.getModuleConfig(request);
    if (moduleConfig == null) {
        moduleConfig = this.getModuleConfig("", context);
        request.setAttribute(Globals.MODULE_KEY, moduleConfig);
    }
    return moduleConfig;
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 24 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class SelectAction method getPath.

// ------------------------------------------------------- Protected Methods
protected String getPath(ActionContext context) {
    ServletActionContext saContext = (ServletActionContext) context;
    HttpServletRequest request = saContext.getRequest();
    String path = null;
    boolean extension = false;
    // For prefix matching, match on the path info
    path = (String) request.getAttribute(Constants.INCLUDE_PATH_INFO);
    if ((path == null) || (path.length() == 0)) {
        path = request.getPathInfo();
    }
    // For extension matching, match on the servlet path
    if ((path == null) || (path.length() == 0)) {
        path = (String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH);
        if ((path == null) || (path.length() == 0)) {
            path = request.getServletPath();
        }
        if ((path == null) || (path.length() == 0)) {
            throw new IllegalArgumentException("No path information in request");
        }
        extension = true;
    }
    // Strip the module prefix and extension (if any)
    ModuleConfig moduleConfig = saContext.getModuleConfig();
    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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 25 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class Resources method getMessageResources.

/**
     * Retrieve <code>MessageResources</code> for the module and bundle.
     *
     * @param application the servlet context
     * @param request     the servlet request
     * @param bundle      the bundle key
     */
public static MessageResources getMessageResources(ServletContext application, HttpServletRequest request, String bundle) {
    if (bundle == null) {
        bundle = Globals.MESSAGES_KEY;
    }
    MessageResources resources = (MessageResources) request.getAttribute(bundle);
    if (resources == null) {
        ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(request, application);
        resources = (MessageResources) application.getAttribute(bundle + moduleConfig.getPrefix());
    }
    if (resources == null) {
        resources = (MessageResources) application.getAttribute(bundle);
    }
    if (resources == null) {
        throw new NullPointerException("No message resources found for bundle: " + bundle);
    }
    return resources;
}
Also used : MessageResources(org.apache.struts.util.MessageResources) ModuleConfig(org.apache.struts.config.ModuleConfig)

Aggregations

ModuleConfig (org.apache.struts.config.ModuleConfig)34 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 JspException (javax.servlet.jsp.JspException)5 Iterator (java.util.Iterator)4 ActionConfig (org.apache.struts.config.ActionConfig)4 ForwardConfig (org.apache.struts.config.ForwardConfig)4 MessageResources (org.apache.struts.util.MessageResources)4 ArrayList (java.util.ArrayList)3 Enumeration (java.util.Enumeration)2 List (java.util.List)2 Locale (java.util.Locale)2 ServletException (javax.servlet.ServletException)2 ActionServlet (org.apache.struts.action.ActionServlet)2 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 ServletContext (javax.servlet.ServletContext)1