Package org.apache.struts.config

Examples of org.apache.struts.config.ExceptionConfig


     * Test that initModuleExceptionConfigs throws an exception when a handler
     * with a null key is present.
     */
    public void testInitModuleExceptionConfigsNullFormType()
        throws ServletException {
        ExceptionConfig handler = new ExceptionConfig();

        handler.setType("java.lang.NullPointerException");
        moduleConfig.addExceptionConfig(handler);

        try {
            actionServlet.initModuleExceptionConfigs(moduleConfig);
            fail("An exception should've been thrown here.");
View Full Code Here


        customBase.setType("java.lang.NullPointerException");
        customBase.setKey("msg.exception.npe");
        moduleConfig.addExceptionConfig(customBase);

        ExceptionConfig customSub = new ExceptionConfig();

        customSub.setType("java.lang.IllegalStateException");
        customSub.setExtends("java.lang.NullPointerException");
        moduleConfig.addExceptionConfig(customSub);

        ExceptionConfig result =
            actionServlet.processExceptionConfigClass(customSub, moduleConfig);

        assertTrue("Incorrect class of exception config",
            result instanceof CustomExceptionConfig);
        assertEquals("Incorrect type", customSub.getType(), result.getType());
        assertEquals("Incorrect key", customSub.getKey(), result.getKey());
        assertEquals("Incorrect extends", customSub.getExtends(),
            result.getExtends());

        assertSame("Result was not registered in the module config", result,
            moduleConfig.findExceptionConfig("java.lang.IllegalStateException"));
    }
View Full Code Here

     */
    public void testProcessExceptionConfigClassNoExtends()
        throws Exception {
        moduleConfig.addExceptionConfig(baseException);

        ExceptionConfig result = null;

        try {
            result =
                actionServlet.processExceptionConfigClass(baseException,
                    moduleConfig);
View Full Code Here

     */
    public void testProcessExceptionConfigClassSubConfigCustomClass()
        throws Exception {
        moduleConfig.addExceptionConfig(baseException);

        ExceptionConfig customSub = new ExceptionConfig();

        customSub.setType("java.lang.IllegalStateException");
        customSub.setExtends("java.lang.NullPointerException");
        moduleConfig.addExceptionConfig(customSub);

        ExceptionConfig result =
            actionServlet.processExceptionConfigClass(customSub, moduleConfig);

        assertSame("The instance returned should be the param given it.",
            customSub, result);
    }
View Full Code Here

     * Make sure the code throws the correct exception when it can't create an
     * instance of the base config's custom class.
     */
    public void notestProcessExceptionConfigClassError()
        throws Exception {
        ExceptionConfig customBase =
            new CustomExceptionConfigArg("java.lang.NullPointerException");

        moduleConfig.addExceptionConfig(customBase);

        ExceptionConfig customSub = new ExceptionConfig();

        customSub.setType("java.lang.IllegalStateException");
        customSub.setExtends("java.lang.NullPointerException");
        moduleConfig.addExceptionConfig(customSub);

        try {
            actionServlet.processExceptionConfigClass(customSub, moduleConfig);
            fail("Exception should be thrown");
View Full Code Here

     */
    public void testProcessExceptionConfigClassOverriddenSubFormClass()
        throws Exception {
        moduleConfig.addExceptionConfig(baseException);

        ExceptionConfig customSub =
            new CustomExceptionConfigArg("java.lang.IllegalStateException");

        customSub.setExtends("java.lang.NullPointerException");
        moduleConfig.addExceptionConfig(customSub);

        try {
            actionServlet.processExceptionConfigClass(customSub, moduleConfig);
        } catch (Exception e) {
View Full Code Here

   
        //
        // Look up the ExceptionConfig that's associated with this Throwable.
        //
        Class exClass = ex.getClass();
        ExceptionConfig exceptionConfig = null;
        if ( actionMapping != null )
        {
            exceptionConfig = actionMapping.findException( exClass );
        }
        else
        {
            // If the mapping was null (i.e., the exception happened before we got the action mapping), look for the
            // exception only in the module config.
            exceptionConfig = getExceptionConfig( exClass, flowController.getModuleConfig() );
        }
       
        //
        // If there was no applicable exception handler in the current ModuleConfig, look in Global.app's module.
        //
        if ( exceptionConfig == null )
        {
            FlowController fallbackFC =
                    getFallbackFlowController( flowController, exClass, request, response, getServletContext() );
           
            if ( fallbackFC != null )
            {
                flowController = fallbackFC;
                context = new FlowControllerHandlerContext( request, response, flowController );
                exceptionConfig = getExceptionConfig( exClass, flowController.getModuleConfig() );
               
                if ( exceptionConfig != null )
                {
                    // This is the module that will be handling the exception.  Ensure that its message resources are
                    // initialized.
                    assert request instanceof HttpServletRequest : request.getClass().getName();
                    InternalUtils.selectModule( flowController.getModuleConfig().getPrefix(),
                                               ( HttpServletRequest ) request, getServletContext() );
                    rw.setCurrentFlowController( flowController );
                }
            }
           
            actionMapping = null;   // This action mapping isn't relevant if we found the exception elsewhere.
        }
       
        if ( exceptionConfig != null )
        {
            if ( _log.isDebugEnabled() )
            {
                _log.debug( "Found exception-config for exception " + exClass.getName()
                            + ": handler=" + exceptionConfig.getHandler() + ", path=" + exceptionConfig.getPath() );
            }

            //
            // First, see if it should be handled by invoking a handler method.
            //
View Full Code Here

        context.getRequest().setAttribute( Globals.EXCEPTION_KEY, ex );
    }
   
    protected ExceptionConfig getExceptionConfig( Class exceptionType, ModuleConfig moduleConfig )
    {
        ExceptionConfig config = null;
               
        if ( moduleConfig != null )
        {
            while ( config == null && exceptionType != null )
            {
View Full Code Here

    }
   
    private boolean checkForExceptionConfig( SharedFlowController sf, Class exClass, ServletRequest request )
    {
        ModuleConfig mc = sf.getModuleConfig();
        ExceptionConfig ec = getExceptionConfig( exClass, mc );
       
        if ( ec != null )
        {
            if ( _log.isDebugEnabled() )
            {
View Full Code Here

                                             ActionForm form,
                                             ActionMapping mapping)
        throws IOException, ServletException {

        // Is there a defined handler for this exception?
        ExceptionConfig config = mapping.findException(exception.getClass());
        if (config == null) {
            log.warn(getInternal().getMessage("unhandledException",
                                              exception.getClass()));
            if (exception instanceof IOException) {
                throw (IOException) exception;
            } else if (exception instanceof ServletException) {
                throw (ServletException) exception;
            } else {
                throw new ServletException(exception);
            }
        }

        // Use the configured exception handling
        try {
            ExceptionHandler handler = (ExceptionHandler)
            RequestUtils.applicationInstance(config.getHandler());
            return (handler.execute(exception, config, mapping, form,
                                    request, response));
        } catch (Exception e) {
            throw new ServletException(e);
        }
View Full Code Here

TOP

Related Classes of org.apache.struts.config.ExceptionConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.