Example usage for javax.servlet UnavailableException UnavailableException

List of usage examples for javax.servlet UnavailableException UnavailableException

Introduction

In this page you can find the example usage for javax.servlet UnavailableException UnavailableException.

Prototype


public UnavailableException(String msg) 

Source Link

Document

Constructs a new exception with a descriptive message indicating that the servlet is permanently unavailable.

Usage

From source file:net.wastl.webmail.storage.simple.SimpleStorage.java

protected void loadXMLSysData() throws UnavailableException {
    String datapath = parent.getProperty("webmail.data.path");
    String file = "file://" + datapath + System.getProperty("file.separator") + "webmail.xml";
    // String file=datapath+System.getProperty("file.separator")+"webmail.xml";
    // bug fixed by Christian Senet
    Document root;/*from  w  w  w . j  a  v  a 2s .c om*/
    try {
        DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        root = parser.parse(file);
        log.debug("Configuration file parsed, document: " + root);
        sysdata = new XMLSystemData(root, cs);
        log.debug("SimpleStorage: WebMail configuration loaded.");
    } catch (Exception ex) {
        log.error("SimpleStorage: Failed to load WebMail configuration file", ex);
        throw new UnavailableException(ex.getMessage());
    }
}

From source file:net.yacy.http.servlets.YaCyDefaultServlet.java

@Override
public void init() throws UnavailableException {
    Switchboard sb = Switchboard.getSwitchboard();
    _htDocsPath = sb.htDocsPath;//  w  w  w  .j  ava  2s .c o m
    _htLocalePath = sb.getDataPath("locale.translated_html", "DATA/LOCALE/htroot");

    _servletContext = getServletContext();

    _mimeTypes = new MimeTypes();
    String tmpstr = this.getServletContext().getInitParameter("welcomeFile");
    if (tmpstr == null) {
        _welcomes = HTTPDFileHandler.defaultFiles;
    } else {
        _welcomes = new String[] { tmpstr, "index.html" };
    }
    _acceptRanges = getInitBoolean("acceptRanges", _acceptRanges);
    _dirAllowed = getInitBoolean("dirAllowed", _dirAllowed);

    Resource.setDefaultUseCaches(false); // caching is handled internally (prevent double caching)

    String rb = getInitParameter("resourceBase");
    try {
        if (rb != null) {
            _resourceBase = Resource.newResource(rb);
        } else {
            _resourceBase = Resource.newResource(
                    sb.getConfig(SwitchboardConstants.HTROOT_PATH, SwitchboardConstants.HTROOT_PATH_DEFAULT)); //default
        }
    } catch (IOException e) {
        ConcurrentLog.severe("FILEHANDLER", "YaCyDefaultServlet: resource base (htRootPath) missing");
        ConcurrentLog.logException(e);
        throw new UnavailableException(e.toString());
    }
    if (ConcurrentLog.isFine("FILEHANDLER")) {
        ConcurrentLog.fine("FILEHANDLER", "YaCyDefaultServlet: resource base = " + _resourceBase);
    }
    templateMethodCache = new ConcurrentHashMap<File, SoftReference<Method>>();
}

From source file:nl.b3p.commons.security.XmlSecurityDatabase.java

/** Initializes the servlet.
 *///from w  ww .  j a  va2 s. c o  m
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    // log = LogFactory.getLog(this.getClass());
    // Initialize Torque
    try {
        String configLocation = getServletContext().getRealPath(config.getInitParameter("config"));
        log("config pad: " + configLocation);
        FileReader fr = new FileReader(configLocation);
        if (fr == null) {
            if (log.isDebugEnabled()) {
                log.debug("config reader is null");
            }
        } else {
            try {
                securityDatabase = WebappUsers.unmarshal(fr);
            } catch (MarshalException me) {
                log.error("MarshalException", me);
            } catch (ValidationException ve) {
                log.error("MarshalException", ve);
            }
        }
    } catch (Exception e) {
        log.error("Xml Security Database load exception", e);
        throw new UnavailableException("Cannot load xml security database");
    }

    // Omzetten in gemakkelijk uitleesbare objecten
    if (securityDatabase != null && log != null) {
        if (log.isDebugEnabled()) {
            log.debug("Xml Database is not null.");
        }
        maxNumOfSessions = securityDatabase.getMaxsessions();

        log.debug("Max number of active sessions: " + maxNumOfSessions + " (0 = no limit)");

        userpasswords = new HashMap();
        userroles = new HashMap();
        int userCount = securityDatabase.getUserCount();
        for (int i = 0; i < userCount; i++) {
            User aUser = null;
            try {
                aUser = securityDatabase.getUser(i);
            } catch (IndexOutOfBoundsException ioobe) {
                break;
            }
            if (aUser != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Init user: " + aUser.getUsername());
                }
                userpasswords.put(aUser.getUsername(), aUser.getPassword());
                String theRoles = aUser.getRoles();
                if (theRoles == null || theRoles.length() == 0) {
                    continue;
                }
                ArrayList roleList = new ArrayList();
                int roleCount = securityDatabase.getRoleCount();
                for (int j = 0; j < roleCount; j++) {
                    Role aRole = null;
                    try {
                        aRole = securityDatabase.getRole(j);
                    } catch (IndexOutOfBoundsException ioobe) {
                        break;
                    }
                    if (aRole != null && theRoles.indexOf(aRole.getRolename()) >= 0) {
                        roleList.add(aRole.getRolename());
                        if (log.isDebugEnabled()) {
                            log.debug("  adding role: " + aRole.getRolename());
                        }
                    }
                }
                userroles.put(aUser.getUsername(), roleList);
            }
        }
        initialized = true;
        if (log.isInfoEnabled()) {
            log.debug("Initializing Xml Security Database servlet");
        }
    } else {
        System.out.println("XML Security Database servlet not initialized!");
    }

}

From source file:org.alfresco.web.app.servlet.JBPMDeployProcessServlet.java

@Override
public void init() throws ServletException {
    // Render this servlet permanently unavailable if its enablement property is not set
    WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
    Properties globalProperties = (Properties) wc.getBean(BEAN_GLOBAL_PROPERTIES);
    String enabled = globalProperties.getProperty(PROP_ENABLED);
    if (!PropertyCheck.isValidPropertyString(enabled) || !Boolean.parseBoolean(enabled)) {
        throw new UnavailableException("system.workflow.deployservlet.enabled=false");
    }/* w  ww.  j av  a  2s .com*/
}

From source file:org.apache.beehive.netui.pageflow.AutoRegisterActionServlet.java

/**
 * This method is almost exactly the same as the base class initModuleConfig.  The only difference
 * is that it does not throw an UnavailableException if a module configuration file is missing or
 * invalid.// www . j av  a  2 s .c om
 */
protected ModuleConfig initModuleConfig(String prefix, String paths) throws ServletException {

    if (_log.isDebugEnabled()) {
        _log.debug("Initializing module path '" + prefix + "' configuration from '" + paths + '\'');
    }

    // Parse the configuration for this module
    ModuleConfig moduleConfig = null;
    InputStream input = null;
    String mapping;

    try {
        ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
        moduleConfig = factoryObject.createModuleConfig(prefix);

        // Support for module-wide ActionMapping type override
        mapping = getServletConfig().getInitParameter("mapping");
        if (mapping != null) {
            moduleConfig.setActionMappingClass(mapping);
        }

        // Configure the Digester instance we will use
        Digester digester = initConfigDigester();

        // Process each specified resource path
        while (paths.length() > 0) {
            digester.push(moduleConfig);
            String path;
            int comma = paths.indexOf(',');
            if (comma >= 0) {
                path = paths.substring(0, comma).trim();
                paths = paths.substring(comma + 1);
            } else {
                path = paths.trim();
                paths = "";
            }
            if (path.length() < 1) {
                break;
            }

            URL url = getConfigResource(path);

            //
            // THIS IS THE MAIN DIFFERENCE: we're doing a null-check here.
            //
            if (url != null) {
                URLConnection conn = url.openConnection();
                conn.setUseCaches(false);
                InputStream in = conn.getInputStream();

                try {
                    InputSource is = new InputSource(in);
                    is.setSystemId(url.toString());
                    input = getConfigResourceAsStream(path);
                    is.setByteStream(input);

                    // also, we're not letting it fail here either.
                    try {
                        digester.parse(is);
                        getServletContext().setAttribute(Globals.MODULE_KEY + prefix, moduleConfig);
                    } catch (Exception e) {
                        _log.error(Bundle.getString("PageFlow_Struts_ModuleParseError", path), e);
                    }
                    input.close();
                } finally {
                    in.close();
                }
            } else {
                //
                // Special case.  If this is the default (root) module and the module path is one that's normally
                // generated by the page flow compiler, then we don't want to error out if it's missing, since
                // this probably just means that there's no root-level page flow.  Set up a default, empty,
                // module config.
                //
                if (prefix.equals("") && isAutoLoadModulePath(path, prefix)) {
                    if (_log.isInfoEnabled()) {
                        _log.info("There is no root module at " + path + "; initializing a default module.");
                    }

                    //
                    // Set the ControllerConfig to a MissingRootModuleControllerConfig.  This is used by
                    // PageFlowRequestProcessor.
                    //
                    moduleConfig.setControllerConfig(new MissingRootModuleControllerConfig());
                } else {
                    _log.error(Bundle.getString("PageFlow_Struts_MissingModuleConfig", path));
                }
            }
        }

    } catch (Throwable t) {
        _log.error(internal.getMessage("configParse", paths), t);
        throw new UnavailableException(internal.getMessage("configParse", paths));
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }

    // Force creation and registration of DynaActionFormClass instances
    // for all dynamic form beans we will be using
    FormBeanConfig fbs[] = moduleConfig.findFormBeanConfigs();
    for (int i = 0; i < fbs.length; i++) {
        if (fbs[i].getDynamic()) {
            DynaActionFormClass.createDynaActionFormClass(fbs[i]);
        }
    }

    // Special handling for the default module (for
    // backwards compatibility only, will be removed later)
    if (prefix.length() < 1) {
        defaultControllerConfig(moduleConfig);
        defaultMessageResourcesConfig(moduleConfig);
    }

    // Return the completed configuration object
    //config.freeze();  // Now done after plugins init
    return moduleConfig;

}

From source file:org.apache.click.ClickServlet.java

/**
 * Initialize the Click servlet and the Velocity runtime.
 *
 * @see javax.servlet.GenericServlet#init()
 *
 * @throws ServletException if the application configuration service could
 * not be initialized/*from www  .j a  v  a 2 s .c  o  m*/
 */
@Override
public void init() throws ServletException {

    try {

        // Create and initialize the application config service
        configService = createConfigService(getServletContext());
        initConfigService(getServletContext());
        logger = configService.getLogService();
        if (logger.isInfoEnabled()) {
            logger.info("Click " + ClickUtils.getClickVersion() + " initialized in "
                    + configService.getApplicationMode() + " mode");
        }
        resourceService = configService.getResourceService();

    } catch (Throwable e) {
        // In mock mode this exception can occur if click.xml is not
        // available.
        if (getServletContext().getAttribute(MOCK_MODE_ENABLED) != null) {
            return;
        }

        e.printStackTrace();

        String msg = "error while initializing Click servlet; throwing " + "javax.servlet.UnavailableException";

        log(msg, e);

        throw new UnavailableException(e.toString());
    }
}

From source file:org.apache.struts.action.ActionServlet.java

/**
 * <p>Initialize this servlet.  Most of the processing has been factored
 * into support methods so that you can override particular functionality
 * at a fairly granular level.</p>
 *
 * @throws ServletException if we cannot configure ourselves correctly
 *///  w  w  w. j a  v  a 2s  .c om
public void init() throws ServletException {
    final String configPrefix = "config/";
    final int configPrefixLength = configPrefix.length() - 1;

    // Wraps the entire initialization in a try/catch to better handle
    // unexpected exceptions and errors to provide better feedback
    // to the developer
    try {
        initInternal();
        initOther();
        initServlet();
        initChain();

        getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
        initModuleConfigFactory();

        // Initialize modules as needed
        ModuleConfig moduleConfig = initModuleConfig("", config);

        initModuleMessageResources(moduleConfig);
        initModulePlugIns(moduleConfig);
        initModuleFormBeans(moduleConfig);
        initModuleForwards(moduleConfig);
        initModuleExceptionConfigs(moduleConfig);
        initModuleActions(moduleConfig);
        moduleConfig.freeze();

        Enumeration names = getServletConfig().getInitParameterNames();

        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();

            if (!name.startsWith(configPrefix)) {
                continue;
            }

            String prefix = name.substring(configPrefixLength);

            moduleConfig = initModuleConfig(prefix, getServletConfig().getInitParameter(name));
            initModuleMessageResources(moduleConfig);
            initModulePlugIns(moduleConfig);
            initModuleFormBeans(moduleConfig);
            initModuleForwards(moduleConfig);
            initModuleExceptionConfigs(moduleConfig);
            initModuleActions(moduleConfig);
            moduleConfig.freeze();
        }

        this.initModulePrefixes(this.getServletContext());

        this.destroyConfigDigester();
    } catch (UnavailableException ex) {
        throw ex;
    } catch (Throwable t) {
        // The follow error message is not retrieved from internal message
        // resources as they may not have been able to have been
        // initialized
        log.error("Unable to initialize Struts ActionServlet due to an "
                + "unexpected exception or error thrown, so marking the "
                + "servlet as unavailable.  Most likely, this is due to an "
                + "incorrect or missing library dependency.", t);
        throw new UnavailableException(t.getMessage());
    }
}

From source file:org.apache.struts.action.ActionServlet.java

/**
 * <p>Look up and return the {@link RequestProcessor} responsible for the
 * specified module, creating a new one if necessary.</p>
 *
 * @param config The module configuration for which to acquire and return
 *               a RequestProcessor.//  w ww  .j a va2 s.  co m
 * @return The {@link RequestProcessor} responsible for the specified
 *         module,
 * @throws ServletException If we cannot instantiate a RequestProcessor
 *                          instance a {@link UnavailableException} is
 *                          thrown, meaning your application is not loaded
 *                          and will not be available.
 * @since Struts 1.1
 */
protected synchronized RequestProcessor getRequestProcessor(ModuleConfig config) throws ServletException {
    RequestProcessor processor = this.getProcessorForModule(config);

    if (processor == null) {
        try {
            processor = (RequestProcessor) RequestUtils
                    .applicationInstance(config.getControllerConfig().getProcessorClass());
        } catch (Exception e) {
            throw new UnavailableException("Cannot initialize RequestProcessor of class "
                    + config.getControllerConfig().getProcessorClass() + ": " + e);
        }

        processor.init(this, config);

        String key = Globals.REQUEST_PROCESSOR_KEY + config.getPrefix();

        getServletContext().setAttribute(key, processor);
    }

    return (processor);
}

From source file:org.apache.struts.action.ActionServlet.java

/**
 * <p>Parses one module config file.</p>
 *
 * @param digester Digester instance that does the parsing
 * @param path     The path to the config file to parse.
 * @throws UnavailableException if file cannot be read or parsed
 * @since Struts 1.2//ww w. ja  v  a  2s . c  om
 * @deprecated use parseModuleConfigFile(Digester digester, URL url)
 *             instead
 */
protected void parseModuleConfigFile(Digester digester, String path) throws UnavailableException {
    try {
        List paths = splitAndResolvePaths(path);

        if (paths.size() > 0) {
            // Get first path as was the old behavior
            URL url = (URL) paths.get(0);

            parseModuleConfigFile(digester, url);
        } else {
            throw new UnavailableException("Cannot locate path " + path);
        }
    } catch (UnavailableException ex) {
        throw ex;
    } catch (ServletException ex) {
        handleConfigException(path, ex);
    }
}

From source file:org.apache.struts.action.ActionServlet.java

/**
 * <p>Simplifies exception handling in the parseModuleConfigFile
 * method.<p>//  w w  w  . j  a v  a2s .  com
 *
 * @param path The path to which the exception relates.
 * @param e    The exception to be wrapped and thrown.
 * @throws UnavailableException as a wrapper around Exception
 */
private void handleConfigException(String path, Exception e) throws UnavailableException {
    String msg = internal.getMessage("configParse", path);

    log.error(msg, e);
    throw new UnavailableException(msg);
}