org.apache.catalina.util.ServerInfo Java Examples

The following examples show how to use org.apache.catalina.util.ServerInfo. 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: CatalinaContainer.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
public boolean start() throws ContainerException {
    // load the web applications
    loadComponents();

    // Start the Tomcat server
    try {
        tomcat.getServer().start();
    } catch (LifecycleException e) {
        throw new ContainerException(e);
    }

    for (Connector con: tomcat.getService().findConnectors()) {
        Debug.logInfo("Connector " + con.getProtocol() + " @ " + con.getPort() + " - " +
            (con.getSecure() ? "secure" : "not-secure") + " [" + con.getProtocolHandlerClassName() + "] started.", module);
    }
    Debug.logInfo("Started " + ServerInfo.getServerInfo(), module);
    return true;
}
 
Example #2
Source File: ExtendedAccessLogValve.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Open the new log file for the date specified by <code>dateStamp</code>.
 */
@Override
protected synchronized void open() {
    super.open();
    if (currentLogFile.length()==0) {
        writer.println("#Fields: " + pattern);
        writer.println("#Version: 2.0");
        writer.println("#Software: " + ServerInfo.getServerInfo());
    }
}
 
Example #3
Source File: ServerListener.java    From tomee with Apache License 2.0 5 votes vote down vote up
private synchronized void installServerInfo() {
    if (SystemInstance.get().getOptions().get("tomee.keep-server-info", false)) {
        return;
    }

    // force static init
    final String value = ServerInfo.getServerInfo();

    Field field = null;
    boolean acc = true;
    try {
        field = ServerInfo.class.getDeclaredField("serverInfo");
        acc = field.isAccessible();
        final int slash = value.indexOf('/');
        field.setAccessible(true);
        final String tomeeVersion = OpenEjbVersion.get().getVersion();
        final int modifiers = field.getModifiers();
        if (Modifier.isFinal(modifiers)) { // this is a bit fragile, we can surely drop this feature at some point
            final Field modifiersField = Field.class.getDeclaredField("modifiers");
            modifiersField.setAccessible(true);
            modifiersField.setInt(field, modifiers & ~Modifier.FINAL);
        }
        field.set(null, value.substring(0, slash) + " (TomEE)" + value.substring(slash) + " (" + tomeeVersion + ")");
    } catch (final Exception e) {
        // no-op
    } finally {
        if (field != null) {
            field.setAccessible(acc);
        }
    }
}
 
Example #4
Source File: StandardServiceModifierTest.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Test
public void startShouldCollectServerInfo() throws Exception {
    // Given
    String expectedServerInfo = ServerInfo.getServerInfo();
    // When
    service.start();
    service.stop();
    // Then
    ServerMetaData serverMetaData = getServerMetaData();
    assertEquals(expectedServerInfo, serverMetaData.getServerInfo());
}
 
Example #5
Source File: StandardServiceStartInterceptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }

    String serverInfo = ServerInfo.getServerInfo();
    ServerMetaDataHolder holder = this.traceContext.getServerMetaDataHolder();
    holder.setServerName(serverInfo);
    holder.notifyListeners();
}
 
Example #6
Source File: OpenIDConnectAuthenticator.java    From tomcat-oidcauth with Apache License 2.0 5 votes vote down vote up
@Override
protected void ensureTomcatVersion()
	throws LifecycleException {

	final Integer[] versionParts = Stream.of(ServerInfo.getServerNumber().split("\\."))
		.map(v -> Integer.parseInt(v))
		.toArray(Integer[]::new);
	if ((versionParts[0].intValue() != 8)
			|| (versionParts[1].intValue() != 5)
			|| (versionParts[2].intValue() < 50))
		throw new LifecycleException("OpenIDConnectAuthenticator requires"
			+ " Apache Tomcat 8.5 version 8.5.50 or higher.");
}
 
Example #7
Source File: OpenIDConnectAuthenticator.java    From tomcat-oidcauth with Apache License 2.0 5 votes vote down vote up
@Override
protected void ensureTomcatVersion()
	throws LifecycleException {

	final Integer[] versionParts = Stream.of(ServerInfo.getServerNumber().split("\\."))
		.map(v -> Integer.parseInt(v))
		.toArray(Integer[]::new);
	if ((versionParts[0].intValue() != 9)
			|| (versionParts[1].intValue() != 0)
			|| (versionParts[2].intValue() < 30))
		throw new LifecycleException("OpenIDConnectAuthenticator requires"
			+ " Apache Tomcat 9.0 version 9.0.30 or higher.");
}
 
Example #8
Source File: StandardEngine.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {
    
    // Log our server identification information
    if(log.isInfoEnabled())
        log.info( "Starting Servlet Engine: " + ServerInfo.getServerInfo());

    // Standard container startup
    super.startInternal();
}
 
Example #9
Source File: ExtendedAccessLogValve.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Open the new log file for the date specified by <code>dateStamp</code>.
 */
@Override
protected synchronized void open() {
    super.open();
    if (currentLogFile.length()==0) {
        writer.println("#Fields: " + pattern);
        writer.println("#Version: 2.0");
        writer.println("#Software: " + ServerInfo.getServerInfo());
    }
}
 
Example #10
Source File: ManagerServlet.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Writes System OS and JVM properties.
 * @param writer Writer to render to
 */
protected void serverinfo(PrintWriter writer,  StringManager smClient) {
    if (debug >= 1)
        log("serverinfo");
    try {
        StringBuilder props = new StringBuilder();
        props.append("OK - Server info");
        props.append("\nTomcat Version: ");
        props.append(ServerInfo.getServerInfo());
        props.append("\nOS Name: ");
        props.append(System.getProperty("os.name"));
        props.append("\nOS Version: ");
        props.append(System.getProperty("os.version"));
        props.append("\nOS Architecture: ");
        props.append(System.getProperty("os.arch"));
        props.append("\nJVM Version: ");
        props.append(System.getProperty("java.runtime.version"));
        props.append("\nJVM Vendor: ");
        props.append(System.getProperty("java.vm.vendor"));
        writer.println(props.toString());
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        getServletContext().log("ManagerServlet.serverinfo",t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }
}
 
Example #11
Source File: TomcatGenericExports.java    From tomcat_exporter with Apache License 2.0 5 votes vote down vote up
private void addVersionInfo(List<MetricFamilySamples> mfs) {
    GaugeMetricFamily tomcatInfo = new GaugeMetricFamily(
            "tomcat_info",
            "tomcat version info",
            Arrays.asList("version", "build"));
    tomcatInfo.addMetric(Arrays.asList(ServerInfo.getServerNumber(), ServerInfo.getServerBuilt()), 1);
    mfs.add(tomcatInfo);
}
 
Example #12
Source File: StandardEngine.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {
    
    // Log our server identification information
    if(log.isInfoEnabled())
        log.info( "Starting Servlet Engine: " + ServerInfo.getServerInfo());

    // Standard container startup
    super.startInternal();
}
 
Example #13
Source File: ExtendedAccessLogValve.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Open the new log file for the date specified by <code>dateStamp</code>.
 */
@Override
protected synchronized void open() {
    super.open();
    if (currentLogFile.length()==0) {
        writer.println("#Fields: " + pattern);
        writer.println("#Version: 2.0");
        writer.println("#Software: " + ServerInfo.getServerInfo());
    }
}
 
Example #14
Source File: ManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Writes System OS and JVM properties.
 * @param writer Writer to render to
 */
protected void serverinfo(PrintWriter writer,  StringManager smClient) {
    if (debug >= 1)
        log("serverinfo");
    try {
        StringBuilder props = new StringBuilder();
        props.append("OK - Server info");
        props.append("\nTomcat Version: ");
        props.append(ServerInfo.getServerInfo());
        props.append("\nOS Name: ");
        props.append(System.getProperty("os.name"));
        props.append("\nOS Version: ");
        props.append(System.getProperty("os.version"));
        props.append("\nOS Architecture: ");
        props.append(System.getProperty("os.arch"));
        props.append("\nJVM Version: ");
        props.append(System.getProperty("java.runtime.version"));
        props.append("\nJVM Vendor: ");
        props.append(System.getProperty("java.vm.vendor"));
        writer.println(props.toString());
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        getServletContext().log("ManagerServlet.serverinfo",t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }
}
 
Example #15
Source File: Bootstrap.java    From bistoury with GNU General Public License v3.0 5 votes vote down vote up
public static void log(final String webappDirLocation, final String confDir) {
    logger.info("Server webapp docBase: {}", new File("" + webappDirLocation).getAbsolutePath());
    logger.info("Server project dir:    {}", new File("").getAbsolutePath());
    logger.info("Server config dir:     {}", confDir);
    logger.info(sm.getString("versionLoggerListener.serverInfo.server.version",
            ServerInfo.getServerInfo()));
    logger.info(sm.getString("versionLoggerListener.serverInfo.server.built",
            ServerInfo.getServerBuilt()));
    logger.info(sm.getString("versionLoggerListener.serverInfo.server.number",
            ServerInfo.getServerNumber()));
    logger.info(sm.getString("versionLoggerListener.os.name",
            System.getProperty("os.name")));
    logger.info(sm.getString("versionLoggerListener.os.version",
            System.getProperty("os.version")));
    logger.info(sm.getString("versionLoggerListener.os.arch",
            System.getProperty("os.arch")));
    logger.info(sm.getString("versionLoggerListener.java.home",
            System.getProperty("java.home")));
    logger.info(sm.getString("versionLoggerListener.vm.version",
            System.getProperty("java.runtime.version")));
    logger.info(sm.getString("versionLoggerListener.vm.vendor",
            System.getProperty("java.vm.vendor")));
    logger.info(sm.getString("versionLoggerListener.catalina.base",
            System.getProperty("catalina.base")));
    logger.info(sm.getString("versionLoggerListener.catalina.home",
            System.getProperty("catalina.home")));

    //argument
    List<String> args = ManagementFactory.getRuntimeMXBean().getInputArguments();
    for (String arg : args) {
        logger.info(sm.getString("versionLoggerListener.arg", arg));
    }

    ServerManager.printServerConfig();
}
 
Example #16
Source File: Bootstrap.java    From bistoury with GNU General Public License v3.0 5 votes vote down vote up
public static void log(final String webappDirLocation, final String confDir) {
    logger.info("Server webapp docBase: {}", new File("" + webappDirLocation).getAbsolutePath());
    logger.info("Server project dir:    {}", new File("").getAbsolutePath());
    logger.info("Server config dir:     {}", confDir);
    logger.info(sm.getString("versionLoggerListener.serverInfo.server.version",
            ServerInfo.getServerInfo()));
    logger.info(sm.getString("versionLoggerListener.serverInfo.server.built",
            ServerInfo.getServerBuilt()));
    logger.info(sm.getString("versionLoggerListener.serverInfo.server.number",
            ServerInfo.getServerNumber()));
    logger.info(sm.getString("versionLoggerListener.os.name",
            System.getProperty("os.name")));
    logger.info(sm.getString("versionLoggerListener.os.version",
            System.getProperty("os.version")));
    logger.info(sm.getString("versionLoggerListener.os.arch",
            System.getProperty("os.arch")));
    logger.info(sm.getString("versionLoggerListener.java.home",
            System.getProperty("java.home")));
    logger.info(sm.getString("versionLoggerListener.vm.version",
            System.getProperty("java.runtime.version")));
    logger.info(sm.getString("versionLoggerListener.vm.vendor",
            System.getProperty("java.vm.vendor")));
    logger.info(sm.getString("versionLoggerListener.catalina.base",
            System.getProperty("catalina.base")));
    logger.info(sm.getString("versionLoggerListener.catalina.home",
            System.getProperty("catalina.home")));
    //argument
    List<String> args = ManagementFactory.getRuntimeMXBean().getInputArguments();
    for (String arg : args) {
        logger.info(sm.getString("versionLoggerListener.arg", arg));
    }

    ServerManager.printServerConfig();
}
 
Example #17
Source File: ManagerServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Writes System OS and JVM properties.
 * @param writer Writer to render to
 * @param smClient i18n support for current client's locale
*/
protected void serverinfo(PrintWriter writer,  StringManager smClient) {
    if (debug >= 1)
        log("serverinfo");
    try {
        writer.println(smClient.getString("managerServlet.serverInfo", ServerInfo.getServerInfo(),
                System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"),
                System.getProperty("java.runtime.version"), System.getProperty("java.vm.vendor")));
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        getServletContext().log("ManagerServlet.serverinfo",t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }
}
 
Example #18
Source File: StandardServer.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Report the current Tomcat Server Release number
 * @return Tomcat release identifier
 */
public String getServerInfo() {

    return ServerInfo.getServerInfo();
}
 
Example #19
Source File: TomcatGenericExportsTest.java    From tomcat_exporter with Apache License 2.0 4 votes vote down vote up
@Test
public void testTomcatInfo() throws Exception {
    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("tomcat_info", new String[]{"version", "build"}, new String[]{ServerInfo.getServerNumber(), ServerInfo.getServerBuilt()}), is(1.0));
}
 
Example #20
Source File: TestHttp2InitialConnection.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
protected String getResponseBodyFrameTrace(int streamId, String body) {
    if (testData.getExpectedStatus() == 200) {
        return super.getResponseBodyFrameTrace(streamId, body);
    } else if (testData.getExpectedStatus() == 400) {
        /*
         * Need to be careful here. The test wants the exact content length
         * in bytes.
         * This will vary depending on where the test is run due to:
         * - The length of the version string that appears once in the error
         *   page
         * - The status header uses a UTF-8 EN dash. When running in an IDE
         *   the UTF-8 properties files will be used directly rather than
         *   after native2ascii conversion.
         *
         * Note: The status header appears twice in the error page.
         */
        int serverInfoLength = ServerInfo.getServerInfo().getBytes().length;
        StringManager sm = StringManager.getManager(
                ErrorReportValve.class.getPackage().getName(), Locale.ENGLISH);
        String reason = sm.getString("http." + testData.getExpectedStatus() + ".reason");
        int descriptionLength = sm.getString("http." + testData.getExpectedStatus() + ".desc")
                .getBytes(StandardCharsets.UTF_8).length;
        int statusHeaderLength = sm
                .getString("errorReportValve.statusHeader",
                        String.valueOf(testData.getExpectedStatus()), reason)
                .getBytes(StandardCharsets.UTF_8).length;
        int typeLabelLength = sm.getString("errorReportValve.type")
                .getBytes(StandardCharsets.UTF_8).length;
        int statusReportLabelLength = sm.getString("errorReportValve.statusReport")
                .getBytes(StandardCharsets.UTF_8).length;
        int descriptionLabelLength = sm.getString("errorReportValve.description")
                .getBytes(StandardCharsets.UTF_8).length;
        // 196 bytes is the static length of the pure HTML code from the ErrorReportValve
        int len = 196 + org.apache.catalina.util.TomcatCSS.TOMCAT_CSS
                .getBytes(StandardCharsets.UTF_8).length +
                typeLabelLength + statusReportLabelLength + descriptionLabelLength +
                descriptionLength + serverInfoLength + statusHeaderLength * 2;
        String contentLength = String.valueOf(len);
        return getResponseBodyFrameTrace(streamId,
                testData.getExpectedStatus(), "text/html;charset=utf-8",
                "en", contentLength, contentLength);
    } else {
        Assert.fail();
        // To keep the IDE happy
        return null;
    }
}
 
Example #21
Source File: CheckServerInfoTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Test
public void checkServerInfo() {
    final String serverInfo = ServerInfo.getServerInfo();
    assertTrue(serverInfo, serverInfo.startsWith("Apache Tomcat"));
}
 
Example #22
Source File: ApplicationContext.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public String getServerInfo() {
    return ServerInfo.getServerInfo();
}
 
Example #23
Source File: ApplicationContext.java    From Tomcat7.0.67 with Apache License 2.0 3 votes vote down vote up
/**
 * Return the name and version of the servlet container.
 */
@Override
public String getServerInfo() {

    return (ServerInfo.getServerInfo());

}
 
Example #24
Source File: StandardEngine.java    From Tomcat8-Source-Read with MIT License 3 votes vote down vote up
/**
 1.BootStrap反射调用Catalina的start。
 * 2.Catalina去调用了StandardServer的start方法。
 * 3.StandardServer调用StandardService的start方法。
 * 4.StandardService调用StandarEngine的start方法。
 * 5.StandarEngine调用ContainerBase的start方法。(重点)
 *
 *
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 *
 *
 *
 */
@Override
protected synchronized void startInternal() throws LifecycleException {

    // Log our server identification information
    if(log.isInfoEnabled())
        log.info( "Starting Servlet Engine: " + ServerInfo.getServerInfo());

    // Standard container startup
    super.startInternal();
}
 
Example #25
Source File: ApplicationContext.java    From tomcatsrc with Apache License 2.0 3 votes vote down vote up
/**
 * Return the name and version of the servlet container.
 */
@Override
public String getServerInfo() {

    return (ServerInfo.getServerInfo());

}
 
Example #26
Source File: StandardServer.java    From tomcatsrc with Apache License 2.0 2 votes vote down vote up
/**
 * Return the current server's version number.
 * @return server's version number.
 */
public String getServerNumber() {
    return ServerInfo.getServerNumber();
}
 
Example #27
Source File: StandardServer.java    From Tomcat8-Source-Read with MIT License 2 votes vote down vote up
/**
 * Return the current server's version number.
 * @return server's version number.
 */
public String getServerNumber() {
    return ServerInfo.getServerNumber();
}
 
Example #28
Source File: StandardServer.java    From Tomcat8-Source-Read with MIT License 2 votes vote down vote up
/**
 * Return the current server built timestamp
 * @return server built timestamp.
 */
public String getServerBuilt() {
    return ServerInfo.getServerBuilt();
}
 
Example #29
Source File: StandardServer.java    From Tomcat8-Source-Read with MIT License 2 votes vote down vote up
/**
 * Report the current Tomcat Server Release number
 * @return Tomcat release identifier
 */
public String getServerInfo() {
    return ServerInfo.getServerInfo();
}
 
Example #30
Source File: StandardServer.java    From tomcatsrc with Apache License 2.0 2 votes vote down vote up
/**
 * Return the current server built timestamp
 * @return server built timestamp.
 */
public String getServerBuilt() {
    return ServerInfo.getServerBuilt();
}