List of usage examples for javax.servlet ServletConfig getServletContext
public ServletContext getServletContext();
From source file:net.oneandone.jasmin.main.Servlet.java
/** creates configuration. */ @Override/* w w w . jav a 2 s . c o m*/ public void init(ServletConfig config) throws ServletException { World world; String str; try { world = new World(); configure(world, "http"); configure(world, "https"); str = config.getInitParameter("docroot"); docroot = Application.file(world, str != null ? str : config.getServletContext().getRealPath("")); docroot.checkDirectory(); LOG.info("home: " + world.getHome()); application = Application.load(world, config, docroot); LOG.info("docroot: " + docroot); } catch (RuntimeException | Error e) { error(null, "init", e); throw e; } catch (Exception e) { error(null, "init", e); throw new ServletException(e); } catch (Throwable e) { error(null, "init", e); throw new RuntimeException("unexpected throwable", e); } }
From source file:org.kuali.rice.ksb.messaging.servlet.KSBDispatcherServlet.java
/** * This is a workaround after upgrading to CXF 2.7.0 whereby we could no longer just call "setHideServiceList" on * the ServletController. Instead, it is now reading this information from the ServletConfig, so wrapping the base * ServletContext to return true or false for hide service list depending on whether or not we are in dev mode. *///from w w w.j ava 2 s .c o m protected ServletConfig getCXFServletConfig(final ServletConfig baseServletConfig) { // disable handling of URLs ending in /services which display CXF generated service lists if we are not in dev mode final String shouldHide = Boolean .toString(!ConfigContext.getCurrentContextConfig().getDevMode().booleanValue()); return new ServletConfig() { private static final String HIDE_SERVICE_LIST_PAGE_PARAM = "hide-service-list-page"; @Override public String getServletName() { return baseServletConfig.getServletName(); } @Override public ServletContext getServletContext() { return baseServletConfig.getServletContext(); } @Override public String getInitParameter(String parameter) { if (HIDE_SERVICE_LIST_PAGE_PARAM.equals(parameter)) { return shouldHide; } return baseServletConfig.getInitParameter(parameter); } @Override public Enumeration<String> getInitParameterNames() { List<String> initParameterNames = EnumerationUtils .toList(baseServletConfig.getInitParameterNames()); initParameterNames.add(HIDE_SERVICE_LIST_PAGE_PARAM); return new Vector<String>(initParameterNames).elements(); } }; }
From source file:com.liferay.portal.servlet.MainServlet.java
public void init(ServletConfig config) throws ServletException { synchronized (MainServlet.class) { super.init(config); Config.initializeConfig();/* w ww . j a v a 2 s . co m*/ com.dotmarketing.util.Config.setMyApp(config.getServletContext()); // Need the plugin root dir before Hibernate comes up try { APILocator.getPluginAPI() .setPluginJarDir(new File(config.getServletContext().getRealPath("WEB-INF/lib"))); } catch (IOException e1) { Logger.debug(InitServlet.class, "IOException: " + e1.getMessage(), e1); } // Checking for execute upgrades try { StartupTasksExecutor.getInstance().executeUpgrades(config.getServletContext().getRealPath(".")); } catch (DotRuntimeException e1) { throw new ServletException(e1); } catch (DotDataException e1) { throw new ServletException(e1); } // Starting the reindexation threads ClusterThreadProxy.createThread(); if (Config.getBooleanProperty("DIST_INDEXATION_ENABLED")) { ClusterThreadProxy.startThread(Config.getIntProperty("DIST_INDEXATION_SLEEP", 500), Config.getIntProperty("DIST_INDEXATION_INIT_DELAY", 5000)); } ReindexThread.startThread(Config.getIntProperty("REINDEX_THREAD_SLEEP", 500), Config.getIntProperty("REINDEX_THREAD_INIT_DELAY", 5000)); try { EventsProcessor.process(new String[] { StartupAction.class.getName() }, true); } catch (Exception e) { Logger.error(this, e.getMessage(), e); } // Context path ServletConfig sc = getServletConfig(); ServletContext ctx = getServletContext(); String ctxPath = GetterUtil.get(sc.getInitParameter("ctx_path"), "/"); ctx.setAttribute(WebKeys.CTX_PATH, StringUtil.replace(ctxPath + "/c", "//", "/")); ctx.setAttribute(WebKeys.CAPTCHA_PATH, StringUtil.replace(ctxPath + "/captcha", "//", "/")); ctx.setAttribute(WebKeys.IMAGE_PATH, StringUtil.replace(ctxPath + "/image", "//", "/")); // Company id _companyId = ctx.getInitParameter("company_id"); ctx.setAttribute(WebKeys.COMPANY_ID, _companyId); // Initialize portlets try { String[] xmls = new String[] { Http.URLtoString(ctx.getResource("/WEB-INF/portlet.xml")), Http.URLtoString(ctx.getResource("/WEB-INF/portlet-ext.xml")), Http.URLtoString(ctx.getResource("/WEB-INF/liferay-portlet.xml")), Http.URLtoString(ctx.getResource("/WEB-INF/liferay-portlet-ext.xml")) }; PortletManagerUtil.initEAR(xmls); } catch (Exception e) { Logger.error(this, e.getMessage(), e); } // Initialize portlets display try { String xml = Http.URLtoString(ctx.getResource("/WEB-INF/liferay-display.xml")); Map oldCategories = (Map) WebAppPool.get(_companyId, WebKeys.PORTLET_DISPLAY); Map newCategories = PortletManagerUtil.getEARDisplay(xml); Map mergedCategories = PortalUtil.mergeCategories(oldCategories, newCategories); WebAppPool.put(_companyId, WebKeys.PORTLET_DISPLAY, mergedCategories); } catch (Exception e) { Logger.error(this, e.getMessage(), e); } // Initialize skins // // try { // String[] xmls = new String[] { Http.URLtoString(ctx.getResource("/WEB-INF/liferay-skin.xml")), // Http.URLtoString(ctx.getResource("/WEB-INF/liferay-skin-ext.xml")) }; // // SkinManagerUtil.init(xmls); // } catch (Exception e) { // Logger.error(this, e.getMessage(), e); // } // Check company try { CompanyLocalManagerUtil.checkCompany(_companyId); } catch (Exception e) { Logger.error(this, e.getMessage(), e); } // Check web settings try { String xml = Http.URLtoString(ctx.getResource("/WEB-INF/web.xml")); _checkWebSettings(xml); } catch (Exception e) { Logger.error(this, e.getMessage(), e); } // Scheduler // try { // Iterator itr = // PortletManagerUtil.getPortlets(_companyId).iterator(); // // while (itr.hasNext()) { // Portlet portlet = (Portlet)itr.next(); // // String className = portlet.getSchedulerClass(); // // if (portlet.isActive() && className != null) { // Scheduler scheduler = // (Scheduler)InstancePool.get(className); // // scheduler.schedule(); // } // } // } // catch (ObjectAlreadyExistsException oaee) { // } // catch (Exception e) { // Logger.error(this,e.getMessage(),e); // } // Message Resources MultiMessageResources messageResources = (MultiMessageResources) ctx.getAttribute(Globals.MESSAGES_KEY); messageResources.setServletContext(ctx); WebAppPool.put(_companyId, Globals.MESSAGES_KEY, messageResources); // Current users WebAppPool.put(_companyId, WebKeys.CURRENT_USERS, new TreeMap()); // HttpBridge TaskController.bridgeUserServicePath = "/httpbridge/home"; TaskController.bridgeHttpServicePath = "/httpbridge/http"; TaskController.bridgeGotoTag = "(goto)"; TaskController.bridgeThenTag = "(then)"; TaskController.bridgePostTag = "(post)"; // Process startup events try { EventsProcessor.process(PropsUtil.getArray(PropsUtil.GLOBAL_STARTUP_EVENTS), true); EventsProcessor.process(PropsUtil.getArray(PropsUtil.APPLICATION_STARTUP_EVENTS), new String[] { _companyId }); } catch (Exception e) { Logger.error(this, e.getMessage(), e); } PortalInstances.init(_companyId); } }
From source file:org.apache.velocity.tools.view.servlet.VelocityViewServlet.java
/** * Looks up an init parameter with the specified key in either the * ServletConfig or, failing that, in the ServletContext. *///from w ww. j ava 2 s. c o m protected String findInitParameter(ServletConfig config, String key) { // check the servlet config String param = config.getInitParameter(key); if (param == null || param.length() == 0) { // check the servlet context ServletContext servletContext = config.getServletContext(); param = servletContext.getInitParameter(key); } return param; }
From source file:com.idega.slide.webdavservlet.DomainConfig.java
/** * <p>/* w w w . j a v a 2s . c o m*/ * Gets the path to the Domain.xml file that is used to initialize Slide * </p> * @return */ protected String getDomainPath(ServletConfig config) { String domainparam; String domainTxPath = "/idegaweb/bundles/org.apache.slide.bundle/properties/Domain-FileStore.xml"; String domainRdbmsPath = "/idegaweb/bundles/org.apache.slide.bundle/properties/Domain.xml"; IWMainApplication iwma = IWMainApplication.getIWMainApplication(config.getServletContext()); domainparam = domainTxPath; try { //First check if a written application property is set: String typeProperty = iwma.getSettings().getProperty(SLIDE_STORE_TYPE); String basePathProperty = iwma.getSettings().getProperty(SLIDE_DATA_PATH); if (basePathProperty != null) { usingVariableBase = true; this.basePath = basePathProperty; } if (typeProperty != null) { if (typeProperty.equals(TYPE_TXFILE)) { domainparam = domainTxPath; } else if (typeProperty.equals(TYPE_RDBMS)) { domainparam = domainRdbmsPath; } } else { if (basePathProperty == null) { basePathProperty = "../data"; iwma.getSettings().setProperty(SLIDE_DATA_PATH, basePathProperty); usingVariableBase = true; this.basePath = basePathProperty; } domainparam = domainTxPath; } //Register the usage for future reference if (domainparam.equals(domainTxPath)) { iwma.getSettings().setProperty(SLIDE_STORE_TYPE, TYPE_TXFILE); } else if (domainparam.equals(domainRdbmsPath)) { iwma.getSettings().setProperty(SLIDE_STORE_TYPE, TYPE_RDBMS); } //THE DEFAULT WILL NOW BE TXFILE!! //Eiki //Secondly check the database if it supports slide: // Connection conn = ConnectionBroker.getConnection(); // String datastoreType = SQLSchemaAdapter.detectDataStoreType(conn); // ConnectionBroker.freeConnection(conn); // SQLSchemaAdapter adapter = SQLSchemaAdapter.getInstance(datastoreType); // if(adapter.getSupportsSlide()){ // domainparam=domainRdbmsPath; // } } catch (Exception e) { e.printStackTrace(); } return domainparam; }
From source file:org.apache.ode.axis2.ODEServer.java
public void init(ServletConfig config, ConfigurationContext configContext) throws ServletException { init(config.getServletContext().getRealPath("/WEB-INF"), configContext); }
From source file:com.vaadin.addon.jpacontainer.demo.servlet.SpringApplicationServlet.java
@Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); /*/* w w w . j a va2 s. com*/ * Look up the name of the Vaadin application prototype bean. */ applicationBean = servletConfig.getInitParameter("applicationBean"); if (applicationBean == null) { if (logger.isErrorEnabled()) { logger.error("ApplicationBean not specified in servlet parameters"); } throw new ServletException("ApplicationBean not specified in servlet parameters"); } if (logger.isInfoEnabled()) { logger.info("Found Vaadin ApplicationBean [" + applicationBean + "]"); } /* * Fetch the Spring web application context */ applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletConfig.getServletContext()); if (!applicationContext.isPrototype(applicationBean)) { if (logger.isWarnEnabled()) { logger.warn("ApplicationBean not configured as a prototype"); } } applicationClass = (Class<? extends Application>) applicationContext.getType(applicationBean); if (logger.isDebugEnabled()) { logger.debug("Vaadin application class is [" + applicationClass + "]"); } }
From source file:de.betterform.agent.web.resources.ResourceServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); if ("false".equals(config.getInitParameter("caching"))) { caching = false;/*from w w w . ja v a2 s. c o m*/ if (LOG.isTraceEnabled()) { LOG.trace("Caching of Resources is disabled"); } } else { caching = true; if (LOG.isTraceEnabled()) { LOG.trace("Caching of Resources is enabled - resources are loaded from classpath"); } } this.lastModified = getLastModifiedValue(); String path = null; try { path = WebFactory.getRealPath("WEB-INF/classes/META-INF/resources", config.getServletContext()); } catch (XFormsConfigException e) { throw new ServletException(e); } if (path != null && new File(path).exists()) { exploded = true; } initMimeTypes(); initResourceStreamers(); }
From source file:org.jahia.bin.JahiaAdministration.java
/** * Default init inherited from HttpServlet. This method set config and * context static variables./*from w w w . ja va 2s .c o m*/ * * @param aConfig Servlet configuration (inherited). */ public void init(ServletConfig aConfig) throws ServletException { super.init(aConfig); // get servlet config and context... JahiaAdministration.context = aConfig.getServletContext(); }
From source file:com.log4ic.compressor.servlet.CompressionServlet.java
@Override public void init(ServletConfig config) throws ServletException { if (!initialized) { String cacheDir;/*from w w w . j ava 2s. co m*/ CacheType cacheType = null; Integer cacheCount = null; boolean autoClean = true; int cleanHourAgo = 4; int lowHit = 3; if (config != null) { //? cacheDir = config.getInitParameter("cacheDir"); if (StringUtils.isNotBlank(cacheDir)) { if (cacheDir.startsWith("{contextPath}")) { cacheDir = getRootAbsolutePath(config.getServletContext()) + cacheDir.replace("{contextPath}", ""); } cacheDir = FileUtils.appendSeparator(cacheDir); } else { cacheDir = getRootAbsolutePath(config.getServletContext()) + "static/compressed/"; } // String cacheTypeStr = config.getInitParameter("cacheType"); if (StringUtils.isNotBlank(cacheTypeStr)) { try { cacheType = CacheType.valueOf(cacheTypeStr.toUpperCase()); } catch (IllegalArgumentException e) { } } if ("none".equals(cacheTypeStr)) { cacheType = null; } // String cacheCountStr = config.getInitParameter("cacheCount"); if (StringUtils.isNotBlank(cacheCountStr)) { try { cacheCount = Integer.parseInt(cacheCountStr); } catch (Exception e) { } } if (cacheCount == null) { cacheCount = 5000; } String autoCleanStr = config.getInitParameter("autoClean"); if (StringUtils.isNotBlank(autoCleanStr)) { try { autoClean = Boolean.parseBoolean(autoCleanStr); } catch (Exception e) { } } String fileDomain = config.getInitParameter("fileDomain"); if (StringUtils.isNotBlank(fileDomain)) { CompressionServlet.fileDomain = fileDomain; } Class cacheManagerClass = null; String cacheManagerClassStr = config.getInitParameter("cacheManager"); if (StringUtils.isNotBlank(cacheManagerClassStr)) { try { cacheManagerClass = CompressionServlet.class.getClassLoader() .loadClass(cacheManagerClassStr); } catch (ClassNotFoundException e) { logger.error("??!", e); } } else { cacheManagerClass = SimpleCacheManager.class; } if (autoClean) { String cleanIntervalStr = config.getInitParameter("cleanInterval"); long cleanInterval = 1000 * 60 * 60 * 5L; if (StringUtils.isNotBlank(cleanIntervalStr)) { try { cleanInterval = Long.parseLong(cleanIntervalStr); } catch (Exception e) { } } String lowHitStr = config.getInitParameter("cleanLowHit"); if (StringUtils.isNotBlank(lowHitStr)) { try { lowHit = Integer.parseInt(autoCleanStr); } catch (Exception e) { } } String cleanHourAgoStr = config.getInitParameter("cleanHourAgo"); if (StringUtils.isNotBlank(cleanHourAgoStr)) { try { cleanHourAgo = Integer.parseInt(cleanHourAgoStr); } catch (Exception e) { } } if (cacheType != null) { try { Constructor constructor = cacheManagerClass.getConstructor(CacheType.class, int.class, int.class, int.class, long.class, String.class); cacheManager = (CacheManager) constructor.newInstance(cacheType, cacheCount, lowHit, cleanHourAgo, cleanInterval, cacheDir); } catch (NoSuchMethodException e) { logger.error("??", e); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InstantiationException e) { logger.error("??", e); } catch (IllegalAccessException e) { logger.error("??", e); } catch (Exception e) { logger.error("??", e); } } } else { if (cacheType != null) { try { Constructor constructor = cacheManagerClass.getConstructor(CacheType.class, int.class, String.class); cacheManager = (CacheManager) constructor.newInstance(cacheType, cacheCount, cacheDir); } catch (NoSuchMethodException e) { logger.error("??", e); } catch (InvocationTargetException e) { logger.error("??", e); } catch (InstantiationException e) { logger.error("??", e); } catch (IllegalAccessException e) { logger.error("??", e); } catch (Exception e) { logger.error("??", e); } } } } initialized = true; } }