List of usage examples for javax.servlet ServletContext getMajorVersion
public int getMajorVersion();
From source file:org.openflamingo.web.util.VersionConfigurer.java
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { Log4jWebConfigurer.initLogging(servletContextEvent.getServletContext()); Properties properties = new Properties(); ServletContext context = servletContextEvent.getServletContext(); InputStream inputStream = null; try {//w ww . j av a 2 s.c o m inputStream = context.getResourceAsStream("/WEB-INF/version.properties"); properties.load(inputStream); } catch (Exception ex) { throw new IllegalArgumentException("Cannot load a '/WEB/INF/version.properties' file.", ex); } finally { IOUtils.closeQuietly(inputStream); } StringBuilder builder = new StringBuilder(); printHeader(builder, "Application Information"); Properties appProps = new Properties(); appProps.put("Application", "Flamingo Workflow Engine"); appProps.put("Version", properties.get("version")); appProps.put("Build Date", properties.get("build.timestamp")); appProps.put("Build Number", properties.get("build.number")); appProps.put("Revision Number", properties.get("revision.number")); appProps.put("Build Key", properties.get("build.key")); if (context != null) { appProps.put("Application Server", context.getServerInfo() + " - Servlet API " + context.getMajorVersion() + "." + context.getMinorVersion()); } Properties systemProperties = System.getProperties(); appProps.put("Java Version", systemProperties.getProperty("java.version", UNKNOWN) + " - " + systemProperties.getProperty("java.vendor", UNKNOWN)); appProps.put("Current Working Directory", systemProperties.getProperty("user.dir", UNKNOWN)); print(builder, appProps); Properties memPros = new Properties(); final Runtime rt = Runtime.getRuntime(); final long maxMemory = rt.maxMemory() / MEGA_BYTES; final long totalMemory = rt.totalMemory() / MEGA_BYTES; final long freeMemory = rt.freeMemory() / MEGA_BYTES; final long usedMemory = totalMemory - freeMemory; memPros.put("Maximum Allowable Memory", maxMemory + "MB"); memPros.put("Total Memory", totalMemory + "MB"); memPros.put("Free Memory", freeMemory + "MB"); memPros.put("Used Memory", usedMemory + "MB"); print(builder, memPros); printHeader(builder, "Java System Properties"); Properties sysProps = new Properties(); for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) { sysProps.put(entry.getKey(), entry.getValue()); } print(builder, sysProps); printHeader(builder, "System Environments"); Map<String, String> getenv = System.getenv(); Properties envProps = new Properties(); Set<String> strings = getenv.keySet(); for (String key : strings) { String message = getenv.get(key); envProps.put(key, message); } print(builder, envProps); logger.info("================================================="); logger.info(" Flamingo Web Services starting..."); logger.info("=================================================\n{}", builder.toString()); }
From source file:org.rhq.helpers.rtfilter.util.ServletUtility.java
/** * Get the context root for the specified servlet context. * * @param servletContext// ww w . j av a2 s . co m * * @return */ public static String getContextRoot(ServletContext servletContext) { String ctxName; /* * Get the servlet context. If we have servlet spec >=2.5, then there is a method on the servlet context for it. * Else we need to do some heuristics (which may be wrong at the end). */ int major = servletContext.getMajorVersion(); int minor = servletContext.getMinorVersion(); if (((major == 2) && (minor >= 5)) || (major >= 3)) { ctxName = getContextRootFromSpec25(servletContext); } else { // First we check if the context-root was explicitly given in jboss-web.xml ctxName = getContextRootFromJbossWebXml(servletContext); // Still nothing? try application.xml if (ctxName == null) { ctxName = getContextRootFromApplicationXml(servletContext); } // if all else fails, take the name of the .war if (ctxName == null) { ctxName = getContextRootFromWarFileName(servletContext); } if ((ctxName == null) || "".equals(ctxName)) { ctxName = "__unknown"; } } // Actually the context might always start with / even on Win* so on Unix this is / or /, // but this does not harm if (ctxName.startsWith(SEPARATOR) || ctxName.startsWith("/")) { ctxName = ctxName.substring(1); } return ctxName; }