Package org.apache.struts.config

Examples of org.apache.struts.config.ExceptionConfig


       
        ActionConfig[] actionConfigs = moduleConfig.findActionConfigs();
        assertNotNull(actionConfigs);
        assertEquals(2, actionConfigs.length);
       
        ExceptionConfig exceptionConfig = moduleConfig.findExceptionConfig(Exception.class.getName());
        assertNotNull(exceptionConfig);
        assertEquals(Exception.class.getName(), exceptionConfig.getType());
       
        ExceptionConfig[] exceptionConfigs = moduleConfig.findExceptionConfigs();
        assertNotNull(exceptionConfigs);
        assertEquals(1, exceptionConfigs.length);
       
View Full Code Here


     * The ExceptionConfig is loaded from test-struts-factory.xml.
     */
    public void testCreateExceptionConfig() {
        PackageConfig packageConfig = config.getPackageConfig(PACKAGE_NAME);
        ExceptionMappingConfig cfg = (ExceptionMappingConfig) packageConfig.getGlobalExceptionMappingConfigs().get(0);
        ExceptionConfig exceptionConfig = factory.createExceptionConfig(cfg);
        assertNotNull(exceptionConfig);
        assertEquals(Exception.class.getName(), exceptionConfig.getType());

        assertNYI(exceptionConfig, "getBundle", null);
        assertNYI(exceptionConfig, "getHandler", null);
        assertNYI(exceptionConfig, "getKey", null);
        assertNYI(exceptionConfig, "getPath", null);
View Full Code Here

    private void initExceptionConfigs() {
        if (exceptions == null) {
            exceptions = new HashMap();
            List exceptionMappings = delegate.getExceptionMappings();
            for (Iterator i = exceptionMappings.iterator(); i.hasNext();) {
                ExceptionConfig wrapper = strutsFactory.createExceptionConfig((ExceptionMappingConfig) i.next());
                exceptions.put(wrapper.getType(), wrapper);
            }
        }
    }
View Full Code Here

     * Return the exception configurations for this module.  If there
     * are none, a zero-length array is returned.
     */
    public ExceptionConfig[] findExceptionConfigs() {

        ExceptionConfig results[] = new ExceptionConfig[exceptions.size()];
        return ((ExceptionConfig[]) exceptions.values().toArray(results));

    }
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

   
        //
        // 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() );
                    PageFlowRequestWrapper.get( request ).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

     * @since Struts 1.1
     */
    public ExceptionConfig findException(Class type) {

        // Check through the entire superclass hierarchy as needed
        ExceptionConfig config = null;
        while (true) {

            // Check for a locally defined handler
            String name = type.getName();
            config = findExceptionConfig(name);
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.