Example usage for org.apache.commons.dbcp SQLNestedException printStackTrace

List of usage examples for org.apache.commons.dbcp SQLNestedException printStackTrace

Introduction

In this page you can find the example usage for org.apache.commons.dbcp SQLNestedException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.rti.zcore.dar.servlet.DynasiteConfigServlet.java

/**
        * Custom init to modify the XML config files before normal processing by the
        * superclass./*from   w  ww. j  av  a 2  s.c  o  m*/
        *
        * @throws ServletException
                
                
        /**
        * <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>
        *
        * @exception ServletException if we cannot configure ourselves correctly
        */
public void init() throws ServletException {

    // 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();
        // Test that the server is up
        Connection conn = null;
        try {
            conn = DatabaseUtils.getZEPRSCatchableConnection("zepadmin");
        } catch (SQLNestedException e) {
            log.debug("Sleeping");
            Thread.sleep(5000);
            try {
                conn = DatabaseUtils.getZEPRSCatchableConnection("zepadmin");

            } catch (SQLNestedException e1) {
                log.debug("Sleeping");
                Thread.sleep(10000);
                if (conn == null) {
                    // wait
                    log.debug("Sleeping");
                    Thread.sleep(5000);
                }
                // if it is still not ready, let's wait a tad longer
                if (conn == null) {
                    // wait
                    log.debug("It's taking a bit long to access the database.");
                    Thread.sleep(5000);
                }
            }
        } finally {
            try {
                if (conn != null)
                    conn.close();
            } catch (SQLException e3) {
                // TODO Auto-generated catch block
                e3.printStackTrace();
            }
        }

        /*if ((Constants.UPDATES_DYNASITE != null) && (Constants.UPDATES_DYNASITE.equals("true"))) {
           log.debug("Processing Database Updates");
           try {
              UpdateDatabase.execute();
           } catch (SQLException e) {
              log.error("ApplicationUpdate SQL error" + e);
           } catch (Exception e2) {
              e2.printStackTrace();
           }
           log.debug("Finished processing Applicaton Updates");
        }*/

        // ZEPRS DynaSiteObjects
        log.debug("Processing DynaSiteObjects");
        DynasiteConfigServlet.loadDynaSiteObjects();
        Boolean dev = DynaSiteObjects.getDev();

        // uncomment to load Jmdns
        // loadJmdns();

        getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
        initModuleConfigFactory();
        // Initialize modules as needed
        ModuleConfig moduleConfig = initModuleConfig("", config);
        initModuleMessageResources(moduleConfig);
        initModuleDataSources(moduleConfig);
        try {
            initModulePlugIns(moduleConfig);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            log.debug("Error loading struts config files. Re-generating config files.");
            new GenerateStrutsConfig().init(dev);
            e.printStackTrace();
        }
        moduleConfig.freeze();

        Enumeration names = getServletConfig().getInitParameterNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            if (!name.startsWith("config/")) {
                continue;
            }
            String prefix = name.substring(6);
            moduleConfig = initModuleConfig(prefix, getServletConfig().getInitParameter(name));
            initModuleMessageResources(moduleConfig);
            initModuleDataSources(moduleConfig);
            initModulePlugIns(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. Look at the stack trace...", t);
        t.printStackTrace();
        //throw new UnavailableException(t.getMessage());

    }
}