Search in sources :

Example 1 with ServerInfo

use of org.apache.catalina.util.ServerInfo in project tomee by apache.

the class ServerListener method installServerInfo.

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);
        }
    }
}
Also used : Field(java.lang.reflect.Field) ServerInfo(org.apache.catalina.util.ServerInfo) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 ServerInfo (org.apache.catalina.util.ServerInfo)1