You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2021/12/30 06:06:42 UTC

[felix-dev] branch master updated: FELIX-6492 : Remove usage of deprecated Jetty api

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new 58a3146  FELIX-6492 : Remove usage of deprecated Jetty api
58a3146 is described below

commit 58a3146ff214c8244fc87c1ede3b3de4bee1e08c
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Dec 30 07:06:17 2021 +0100

    FELIX-6492 : Remove usage of deprecated Jetty api
---
 http/jetty/pom.xml                                 |  1 +
 .../jetty/internal/ConfigMetaTypeProvider.java     | 14 ------
 .../felix/http/jetty/internal/FileRequestLog.java  | 31 +++++-------
 .../felix/http/jetty/internal/JettyConfig.java     | 56 ----------------------
 .../felix/http/jetty/internal/JettyService.java    |  2 -
 .../http/jetty/internal/LogServiceRequestLog.java  | 26 ++++------
 .../http/jetty/internal/RequestLogTracker.java     |  2 +-
 7 files changed, 24 insertions(+), 108 deletions(-)

diff --git a/http/jetty/pom.xml b/http/jetty/pom.xml
index 3dcccac..d9e97d5 100644
--- a/http/jetty/pom.xml
+++ b/http/jetty/pom.xml
@@ -142,6 +142,7 @@
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
+                <version>5.1.3</version>
                 <extensions>true</extensions>
                 <configuration>
                     <instructions>
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java
index 809e955..4fd5687 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java
@@ -20,7 +20,6 @@ package org.apache.felix.http.jetty.internal;
 
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.zip.Deflater;
 
 import org.apache.felix.http.base.internal.HttpConfig;
 import org.eclipse.jetty.server.handler.gzip.GzipHandler;
@@ -341,11 +340,6 @@ class ConfigMetaTypeProvider implements MetaTypeProvider
                 String.format("The minimum response size to trigger dynamic compression. Default is %d.", GzipHandler.DEFAULT_MIN_GZIP_SIZE),
                 GzipHandler.DEFAULT_MIN_GZIP_SIZE,
                 bundle.getBundleContext().getProperty(JettyConfig.FELIX_JETTY_GZIP_MIN_GZIP_SIZE)));
-        adList.add(new AttributeDefinitionImpl(JettyConfig.FELIX_JETTY_GZIP_COMPRESSION_LEVEL,
-                "Gzip Compression Level",
-                String.format("The compression level to use. Default is %d.", Deflater.DEFAULT_COMPRESSION),
-                Deflater.DEFAULT_COMPRESSION,
-                bundle.getBundleContext().getProperty(JettyConfig.FELIX_JETTY_GZIP_COMPRESSION_LEVEL)));
         adList.add(new AttributeDefinitionImpl(JettyConfig.FELIX_JETTY_GZIP_INFLATE_BUFFER_SIZE,
                 "Gzip Inflate Buffer Size",
                 "The size in bytes of the buffer to inflate compressed request, or <= 0 for no inflation. Default is -1.",
@@ -356,14 +350,6 @@ class ConfigMetaTypeProvider implements MetaTypeProvider
                 "True if Deflater#SYNC_FLUSH should be used, else Deflater#NO_FLUSH will be used. Default is false.",
                 false,
                 bundle.getBundleContext().getProperty(JettyConfig.FELIX_JETTY_GZIP_SYNC_FLUSH)));
-        adList.add(new AttributeDefinitionImpl(JettyConfig.FELIX_JETTY_GZIP_EXCLUDED_USER_AGENT,
-                "Gzip Exclude User Agents",
-                "The regular expressions matching additional user agents to exclude. Default is none.",
-                AttributeDefinition.STRING,
-                null,
-                2147483647,
-                null, null,
-                getStringArray(bundle.getBundleContext().getProperty(JettyConfig.FELIX_JETTY_GZIP_EXCLUDED_USER_AGENT))));
         adList.add(new AttributeDefinitionImpl(JettyConfig.FELIX_JETTY_GZIP_INCLUDED_METHODS,
                 "Gzip Include Methods",
                 "The additional http methods to include in compression. Default is none.",
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/FileRequestLog.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/FileRequestLog.java
index e0cf04a..fbb4854 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/FileRequestLog.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/FileRequestLog.java
@@ -24,9 +24,10 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 
 import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.eclipse.jetty.server.AsyncNCSARequestLog;
-import org.eclipse.jetty.server.NCSARequestLog;
+import org.eclipse.jetty.server.AsyncRequestLogWriter;
+import org.eclipse.jetty.server.CustomRequestLog;
 import org.eclipse.jetty.server.RequestLog;
+import org.eclipse.jetty.server.RequestLogWriter;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 
@@ -36,34 +37,26 @@ class FileRequestLog {
     public static final String DEFAULT_NAME = "file";
     public static final String SVC_PROP_FILEPATH = "filepath";
 
-    private final NCSARequestLog delegate;
+    private final CustomRequestLog delegate;
     private final String logFilePath;
     private final String serviceName;
-    private ServiceRegistration<RequestLog> registration = null;
+    private volatile ServiceRegistration<RequestLog> registration;
 
     FileRequestLog(JettyConfig config) {
         logFilePath = config.getRequestLogFilePath();
         serviceName = config.getRequestLogFileServiceName() != null ? config.getRequestLogFileServiceName() : DEFAULT_NAME;
+        final RequestLogWriter writer;
         if (config.isRequestLogFileAsync()) {
-            delegate = new AsyncNCSARequestLog(logFilePath, null);
+            writer = new AsyncRequestLogWriter(logFilePath);
         } else {
-            delegate = new NCSARequestLog(logFilePath);
+            writer = new RequestLogWriter(logFilePath);
         }
+        writer.setAppend(config.isRequestLogFileAppend());
+        writer.setRetainDays(config.getRequestLogFileRetainDays());
+        writer.setFilenameDateFormat(config.getRequestLogFilenameDateFormat());
 
-        delegate.setAppend(config.isRequestLogFileAppend());
-        delegate.setRetainDays(config.getRequestLogFileRetainDays());
-        delegate.setFilenameDateFormat(config.getRequestLogFilenameDateFormat());
-        delegate.setExtended(config.isRequestLogFileExtended());
+        delegate = new CustomRequestLog(writer, CustomRequestLog.EXTENDED_NCSA_FORMAT);
         delegate.setIgnorePaths(config.getRequestLogFileIgnorePaths());
-        delegate.setLogCookies(config.isRequestLogFileLogCookies());
-        delegate.setLogServer(config.isRequestLogFileLogServer());
-        delegate.setLogLatency(config.isRequestLogFileLogLatency());
-        if (config.getRequestLogDateFormat() != null) {
-            delegate.setLogDateFormat(config.getRequestLogDateFormat());
-        }
-        if (config.getRequestLogTimeZone() != null) {
-            delegate.setLogTimeZone(config.getRequestLogTimeZone());
-        }
     }
 
     synchronized void start(BundleContext context) throws IOException, IllegalStateException {
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
index 1f5cf44..3588039 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
@@ -201,27 +201,9 @@ public final class JettyConfig
     /** Felix specific property to specify the date format in request log file names */
     public static final String FELIX_HTTP_REQUEST_LOG_FILE_FILENAME_DATE_FORMAT = "org.apache.felix.http.requestlog.file.dateformat";
 
-    /** Felix specific property to enable extended request logging to a named file */
-    public static final String FELIX_HTTP_REQUEST_LOG_FILE_EXTENDED = "org.apache.felix.http.requestlog.file.extended";
-
     /** Felix specific property to ignore matching paths in the request log file */
     public static final String FELIX_HTTP_REQUEST_LOG_FILE_IGNORE_PATHS = "org.apache.felix.http.requestlog.file.ignorepaths";
 
-    /** Felix specific property to enable request logging cookies in the request log file*/
-    public static final String FELIX_HTTP_REQUEST_LOG_FILE_LOG_COOKIES = "org.apache.felix.http.requestlog.file.logcookies";
-
-    /** Felix specific property to enable request logging the host name in the request log file*/
-    public static final String FELIX_HTTP_REQUEST_LOG_FILE_LOG_SERVER = "org.apache.felix.http.requestlog.file.logserver";
-
-    /** Felix specific property to enable request logging request processing time in the request log file*/
-    public static final String FELIX_HTTP_REQUEST_LOG_FILE_LOG_LATENCY = "org.apache.felix.http.requestlog.file.loglatency";
-
-    /** Felix specific property to specify the date format used for the logging timestamps*/
-    public static final String FELIX_HTTP_REQUEST_LOG_FILE_DATE_FORMAT = "org.apache.felix.http.requestlog.file.logdateformat";
-
-    /** Felix specific property to specify the timezone used for the logging timestamps*/
-    public static final String FELIX_HTTP_REQUEST_LOG_FILE_TIMEZONE = "org.apache.felix.http.requestlog.file.timezone";
-
     /** Felix specific property to define custom properties for the http runtime service. */
     public static final String FELIX_CUSTOM_HTTP_RUNTIME_PROPERTY_PREFIX = "org.apache.felix.http.runtime.init.";
 
@@ -234,18 +216,12 @@ public final class JettyConfig
     /** Felix specific property to specify the minimum response size to trigger dynamic compression */
     public static final String FELIX_JETTY_GZIP_MIN_GZIP_SIZE = "org.apache.felix.jetty.gzip.minGzipSize";
 
-    /** Felix specific property to specify the compression level to use to initialize {@link Deflater#setLevel(int)} */
-    public static final String FELIX_JETTY_GZIP_COMPRESSION_LEVEL = "org.apache.felix.jetty.gzip.compressionLevel";
-
     /** Felix specific property to specify the size in bytes of the buffer to inflate compressed request, or 0 for no inflation. */
     public static final String FELIX_JETTY_GZIP_INFLATE_BUFFER_SIZE = "org.apache.felix.jetty.gzip.inflateBufferSize";
 
     /** Felix specific property to specify the {@link Deflater} flush mode to use. */
     public static final String FELIX_JETTY_GZIP_SYNC_FLUSH = "org.apache.felix.jetty.gzip.syncFlush";
 
-    /** Felix specific property to specify the regular expressions matching user agents to exclude */
-    public static final String FELIX_JETTY_GZIP_EXCLUDED_USER_AGENT = "org.apache.felix.jetty.gzip.excludedUserAgents";
-
     /** Felix specific property to specify the methods to include in compression */
     public static final String FELIX_JETTY_GZIP_INCLUDED_METHODS = "org.apache.felix.jetty.gzip.includedMethods";
 
@@ -631,34 +607,10 @@ public final class JettyConfig
         return getProperty(FELIX_HTTP_REQUEST_LOG_FILE_FILENAME_DATE_FORMAT, null);
     }
 
-    public boolean isRequestLogFileExtended() {
-        return getBooleanProperty(FELIX_HTTP_REQUEST_LOG_FILE_EXTENDED, false);
-    }
-
     public String[] getRequestLogFileIgnorePaths() {
         return getStringArrayProperty(FELIX_HTTP_REQUEST_LOG_FILE_IGNORE_PATHS, new String[0]);
     }
 
-    public boolean isRequestLogFileLogCookies() {
-        return getBooleanProperty(FELIX_HTTP_REQUEST_LOG_FILE_LOG_COOKIES, false);
-    }
-
-    public boolean isRequestLogFileLogServer() {
-        return getBooleanProperty(FELIX_HTTP_REQUEST_LOG_FILE_LOG_SERVER, false);
-    }
-
-    public boolean isRequestLogFileLogLatency() {
-        return getBooleanProperty(FELIX_HTTP_REQUEST_LOG_FILE_LOG_LATENCY, false);
-    }
-
-    public String getRequestLogDateFormat() {
-        return getProperty(FELIX_HTTP_REQUEST_LOG_FILE_DATE_FORMAT, null);
-    }
-
-    public String getRequestLogTimeZone() {
-        return getProperty(FELIX_HTTP_REQUEST_LOG_FILE_TIMEZONE, null);
-    }
-
     public boolean isStatisticsHandlerEnabled() {
         return getBooleanProperty(FELIX_JETTY_STATISTICS_HANDLER_ENABLE, false);
     }
@@ -671,10 +623,6 @@ public final class JettyConfig
         return getIntProperty(FELIX_JETTY_GZIP_MIN_GZIP_SIZE, GzipHandler.DEFAULT_MIN_GZIP_SIZE);
     }
 
-    public int getGzipCompressionLevel() {
-        return getIntProperty(FELIX_JETTY_GZIP_COMPRESSION_LEVEL, Deflater.DEFAULT_COMPRESSION);
-    }
-
     public int getGzipInflateBufferSize() {
         return getIntProperty(FELIX_JETTY_GZIP_INFLATE_BUFFER_SIZE, -1);
     }
@@ -683,10 +631,6 @@ public final class JettyConfig
         return getBooleanProperty(FELIX_JETTY_GZIP_SYNC_FLUSH, false);
     }
 
-    public String[] getGzipExcludedUserAgent() {
-        return getStringArrayProperty(FELIX_JETTY_GZIP_EXCLUDED_USER_AGENT, new String[0]);
-    }
-
     public String[] getGzipIncludedMethods() {
         return getStringArrayProperty(FELIX_JETTY_GZIP_INCLUDED_METHODS, new String[0]);
     }
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
index d887ef3..d25fe6e 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
@@ -310,10 +310,8 @@ public final class JettyService extends AbstractLifeCycle.AbstractLifeCycleListe
             {
             	GzipHandler gzipHandler = new GzipHandler();
             	gzipHandler.setMinGzipSize(this.config.getGzipMinGzipSize());
-            	gzipHandler.setCompressionLevel(this.config.getGzipCompressionLevel());
             	gzipHandler.setInflateBufferSize(this.config.getGzipInflateBufferSize());
             	gzipHandler.setSyncFlush(this.config.isGzipSyncFlush());
-            	gzipHandler.addExcludedAgentPatterns(this.config.getGzipExcludedUserAgent());
             	gzipHandler.addIncludedMethods(this.config.getGzipIncludedMethods());
             	gzipHandler.addExcludedMethods(this.config.getGzipExcludedMethods());
             	gzipHandler.addIncludedPaths(this.config.getGzipIncludedPaths());
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/LogServiceRequestLog.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/LogServiceRequestLog.java
index 05df9c5..15078ef 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/LogServiceRequestLog.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/LogServiceRequestLog.java
@@ -21,16 +21,15 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 
 import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.eclipse.jetty.server.AbstractNCSARequestLog;
+import org.eclipse.jetty.server.CustomRequestLog;
 import org.eclipse.jetty.server.RequestLog;
-import org.eclipse.jetty.server.RequestLogWriter;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 
 /**
  * A RequestLog that logs to the OSGi LogService when present. Not registered by default.
  */
-class LogServiceRequestLog extends AbstractNCSARequestLog {
+class LogServiceRequestLog extends CustomRequestLog {
 
     public static final String SVC_PROP_NAME = "name";
     public static final String DEFAULT_NAME = "osgi";
@@ -38,10 +37,16 @@ class LogServiceRequestLog extends AbstractNCSARequestLog {
 
     private final String serviceName;
 
-    private ServiceRegistration<RequestLog> registration;
+    private volatile ServiceRegistration<RequestLog> registration;
 
     LogServiceRequestLog(JettyConfig config) {
-        super(new RequestLogWriter());
+        super(new RequestLog.Writer() {
+
+                @Override
+                public void write(String requestEntry) throws IOException {
+                    SystemLogger.info(PREFIX.concat(requestEntry));
+                }
+            }, CustomRequestLog.NCSA_FORMAT);
         this.serviceName = config.getRequestLogOSGiServiceName();
     }
 
@@ -63,15 +68,4 @@ class LogServiceRequestLog extends AbstractNCSARequestLog {
             registration = null;
         }
     }
-
-    @Override
-    public void write(String s) throws IOException {
-        SystemLogger.info(PREFIX + s);
-    }
-
-    @Override
-    protected boolean isEnabled() {
-        return true;
-    }
-
 }
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/RequestLogTracker.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/RequestLogTracker.java
index 6b15881..ba93584 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/RequestLogTracker.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/RequestLogTracker.java
@@ -44,7 +44,7 @@ import org.osgi.util.tracker.ServiceTracker;
  */
 class RequestLogTracker extends ServiceTracker<RequestLog, RequestLog>  implements RequestLog {
 
-    private static final int MAX_ERROR_COUNT = 100;
+    public static final int MAX_ERROR_COUNT = 100;
 
     private final ConcurrentMap<ServiceReference<?>, RequestLog> logSvcs = new ConcurrentHashMap<>();
     private final ConcurrentMap<ServiceReference<?>, Integer> naughtyStep = new ConcurrentHashMap<>();