Java Code Examples for javax.servlet.ServletContext#getServerInfo()
The following examples show how to use
javax.servlet.ServletContext#getServerInfo() .
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: ServletVersionInstrumentation.java From apm-agent-java with Apache License 2.0 | 6 votes |
@Advice.OnMethodEnter(suppress = Throwable.class) @SuppressWarnings("Duplicates") // duplication is fine here as it allows to inline code private static void onEnter(@Advice.Argument(0) @Nullable ServletConfig servletConfig) { if (alreadyLogged) { return; } alreadyLogged = true; int majorVersion = -1; int minorVersion = -1; String serverInfo = null; if (servletConfig != null) { ServletContext servletContext = servletConfig.getServletContext(); if (null != servletContext) { majorVersion = servletContext.getMajorVersion(); minorVersion = servletContext.getMinorVersion(); serverInfo = servletContext.getServerInfo(); } } logger.info("Servlet container info = {}", serverInfo); if (majorVersion < 3) { logger.warn("Unsupported servlet version detected: {}.{}, no Servlet transaction will be created", majorVersion, minorVersion); } }
Example 2
Source File: WriteFile.java From openrasp-testcases with MIT License | 6 votes |
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String bytes = req.getParameter("filedata"); String fname = req.getParameter("filename"); if (fname == null || bytes == null) { resp.getWriter().println("<p>注意: 由于可能产生误报,所以目前官方插件不会拦截这种使用 FileOutputStream 写文件的后门,我们会尽快解决</p>"); } else { try { String path; ServletContext application = this.getServletContext(); String serverInfo = application.getServerInfo(); if (serverInfo != null && serverInfo.toLowerCase().contains("weblogic")) { path = application.getResource("/").getPath() + "/" + fname; } else { path = application.getRealPath("/") + "/" + fname; } FileOutputStream os = new FileOutputStream(path); PrintWriter writer = new PrintWriter(os); writer.print(bytes); writer.close(); resp.getWriter().println("==>" + path); } catch (Exception e) { resp.getWriter().print(e); } } }
Example 3
Source File: BootstrapContainerInitializer.java From ldp4j with Apache License 2.0 | 6 votes |
private void initializeContainer(final ServletContext context) { if(!initialized.compareAndSet(false, true)) { return; } final String serverInfo = context.getServerInfo(); final int majorVersion = context.getMajorVersion(); final int minorVersion = context.getMinorVersion(); LOGGER.debug("Starting container {} {}.{}",serverInfo,majorVersion,minorVersion); Runtime. getRuntime(). addShutdownHook( new Thread() { @Override public void run() { LOGGER.debug("Shutting down container {} {}.{}",serverInfo,majorVersion,minorVersion); } } ); }
Example 4
Source File: ServletVersionInstrumentation.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Advice.OnMethodEnter(suppress = Throwable.class) @SuppressWarnings("Duplicates") // duplication is fine here as it allows to inline code private static void onEnter(@Advice.This Servlet servlet) { if (alreadyLogged) { return; } alreadyLogged = true; ServletConfig servletConfig = servlet.getServletConfig(); int majorVersion = -1; int minorVersion = -1; String serverInfo = null; if (servletConfig != null) { ServletContext servletContext = servletConfig.getServletContext(); if (null != servletContext) { majorVersion = servletContext.getMajorVersion(); minorVersion = servletContext.getMinorVersion(); serverInfo = servletContext.getServerInfo(); } } logger.info("Servlet container info = {}", serverInfo); if (majorVersion < 3) { logger.warn("Unsupported servlet version detected: {}.{}, no Servlet transaction will be created", majorVersion, minorVersion); } }
Example 5
Source File: VersionModel.java From hbase with Apache License 2.0 | 5 votes |
/** * Constructor * @param context the servlet context */ public VersionModel(ServletContext context) { restVersion = RESTServlet.VERSION_STRING; jvmVersion = System.getProperty("java.vm.vendor") + ' ' + System.getProperty("java.version") + '-' + System.getProperty("java.vm.version"); osVersion = System.getProperty("os.name") + ' ' + System.getProperty("os.version") + ' ' + System.getProperty("os.arch"); serverVersion = context.getServerInfo(); jerseyVersion = ServletContainer.class.getPackage().getImplementationVersion(); // Currently, this will always be null because the manifest doesn't have any useful information if (jerseyVersion == null) jerseyVersion = ""; }
Example 6
Source File: CreateRestViewPipe.java From iaf with Apache License 2.0 | 5 votes |
private Map<String,Object> retrieveParameters(HttpServletRequest httpServletRequest, ServletContext servletContext, String srcPrefix) throws DomBuilderException { IbisContext ibisContext = IbisApplicationServlet.getIbisContext(servletContext); Map<String,Object> parameters = new Hashtable<String,Object>(); String requestInfoXml = "<requestInfo>" + "<servletRequest>" + "<serverInfo><![CDATA[" + servletContext.getServerInfo() + "]]></serverInfo>" + "<serverName>" + httpServletRequest.getServerName() + "</serverName>" + "</servletRequest>" + "</requestInfo>"; parameters.put("requestInfo", XmlUtils.buildNode(requestInfoXml)); parameters.put("upTime", XmlUtils.buildNode("<upTime>" + (ibisContext==null?"null":ibisContext.getUptime()) + "</upTime>")); String machineNameXml = "<machineName>" + Misc.getHostname() + "</machineName>"; parameters.put("machineName", XmlUtils.buildNode(machineNameXml)); String fileSystemXml = "<fileSystem>" + "<totalSpace>" + Misc.getFileSystemTotalSpace() + "</totalSpace>" + "<freeSpace>" + Misc.getFileSystemFreeSpace() + "</freeSpace>" + "</fileSystem>"; parameters.put("fileSystem", XmlUtils.buildNode(fileSystemXml)); String applicationConstantsXml = appConstants.toXml(true); parameters.put("applicationConstants", XmlUtils.buildNode(applicationConstantsXml)); String processMetricsXml = ProcessMetrics.toXml(); parameters.put("processMetrics", XmlUtils.buildNode(processMetricsXml)); parameters.put("menuBar", XmlUtils.buildNode(retrieveMenuBarParameter(srcPrefix))); parameters.put(SRCPREFIX, srcPrefix); return parameters; }
Example 7
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; } }