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:TransactionConnectionServlet.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    try {/*from w w  w  .  j a  v  a2  s .c o m*/
        // load the driver
        Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    } catch (ClassNotFoundException e) {
        throw new UnavailableException(
                "TransactionConnection.init() ClassNotFoundException: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new UnavailableException(
                "TransactionConnection.init() IllegalAccessException: " + e.getMessage());
    } catch (InstantiationException e) {
        throw new UnavailableException(
                "TransactionConnection.init() InstantiationException: " + e.getMessage());
    }
}

From source file:DedicatedConnectionServlet.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    try {//from   www  .ja  va 2 s . co m
        // load the driver
        Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    } catch (ClassNotFoundException e) {
        throw new UnavailableException("DedicatedConnection.init() ClassNotFoundException: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new UnavailableException("DedicatedConnection.init() IllegalAccessException: " + e.getMessage());
    } catch (InstantiationException e) {
        throw new UnavailableException("DedicatedConnection.init() InstantiationException: " + e.getMessage());
    }

    try {
        // establish a connection
        connection = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger");
        connected = System.currentTimeMillis();
    } catch (SQLException e) {
        throw new UnavailableException("DedicatedConnection.init() SQLException: " + e.getMessage());
    }
}

From source file:SessionLogin.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    try {/*from   w  ww.  j  a  v a 2 s  . c  o m*/
        // load the driver
        Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    } catch (ClassNotFoundException e) {
        throw new UnavailableException("Login init() ClassNotFoundException: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new UnavailableException("Login init() IllegalAccessException: " + e.getMessage());
    } catch (InstantiationException e) {
        throw new UnavailableException("Login init() InstantiationException: " + e.getMessage());
    }
}

From source file:au.org.paperminer.common.AbstractServlet.java

/**
 * Check all application wide services required to be available
 * before request servicing can proceed.
 * @exception javax.servlet.UnavailableException Do not start application
 *///from   ww  w.j av  a2s  .c  om
@Override
public void init() throws ServletException {
    m_logger = Logger.getLogger(LOGGER);
    if (!testConnectionPool()) {
        throw new UnavailableException("Database unavailable. Notify Administrator.");
    }
}

From source file:TransactionConnectionServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>A Per Transaction Connection</title>");
    out.println("</head>");
    out.println("<body>");

    Connection connection = null;
    try {// w ww .ja  v  a 2 s.c o  m
        // establish a connection
        connection = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger");
    } catch (SQLException e) {
        throw new UnavailableException("TransactionConnection.init() SQLException: " + e.getMessage());
    }

    Statement statement = null;
    ResultSet resultSet = null;
    String userName = null;
    try {
        // test the connection
        statement = connection.createStatement();
        resultSet = statement.executeQuery("select initcap(user) from sys.dual");
        if (resultSet.next())
            userName = resultSet.getString(1);
    } catch (SQLException e) {
        out.println("TransactionConnection.doGet() SQLException: " + e.getMessage() + "<p>");
    } finally {
        if (resultSet != null)
            try {
                resultSet.close();
            } catch (SQLException ignore) {
            }
        if (statement != null)
            try {
                statement.close();
            } catch (SQLException ignore) {
            }
    }

    if (connection != null) {
        // close the connection
        try {
            connection.close();
        } catch (SQLException ignore) {
        }
    }

    out.println("Hello " + userName + "!<p>");
    out.println("You're using a per transaction connection!<p>");
    out.println("</body>");
    out.println("</html>");
}

From source file:com.boylesoftware.web.impl.routes.RoutesRouterConfiguration.java

@Override
protected void buildRoutes(final ServletContext sc, final RoutesBuilder routes) throws UnavailableException {

    try (final InputStream in = sc.getResourceAsStream(ROUTES_PATH)) {

        if (in == null)
            throw new UnavailableException("No " + ROUTES_PATH + " found in the web-application.");

        final RoutesParser parser = new RoutesParser(
                new CommonTokenStream(new RoutesLexer(new ANTLRInputStream(in))));
        parser.setErrorHandler(new BailErrorStrategy());
        parser.setRoutesBuilder(routes);
        try {//w  ww. j  a v a 2 s  .c o m
            parser.config();
        } catch (final Exception e) {
            this.error(e);
        }

    } catch (final IOException e) {
        this.error(e);
    }
}

From source file:de.ecw.zabos.Globals.java

/**
 * Initalisiert das Bean {@link SpringContext#BEAN_DAEMON_MANAGER}, Klasse
 * {@link DaemonMgr}.//from w  ww .  j  a  v  a2 s. com
 * 
 * @throws UnavailableException
 *             Falls das Bean null ist
 */
private static void initDaemons() throws UnavailableException {
    if (SpringContext.getInstance().getBean(SpringContext.BEAN_DAEMON_MANAGER, DaemonMgr.class) == null) {
        throw new UnavailableException(SpringContext.BEAN_DAEMON_MANAGER + " wurde nicht erstellt");
    }
}

From source file:com.boylesoftware.web.impl.routes.RoutesRouterConfiguration.java

/**
 * Convert exception to {@link UnavailableException} and throw it.
 *
 * @param e Original exception.//from  w ww . j  a v a2s  .com
 *
 * @throws UnavailableException Always.
 */
private void error(final Exception e) throws UnavailableException {

    LogFactory.getLog(this.getClass()).error("error loading router configuration", e);
    throw new UnavailableException("Error loading router configuration: " + e.getMessage());
}

From source file:com.boylesoftware.web.impl.auth.SessionlessAuthenticationService.java

/**
 * Create new authenticator.//from w  ww  . ja va  2s  .  c  o m
 *
 * @param userRecordHandler User record handler.
 * @param userRecordsCache Authenticated user records cache.
 *
 * @throws UnavailableException If an error happens creating the service.
 */
public SessionlessAuthenticationService(final UserRecordHandler<T> userRecordHandler,
        final UserRecordsCache<T> userRecordsCache) throws UnavailableException {

    // store the references
    this.userRecordHandler = userRecordHandler;
    this.userRecordsCache = userRecordsCache;

    // get configured secret key from the JNDI
    String secretKeyStr;
    try {
        final InitialContext jndi = new InitialContext();
        try {
            secretKeyStr = (String) jndi.lookup("java:comp/env/secretKey");
        } finally {
            jndi.close();
        }
    } catch (final NamingException e) {
        throw new UnavailableException("Error looking up secret key in the JNDI: " + e);
    }
    if (!secretKeyStr.matches("[0-9A-Fa-f]{32}"))
        throw new UnavailableException("Configured secret key is" + " invalid. The key must be a 16 bytes value"
                + " encoded as a hexadecimal string.");
    final Key secretKey = new SecretKeySpec(Hex.decode(secretKeyStr), CipherToolbox.ALGORITHM);

    // create the cipher pool
    this.cipherPool = new FastPool<>(new PoolableObjectFactory<CipherToolbox>() {

        @Override
        public CipherToolbox makeNew(final FastPool<CipherToolbox> pool, final int pooledObjectId) {

            return new CipherToolbox(pool, pooledObjectId, secretKey);
        }
    }, "AuthenticatorCiphersPool");
}

From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.Default.java

public void init() throws UnavailableException {
    ServletContext config = getServletContext();
    _servletHandler = ((ServletHandler.Context) config).getServletHandler();
    _httpContext = _servletHandler.getHttpContext();

    _acceptRanges = getInitBoolean("acceptRanges");
    _dirAllowed = getInitBoolean("dirAllowed");
    _putAllowed = getInitBoolean("putAllowed");
    _delAllowed = getInitBoolean("delAllowed");
    _redirectWelcomeFiles = getInitBoolean("redirectWelcome");
    _minGzipLength = getInitInt("minGzipLength");

    String rrb = getInitParameter("relativeResourceBase");
    if (rrb != null) {
        try {/*w  w  w. ja  va 2s. com*/
            _resourceBase = _httpContext.getBaseResource().addPath(rrb);
        } catch (Exception e) {
            log.warn(LogSupport.EXCEPTION, e);
            throw new UnavailableException(e.toString());
        }
    }

    String rb = getInitParameter("resourceBase");

    if (rrb != null && rb != null)
        throw new UnavailableException("resourceBase & relativeResourceBase");

    if (rb != null) {
        try {
            _resourceBase = Resource.newResource(rb);
        } catch (Exception e) {
            log.warn(LogSupport.EXCEPTION, e);
            throw new UnavailableException(e.toString());
        }
    }
    if (log.isDebugEnabled())
        log.debug("resource base = " + _resourceBase);

    if (_putAllowed)
        _AllowString += ", PUT";
    if (_delAllowed)
        _AllowString += ", DELETE";
    if (_putAllowed && _delAllowed)
        _AllowString += ", MOVE";
}