下面列出了javax.servlet.ServletContext#getServletContextName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
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;
}
/**
* 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);
}
}
}
/**
* @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 + '\'');
}
/**
* 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;
}
/**
* 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);
}
}
}
/**
* @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 + '\'');
}
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();
}
}
@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);
}
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;
}
}
@Override
public String getServletContextName(ServletContext context) {
return context.getServletContextName();
}
@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);
}