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:org.apache.struts.action.RegistryServlet.java

/**
 * Perform a graceful startup of this servlet instance.
 *
 * @exception ServletException if we cannot process the activity
 *  definition file for this activity/*ww  w.  ja  va2s. co  m*/
 */
public void init() throws ServletException {

    // Record the debugging detail level settings
    String debug = getServletConfig().getInitParameter("debug");
    if (debug != null) {
        try {
            this.debug = Integer.parseInt(debug);
        } catch (NumberFormatException e) {
            throw new UnavailableException("Debug initialization parameter must be an integer");
        }
    }

    // Record the attribute name for our current Context
    String contextKey = getServletConfig().getInitParameter("context-key");
    if (contextKey != null)
        setContextKey(contextKey);

    // Record the attribute name for our current Context
    String registryKey = getServletConfig().getInitParameter("registry-key");
    if (registryKey != null)
        setRegistryKey(registryKey);

    // Parse the activity definition file for our Activity
    String registryPath = getServletConfig().getInitParameter("registry");
    if (registryPath != null)
        this.registryPath = registryPath;
    parse(this.registryPath);

    // Check result of parse
    if (activity == null)
        throw new UnavailableException("No registry defined in resource " + registryPath);

}

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

/**
 * Parse the specified activity definition file for this instance.
 *
 * @param path Context-relative resource path of the activity
 *  definition file// w  w  w.j  a  v a 2  s.c  om
 *
 * @exception ServletException on any processing error in parsing
 */
private void parse(String path) throws ServletException {

    // Get an input source for the specified path
    InputStream is = getServletContext().getResourceAsStream(path);
    if (is == null)
        throw new UnavailableException("Cannot access resource " + path);

    // Configure a Digester instance to parse our definition file
    Digester digester = new Digester();
    digester.setNamespaceAware(true);
    digester.setValidating(false);
    digester.push(this);

    // Add rules to recognize the built-in steps that we know about
    BaseRuleSet brs = new BaseRuleSet();
    digester.addRuleSet(brs);
    digester.addRuleSet(new CoreRuleSet());
    digester.addRuleSet(new IoRuleSet());
    digester.addRuleSet(new WebRuleSet());

    // Add a rule to register the Activity being created
    digester.setRuleNamespaceURI(brs.getNamespaceURI());
    digester.addSetNext("activity", "setActivity", "org.apache.commons.workflow.Activity");

    // Parse the activity definition file
    try {
        digester.parse(is);
    } catch (Throwable t) {
        log("Cannot parse resource " + path, t);
        throw new UnavailableException("Cannot parse resource " + path);
    } finally {
        try {
            is.close();
        } catch (Throwable u) {
            ;
        }
    }

}

From source file:org.apache.struts.chain.ComposableRequestProcessor.java

/**
 * <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
 *//* ww w  . j  a v  a  2  s . c  o m*/
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);
    }
}

From source file:org.apache.struts.service.factory.FactoryService.java

/**
* Initialize our internal MessageResources bundle.
*
* @exception ServletException if we cannot initialize these resources
*//*from   w  w w. java2  s  .com*/
protected void initInternal() throws Exception {

    try {
        internal = MessageResources.getMessageResources(internalName);
    } catch (MissingResourceException e) {
        log("Cannot load internal resources from '" + internalName + "'", e);
        throw new UnavailableException("Cannot load internal resources from '" + internalName + "'");
    }
}

From source file:org.apache.struts.tiles.TilesPlugin.java

/**
 * Create FactoryConfig and initialize it from web.xml and struts-config.xml.
 *
 * @param servlet ActionServlet that is managing all the modules
 *  in this web application./*w ww .j  a  v a  2 s.  com*/
 * @param config ModuleConfig for the module with which
 *  this plugin is associated.
 * @exception ServletException if this <code>PlugIn</code> cannot
 *  be successfully initialized.
 */
protected DefinitionsFactoryConfig readFactoryConfig(ActionServlet servlet, ModuleConfig config)
        throws ServletException {

    // Create tiles definitions config object
    DefinitionsFactoryConfig factoryConfig = new DefinitionsFactoryConfig();
    // Get init parameters from web.xml files
    try {
        DefinitionsUtil.populateDefinitionsFactoryConfig(factoryConfig, servlet.getServletConfig());

    } catch (Exception ex) {
        if (log.isDebugEnabled()) {
            log.debug("", ex);
        }
        ex.printStackTrace();
        throw new UnavailableException(
                "Can't populate DefinitionsFactoryConfig class from 'web.xml': " + ex.getMessage());
    }

    // Get init parameters from struts-config.xml
    try {
        Map strutsProperties = findStrutsPlugInConfigProperties(servlet, config);
        factoryConfig.populate(strutsProperties);

    } catch (Exception ex) {
        if (log.isDebugEnabled()) {
            log.debug("", ex);
        }

        throw new UnavailableException("Can't populate DefinitionsFactoryConfig class from '"
                + config.getPrefix() + "/struts-config.xml':" + ex.getMessage());
    }

    return factoryConfig;
}

From source file:org.apache.struts.validator.ValidatorPlugIn.java

/**
 * Initialize and load our resources.//  w w w.  j  a  v a 2 s .c o  m
 *
 * @param servlet The ActionServlet for our application
 * @param config  The ModuleConfig for our owning module
 * @throws ServletException if we cannot configure ourselves correctly
 */
public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
    // Remember our associated configuration and servlet
    this.config = config;
    this.servlet = servlet;

    // Load our database from persistent storage
    try {
        this.initResources();

        servlet.getServletContext().setAttribute(VALIDATOR_KEY + config.getPrefix(), resources);

        servlet.getServletContext().setAttribute(STOP_ON_ERROR_KEY + '.' + config.getPrefix(),
                (this.stopOnFirstError ? Boolean.TRUE : Boolean.FALSE));
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new UnavailableException("Cannot load a validator resource from '" + pathnames + "'");
    }
}

From source file:org.apache.webapp.admin.ApplicationServlet.java

/**
 * Validate the existence of the Registry that should have been
 * provided to us by an instance of/*www. j a v a  2 s  .  c o  m*/
 * <code>org.apache.catalina.mbean.ServerLifecycleListener</code>
 * enabled at startup time.
 *
 * @exception ServletException if we cannot find the Registry
 */
protected void initRegistry() throws ServletException {

    registry = Registry.getRegistry();
    //(Registry) getServletContext().getAttribute
    //    ("org.apache.catalina.Registry");
    if (registry == null)
        throw new UnavailableException("Registry is not available");

}

From source file:org.apache.webapp.admin.ApplicationServlet.java

/**
 * Validate the existence of the MBeanServer that should have been
 * provided to us by an instance of// www. ja  v  a  2s  .  co m
 * <code>org.apache.catalina.mbean.ServerLifecycleListener</code>
 * enabled at startup time.
 *
 * @exception ServletException if we cannot find the MBeanServer
 */
protected void initServer() throws ServletException {

    server = Registry.getRegistry().getMBeanServer();
    //(MBeanServer) getServletContext().getAttribute
    //    ("org.apache.catalina.MBeanServer");
    if (server == null)
        throw new UnavailableException("MBeanServer is not available");

}

From source file:org.gss_project.gss.server.rest.Webdav.java

@Override
public void init() throws ServletException {
    if (getServletConfig().getInitParameter("input") != null)
        input = Integer.parseInt(getServletConfig().getInitParameter("input"));

    if (getServletConfig().getInitParameter("output") != null)
        output = Integer.parseInt(getServletConfig().getInitParameter("output"));

    fileEncoding = getServletConfig().getInitParameter("fileEncoding");

    // Sanity check on the specified buffer sizes
    if (input < 256)
        input = 256;/*from w w  w  .j a  v a2 s  . c o  m*/
    if (output < 256)
        output = 256;
    if (logger.isDebugEnabled())
        logger.debug("Input buffer size=" + input + ", output buffer size=" + output);

    if (getServletConfig().getInitParameter("secret") != null)
        secret = getServletConfig().getInitParameter("secret");

    // Load the MD5 helper used to calculate signatures.
    try {
        md5Helper = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new UnavailableException("No MD5");
    }
}

From source file:org.mobicents.servlet.sip.pbx.PbxServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    SipFactory sipFactory = (SipFactory) getServletContext().getAttribute(SIP_FACTORY);
    LocationService locationService = (LocationService) getServletContext()
            .getAttribute(Constants.LOCATION_SERVICE);

    if (locationService == null) {
        logger.error("No location service in context");
        throw new UnavailableException("no location service");
    }// w  w  w .j a va 2  s  . c o m

    registrar = new RegistrarService();
    registrar.setLocationService(locationService);
    registrar.setSipFactory(sipFactory);

    proxy = new ProxyService();
    proxy.setLocationService(locationService);
    proxy.setSipFactory(sipFactory);

    logger.info("PbxServlet initialized");
}