public void contextInitialized(ServletContextEvent sce) { final ServletContext app = sce.getServletContext(); final Configuration conf = NutchConfiguration.get(app); LOG.info("creating new bean"); NutchBean bean = null; try { bean = new NutchBean(conf); app.setAttribute(KEY, bean); } catch (final IOException ex) { LOG.error(StringUtils.stringifyException(ex)); } }
/** Check to see if the configuration file has been updated so that it may be reloaded. */ private boolean configUpdated() { try { URL url = ctx.getResource(resourcesDir + XHP_CONFIG); URLConnection con; if (url == null) return false; con = url.openConnection(); long lastModified = con.getLastModified(); long XHP_LAST_MODIFIEDModified = 0; if (ctx.getAttribute(XHP_LAST_MODIFIED) != null) { XHP_LAST_MODIFIEDModified = ((Long) ctx.getAttribute(XHP_LAST_MODIFIED)).longValue(); } else { ctx.setAttribute(XHP_LAST_MODIFIED, new Long(lastModified)); return false; } if (XHP_LAST_MODIFIEDModified < lastModified) { ctx.setAttribute(XHP_LAST_MODIFIED, new Long(lastModified)); return true; } } catch (Exception ex) { getLogger().severe("XmlHttpProxyServlet error checking configuration: " + ex); } return false; }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String length = request.getParameter("primeLength"); ServletContext context = getServletContext(); synchronized (this) { if ((context.getAttribute("primeBean") == null) || (!isMissing(length))) { PrimeBean primeBean = new PrimeBean(length); context.setAttribute("primeBean", primeBean); } String address = "/WEB-INF/results/show-prime.jsp"; RequestDispatcher dispatcher = request.getRequestDispatcher(address); dispatcher.forward(request, response); } }
public void init() { context = getServletContext(); synchronized (context) { pool = (ConnectionPool) context.getAttribute("pool"); if (pool == null) { String driverClassName = context.getInitParameter("driverClassName"); String url = context.getInitParameter("url"); String userName = context.getInitParameter("username"); String password = context.getInitParameter("password"); try { pool = new ConnectionPool(driverClassName, url, userName, password); } catch (Exception error) { Routines.writeToLog( servletName, "Unable to create connection pool : " + error, false, context); } context.setAttribute("pool", pool); } } }