diff --git a/guacamole/src/main/java/org/apache/guacamole/GuacamoleServletContainerInitializer.java b/guacamole/src/main/java/org/apache/guacamole/GuacamoleServletContainerInitializer.java new file mode 100644 index 000000000..afdbb6785 --- /dev/null +++ b/guacamole/src/main/java/org/apache/guacamole/GuacamoleServletContainerInitializer.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.guacamole; + +import java.util.Set; +import javax.servlet.ServletContainerInitializer; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import org.apache.guacamole.log.GuacamoleLogbackServiceProvider; +import org.slf4j.LoggerFactory; +import org.slf4j.helpers.Reporter; + +/** + * ServletContainerInitializer which forces the SLF4J service provider to be + * Guacamole's built-in logging system. This is necessary as Logback also + * includes an SLF4J service provider, and there is no guarantee which provider + * will be chosen by SLF4J in the case that multiple are present. + *

+ * SLF4J uses a "slf4j.provider" system property to allow a specific provider + * to be chosen, which this initializer sets automatically. + */ +public class GuacamoleServletContainerInitializer implements ServletContainerInitializer { + + @Override + public void onStartup(Set> c, ServletContext ctx) throws ServletException { + + // Ideally, we want to use Guacamole's built-in logging facility, but + // we shouldn't override the administrator if they have their own SLF4J + // provider that needs to be used instead (ie: for some log aggregation + // service) + if (System.getProperty(LoggerFactory.PROVIDER_PROPERTY_KEY) == null) { + + System.setProperty(LoggerFactory.PROVIDER_PROPERTY_KEY, + GuacamoleLogbackServiceProvider.class.getCanonicalName()); + + // Avoid excessive verbosity from SLF4J unless the administrator + // has explicitly chosen SLF4J's verbosity level (the SLF4J provider + // class will otherwise be logged at startup, which is an internal + // detail and not typically needed) + if (System.getProperty(Reporter.SLF4J_INTERNAL_VERBOSITY_KEY) == null) + System.setProperty(Reporter.SLF4J_INTERNAL_VERBOSITY_KEY, "WARN"); + + } + + } + +} diff --git a/guacamole/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer b/guacamole/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer new file mode 100644 index 000000000..11801bac0 --- /dev/null +++ b/guacamole/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +org.apache.guacamole.GuacamoleServletContainerInitializer diff --git a/guacamole/src/main/webapp/WEB-INF/web.xml b/guacamole/src/main/webapp/WEB-INF/web.xml index ba1f6115e..3b99914c1 100644 --- a/guacamole/src/main/webapp/WEB-INF/web.xml +++ b/guacamole/src/main/webapp/WEB-INF/web.xml @@ -28,6 +28,14 @@ index.html + + + logbackDisableServletContainerInitializer + true + + cacheRevalidationFilter