Examples of ExceptionConfig


Examples of org.apache.struts.config.ExceptionConfig

        property.setName("score");
        property.setType("java.lang.String");
        baseFormBean.addFormPropertyConfig(property);

        // Setup the exception handler
        baseException = new ExceptionConfig();
        baseException.setType("java.lang.NullPointerException");
        baseException.setKey("msg.exception.npe");

        // Setup the forward config
        baseForward = new ActionForward("success", "/succes.jsp", false);

        // Setup the action config
        baseAction = new ActionMapping();
        baseAction.setPath("/index");
        baseAction.setType("org.apache.struts.actions.DummyAction");
        baseAction.setName("someForm");
        baseAction.setInput("/input.jsp");
        baseAction.addForwardConfig(new ActionForward("next", "/next.jsp", false));
        baseAction.addForwardConfig(new ActionForward("prev", "/prev.jsp", false));

        ExceptionConfig exceptionConfig = new ExceptionConfig();

        exceptionConfig.setType("java.sql.SQLException");
        exceptionConfig.setKey("msg.exception.sql");
        baseAction.addExceptionConfig(exceptionConfig);

        // Nothing is registered to our module config until they are needed
    }
View Full Code Here

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

Examples of org.apache.struts.config.ExceptionConfig

        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

Examples of org.apache.struts.config.ExceptionConfig

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

        ExceptionConfig result = null;

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

Examples of org.apache.struts.config.ExceptionConfig

     */
    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

Examples of org.apache.struts.config.ExceptionConfig

     * 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

Examples of org.apache.struts.config.ExceptionConfig

     */
    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

Examples of org.apache.struts.config.ExceptionConfig

   
        //
        // 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

Examples of org.apache.struts.config.ExceptionConfig

        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

Examples of org.apache.struts.config.ExceptionConfig

    }
   
    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
TOP
Copyright © 2018 www.massapi.com. 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.