Search in sources :

Example 6 with ActionContext

use of org.apache.struts.chain.contexts.ActionContext in project sonar-java by SonarSource.

the class ExceptionCatcher method postprocess.

/**
 * <p>If an exception was thrown by a subsequent <code>Command</code>,
 * pass it on to the specified exception handling chain.  Otherwise, do
 * nothing.</p>
 *
 * @param context   The {@link Context} to be processed by this {@link
 *                  Filter}
 * @param exception The <code>Exception</code> (if any) that was thrown by
 *                  the last {@link Command} that was executed; otherwise
 *                  <code>null</code>
 * @return TRUE if post processing an exception occurred and the exception
 *         processing chain invoked
 * @throws IllegalStateException If exception throws exception
 */
public boolean postprocess(Context context, Exception exception) {
    // Do nothing if there was no exception thrown
    if (exception == null) {
        return (false);
    }
    // Stash the exception in the specified context attribute
    if (LOG.isDebugEnabled()) {
        LOG.debug("Attempting to handle a thrown exception");
    }
    ActionContext actionCtx = (ActionContext) context;
    actionCtx.setException(exception);
    // Execute the specified command
    try {
        Command command = lookupExceptionCommand();
        if (command == null) {
            LOG.error("Cannot find exceptionCommand '" + exceptionCommand + "'");
            throw new IllegalStateException("Cannot find exceptionCommand '" + exceptionCommand + "'");
        }
        if (LOG.isTraceEnabled()) {
            LOG.trace("Calling exceptionCommand '" + exceptionCommand + "'");
        }
        command.execute(context);
    } catch (Exception e) {
        LOG.warn("Exception from exceptionCommand '" + exceptionCommand + "'", e);
        throw new IllegalStateException("Exception chain threw exception");
    }
    return (true);
}
Also used : Command(org.apache.commons.chain.Command) ActionContext(org.apache.struts.chain.contexts.ActionContext)

Example 7 with ActionContext

use of org.apache.struts.chain.contexts.ActionContext in project sonar-java by SonarSource.

the class ComposableRequestProcessor method setActionContextClassName.

/**
 * <p>Make sure that the specified <code>className</code> identfies a
 * class which can be found and which implements the
 * <code>ActionContext</code> interface.</p>
 *
 * @param className Fully qualified name of
 * @throws ServletException     If an error occurs during initialization
 * @throws UnavailableException if class does not implement ActionContext
 *                              or is not found
 */
private void setActionContextClassName(String className) throws ServletException {
    if ((className != null) && (className.trim().length() > 0)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("setActionContextClassName: requested context class: " + className);
        }
        try {
            Class actionContextClass = RequestUtils.applicationClass(className);
            if (!ActionContext.class.isAssignableFrom(actionContextClass)) {
                throw new UnavailableException("ActionContextClass " + "[" + className + "]" + " must implement ActionContext interface.");
            }
            this.setActionContextClass(actionContextClass);
        } catch (ClassNotFoundException e) {
            throw new UnavailableException("ActionContextClass " + className + " not found.");
        }
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("setActionContextClassName: no className specified");
        }
        this.setActionContextClass(null);
    }
}
Also used : UnavailableException(javax.servlet.UnavailableException) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) ActionContext(org.apache.struts.chain.contexts.ActionContext)

Example 8 with ActionContext

use of org.apache.struts.chain.contexts.ActionContext in project sonar-java by SonarSource.

the class ComposableRequestProcessor method process.

/**
 * <p>Process an <code>HttpServletRequest</code> and create the
 * corresponding <code>HttpServletResponse</code>.</p>
 *
 * @param request  The servlet request we are processing
 * @param response The servlet response we are creating
 * @throws IOException      if an input/output error occurs
 * @throws ServletException if a processing exception occurs
 */
public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Wrap the request in the case of a multipart request
    request = processMultipart(request);
    // Create and populate a Context for this request
    ActionContext context = contextInstance(request, response);
    // Create and execute the command.
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Using processing chain for this request");
        }
        command.execute(context);
    } catch (Exception e) {
        // Execute the exception processing chain??
        throw new ServletException(e);
    }
    // Release the context.
    context.release();
}
Also used : ServletException(javax.servlet.ServletException) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) ActionContext(org.apache.struts.chain.contexts.ActionContext) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Aggregations

ActionContext (org.apache.struts.chain.contexts.ActionContext)8 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)6 UnavailableException (javax.servlet.UnavailableException)4 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 Command (org.apache.commons.chain.Command)2