Java Code Examples for javax.servlet.ServletContext#getServletContextName()
The following examples show how to use
javax.servlet.ServletContext#getServletContextName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Context.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
public static Context concrete(ServletContextEvent servletContextEvent) throws Exception { /* 强制忽略ssl服务器认证 */ SslTools.ignoreSsl(); ServletContext servletContext = servletContextEvent.getServletContext(); Context context = new Context(); context.contextPath = servletContext.getContextPath(); context.clazz = Class.forName(servletContext.getInitParameter(INITPARAMETER_PORJECT)); context.module = context.clazz.getAnnotation(Module.class); context.name = context.module.name(); context.path = servletContext.getRealPath(""); context.servletContext = servletContext; context.servletContextName = servletContext.getServletContextName(); context.weight = Config.currentNode().getApplication().weight(context.clazz); context.scheduleWeight = Config.currentNode().getApplication().scheduleWeight(context.clazz); context.sslEnable = Config.currentNode().getApplication().getSslEnable(); context.initDatas(); servletContext.setAttribute(context.getClass().getName(), context); context.initialized = true; /* 20190927新注册机制 */ // registApplication(context); return context; }
Example 2
Source File: Context.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
public static Context concrete(ServletContextEvent servletContextEvent) throws Exception { ServletContext servletContext = servletContextEvent.getServletContext(); Context context = new Context(); context.contextPath = servletContext.getContextPath(); context.clazz = Class.forName(servletContext.getInitParameter(INITPARAMETER_PORJECT)); context.module = context.clazz.getAnnotation(Module.class); context.name = context.module.name(); context.path = servletContext.getRealPath(""); context.servletContext = servletContext; context.servletContextName = servletContext.getServletContextName(); context.clazz = Class.forName(servletContextEvent.getServletContext().getInitParameter(INITPARAMETER_PORJECT)); context.initDatas(); try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { // context.cleanupSchedule(emc); // context.cleanupScheduleLocal(emc); context.checkDefaultRole(emc); } servletContext.setAttribute(context.getClass().getName(), context); return context; }
Example 3
Source File: SakaiContextLoader.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Allows loading/override of custom bean definitions from sakai.home * * <p>The pattern is the 'servlet_name-context.xml'</p> * * @param sc current servlet context * @param wac the new WebApplicationContext */ @Override protected void customizeContext(ServletContext sc, ConfigurableWebApplicationContext wac) { super.customizeContext(sc, wac); if (wac != null) { final String servletName = sc.getServletContextName(); String location = getHomeBeanDefinitionIfExists(servletName); if (StringUtils.isNotBlank(location)) { String[] configLocations = wac.getConfigLocations(); String[] newLocations = Arrays.copyOf(configLocations, configLocations.length + 1); newLocations[configLocations.length] = "file:" + location; wac.setConfigLocations(newLocations); log.info("Servlet {} added an additional bean config location [{}]", servletName, location); } } }
Example 4
Source File: SLF4JLogChute.java From sakai with Educational Community License v2.0 | 6 votes |
/** * @see LogChute#init(RuntimeServices) */ public void init(RuntimeServices rs) throws Exception { // override from velocity.properties String name = (String) rs.getProperty(RUNTIME_LOG_SLF4J_LOGGER); if (StringUtils.isBlank(name)) { // lets try Sakai convention ServletContext context = (ServletContext) rs.getApplicationAttribute("javax.servlet.ServletContext"); if (context != null) { name = DEFAULT_LOGGER + "." + context.getServletContextName(); name = name.replace("-", "."); } else { // default to "velocity" name = DEFAULT_LOGGER; } } log(INFO_ID, "SLF4JLogChute using logger '" + name + '\''); }
Example 5
Source File: SpringContextService.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Returns a name for this context * * @param servletContext the servlet context * @return name for this context */ private static String getContextName( ServletContext servletContext ) { String name = "lutece"; if ( servletContext != null ) { String contextName = servletContext.getServletContextName( ); if ( contextName == null ) { contextName = servletContext.getContextPath( ); } if ( StringUtils.isNotBlank( contextName ) ) { name = contextName; } } return name; }
Example 6
Source File: SakaiContextLoader.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Allows loading/override of custom bean definitions from sakai.home * * <p>The pattern is the 'servlet_name-context.xml'</p> * * @param sc current servlet context * @param wac the new WebApplicationContext */ @Override protected void customizeContext(ServletContext sc, ConfigurableWebApplicationContext wac) { super.customizeContext(sc, wac); if (wac != null) { final String servletName = sc.getServletContextName(); String location = getHomeBeanDefinitionIfExists(servletName); if (StringUtils.isNotBlank(location)) { String[] configLocations = wac.getConfigLocations(); String[] newLocations = Arrays.copyOf(configLocations, configLocations.length + 1); newLocations[configLocations.length] = "file:" + location; wac.setConfigLocations(newLocations); log.info("Servlet {} added an additional bean config location [{}]", servletName, location); } } }
Example 7
Source File: SLF4JLogChute.java From sakai with Educational Community License v2.0 | 6 votes |
/** * @see LogChute#init(RuntimeServices) */ public void init(RuntimeServices rs) throws Exception { // override from velocity.properties String name = (String) rs.getProperty(RUNTIME_LOG_SLF4J_LOGGER); if (StringUtils.isBlank(name)) { // lets try Sakai convention ServletContext context = (ServletContext) rs.getApplicationAttribute("javax.servlet.ServletContext"); if (context != null) { name = DEFAULT_LOGGER + "." + context.getServletContextName(); name = name.replace("-", "."); } else { // default to "velocity" name = DEFAULT_LOGGER; } } log(INFO_ID, "SLF4JLogChute using logger '" + name + '\''); }
Example 8
Source File: ServletConfigListener.java From deltaspike with Apache License 2.0 | 6 votes |
private void setServletConfig(ServletConfigSource configSource, ServletContextEvent sce) { ServletContext servletContext = sce.getServletContext(); String servletContextName = servletContext.getServletContextName(); if (servletContextName != null && servletContextName.length() > 0) { String oldAppName = ConfigResolver.getPropertyValue(ConfigResolver.DELTASPIKE_APP_NAME_CONFIG); // we first need to unregister the old MBean // as we don't know whether the CDI Extension or the Servlet Listener comes first. // It's simply not defined by the spec :/ ConfigurationExtension.unRegisterConfigMBean(oldAppName); configSource.setPropertyValue(ConfigResolver.DELTASPIKE_APP_NAME_CONFIG, servletContextName); // and as we now did set the new name -> register again: ConfigurationExtension.registerConfigMBean(); } }
Example 9
Source File: StartupListener.java From entando-core with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void contextInitialized(ServletContextEvent event) { ServletContext svCtx = event.getServletContext(); String msg = this.getClass().getName()+ ": INIT " + svCtx.getServletContextName(); System.out.println(msg); super.contextInitialized(event); msg = this.getClass().getName() + ": INIT DONE "+ svCtx.getServletContextName(); System.out.println(msg); }
Example 10
Source File: JavaInformations.java From javamelody with Apache License 2.0 | 4 votes |
public JavaInformations(ServletContext servletContext, boolean includeDetails) { // CHECKSTYLE:ON super(); memoryInformations = new MemoryInformations(); tomcatInformationsList = TomcatInformations.buildTomcatInformationsList(); sessionCount = SessionListener.getSessionCount(); sessionAgeSum = SessionListener.getSessionAgeSum(); activeThreadCount = JdbcWrapper.getActiveThreadCount(); usedConnectionCount = JdbcWrapper.getUsedConnectionCount(); activeConnectionCount = JdbcWrapper.getActiveConnectionCount(); maxConnectionCount = JdbcWrapper.getMaxConnectionCount(); transactionCount = JdbcWrapper.getTransactionCount(); systemLoadAverage = buildSystemLoadAverage(); systemCpuLoad = buildSystemCpuLoad(); processCpuTimeMillis = buildProcessCpuTimeMillis(); unixOpenFileDescriptorCount = buildOpenFileDescriptorCount(); unixMaxFileDescriptorCount = buildMaxFileDescriptorCount(); host = Parameters.getHostName() + '@' + Parameters.getHostAddress(); os = buildOS(); availableProcessors = Runtime.getRuntime().availableProcessors(); javaVersion = System.getProperty("java.runtime.name") + ", " + System.getProperty("java.runtime.version"); jvmVersion = System.getProperty("java.vm.name") + ", " + System.getProperty("java.vm.version") + ", " + System.getProperty("java.vm.info"); if (servletContext == null) { serverInfo = null; contextPath = null; contextDisplayName = null; webappVersion = null; } else { serverInfo = servletContext.getServerInfo(); contextPath = Parameters.getContextPath(servletContext); contextDisplayName = servletContext.getServletContextName(); webappVersion = MavenArtifact.getWebappVersion(); } startDate = START_DATE; jvmArguments = buildJvmArguments(); final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); threadCount = threadBean.getThreadCount(); peakThreadCount = threadBean.getPeakThreadCount(); totalStartedThreadCount = threadBean.getTotalStartedThreadCount(); freeDiskSpaceInTemp = Parameters.TEMPORARY_DIRECTORY.getFreeSpace(); usableDiskSpaceInTemp = Parameters.TEMPORARY_DIRECTORY.getUsableSpace(); springBeanExists = SPRING_AVAILABLE && SpringContext.getSingleton() != null; if (includeDetails) { dataBaseVersion = buildDataBaseVersion(); dataSourceDetails = buildDataSourceDetails(); threadInformationsList = buildThreadInformationsList(); cacheInformationsList = CacheInformations.buildCacheInformationsList(); jcacheInformationsList = JCacheInformations.buildJCacheInformationsList(); jobInformationsList = JobInformations.buildJobInformationsList(); hsErrPidList = HsErrPid.buildHsErrPidList(); pid = PID.getPID(); } else { dataBaseVersion = null; dataSourceDetails = null; threadInformationsList = null; cacheInformationsList = null; jcacheInformationsList = null; jobInformationsList = null; hsErrPidList = null; pid = null; } }
Example 11
Source File: JSPEngineWrapper.java From ontopia with Apache License 2.0 | 4 votes |
@Override public String getServletContextName(ServletContext context) { return context.getServletContextName(); }
Example 12
Source File: GeomajasContextListener.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION") public void contextInitialized(ServletContextEvent servletContextEvent) { ServletContext servletContext = servletContextEvent.getServletContext(); StringBuilder configLocation = new StringBuilder(); configLocation.append("classpath:org/geomajas/spring/geomajasContext.xml"); String additionalLocations = servletContext.getInitParameter(CONFIG_LOCATION_PARAMETER); if (null != additionalLocations) { for (String onePart : additionalLocations.split("\\s")) { String part = onePart.trim(); if (part.length() > 0) { configLocation.append(','); int pos = part.indexOf(':'); if (pos < 0) { // no protocol specified, use classpath. configLocation.append(GeomajasConstant.CLASSPATH_URL_PREFIX); } else if (0 == pos) { // location starts with colon, use default application context part = part.substring(1); } configLocation.append(part); } } } ConfigurableWebApplicationContext applicationContext = new XmlWebApplicationContext(); // Assign the best possible id value. String id; try { String contextPath = (String) ServletContext.class.getMethod("getContextPath").invoke(servletContext); id = ObjectUtils.getDisplayString(contextPath); } catch (Exception ex) { // Servlet <= 2.4: resort to name specified in web.xml, if any. String servletContextName = servletContext.getServletContextName(); id = ObjectUtils.getDisplayString(servletContextName); } applicationContext.setId("Geomajas:" + id); applicationContext.setServletContext(servletContext); applicationContext.setConfigLocation(configLocation.toString()); applicationContext.refresh(); ApplicationContextUtil.setApplicationContext(servletContext, applicationContext); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); }