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

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


The following commit(s) were added to refs/heads/http-4.x by this push:
     new ca8d7b4afe FELIX-6618 : Check relevant registration properties for 
whiteboard services
ca8d7b4afe is described below

commit ca8d7b4afe70ba91a2f765508c17f3e64672edd3
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Wed Jul 19 14:48:09 2023 +0200

    FELIX-6618 : Check relevant registration properties for whiteboard services
---
 .../base/internal/dispatch/MultipartConfig.java    | 24 ++++++++++++++++++++++
 .../http/base/internal/runtime/AbstractInfo.java   | 18 ++++++++++++++--
 .../http/base/internal/runtime/FilterInfo.java     | 17 +++++++++++++++
 .../http/base/internal/runtime/ListenerInfo.java   | 13 ++++++++++++
 .../base/internal/runtime/PreprocessorInfo.java    | 11 ++++++++++
 .../http/base/internal/runtime/ResourceInfo.java   | 13 ++++++++++++
 .../internal/runtime/ServletContextHelperInfo.java | 12 +++++++++++
 .../http/base/internal/runtime/ServletInfo.java    | 19 +++++++++++++++++
 .../internal/runtime/WhiteboardServiceInfo.java    | 11 ++++++++++
 .../tracker/ServletContextHelperTracker.java       |  8 ++++++--
 .../tracker/WhiteboardServiceTracker.java          |  8 ++++++--
 .../base/internal/runtime/ListenerInfoTest.java    | 22 ++++++++++++++++++++
 12 files changed, 170 insertions(+), 6 deletions(-)

diff --git 
a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/MultipartConfig.java
 
b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/MultipartConfig.java
index 2c19cfe545..b6c114bd3a 100644
--- 
a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/MultipartConfig.java
+++ 
b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/MultipartConfig.java
@@ -16,6 +16,8 @@
  */
 package org.apache.felix.http.base.internal.dispatch;
 
+import java.util.Objects;
+
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 
 public final class MultipartConfig
@@ -86,4 +88,26 @@ public final class MultipartConfig
             this.multipartMaxFileCount = 50;
         }
     }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(multipartThreshold, multipartLocation, 
multipartMaxFileSize, multipartMaxRequestSize,
+                multipartMaxFileCount);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        MultipartConfig other = (MultipartConfig) obj;
+        return multipartThreshold == other.multipartThreshold
+                && Objects.equals(multipartLocation, other.multipartLocation)
+                && multipartMaxFileSize == other.multipartMaxFileSize
+                && multipartMaxRequestSize == other.multipartMaxRequestSize
+                && multipartMaxFileCount == other.multipartMaxFileCount;
+    }
 }
diff --git 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
index 630f90b4ba..40ece7f65c 100644
--- 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
+++ 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
@@ -22,6 +22,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
@@ -88,13 +89,26 @@ public abstract class AbstractInfo<T> implements 
Comparable<AbstractInfo<T>>
             }
             // Service id's can be negative. Negative id's follow the reverse 
natural ordering of integers.
             int reverseOrder = ( this.serviceId >= 0 && other.serviceId >= 0 ) 
? 1 : -1;
-            return reverseOrder * new 
Long(this.serviceId).compareTo(other.serviceId);
+            return reverseOrder * 
Long.valueOf(this.serviceId).compareTo(other.serviceId);
         }
 
-        int result = new Integer(other.ranking).compareTo(this.ranking);
+        int result = Integer.valueOf(other.ranking).compareTo(this.ranking);
         return result;
     }
 
+    /**
+     * Compare two info objects 
+     */
+    public boolean isSame(final AbstractInfo<T> other) {
+        if (this.serviceId != other.serviceId) {
+            return false;
+        }
+        if (this.ranking != other.ranking) {
+            return false;
+        }
+        return Objects.equals(this.target, other.target);
+    }
+
     protected boolean isEmpty(final String value)
     {
         return value == null || value.length() == 0;
diff --git 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/FilterInfo.java
 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/FilterInfo.java
index d08dbc0677..3e9b110e86 100644
--- 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/FilterInfo.java
+++ 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/FilterInfo.java
@@ -18,7 +18,9 @@
  */
 package org.apache.felix.http.base.internal.runtime;
 
+import java.util.Arrays;
 import java.util.Map;
+import java.util.Objects;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 
@@ -202,4 +204,19 @@ public final class FilterInfo extends 
WhiteboardServiceInfo<Filter>
     {
         return initParams;
     }
+
+    @Override
+    public boolean isSame(AbstractInfo<Filter> other) {
+        if (!super.isSame(other)) {
+            return false;
+        }
+        final FilterInfo o = (FilterInfo) other;
+        return Objects.equals(this.name, o.name)
+            && Arrays.equals(this.patterns, o.patterns)
+            && Arrays.equals(this.servletNames, o.servletNames)
+            && Arrays.equals(this.regexs, o.regexs)
+            && this.asyncSupported == o.asyncSupported
+            && Arrays.equals(this.dispatcher, o.dispatcher)
+            && Objects.equals(this.initParams, o.initParams);
+    }
 }
diff --git 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java
 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java
index 7611f487cc..bca5bdfe3a 100644
--- 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java
+++ 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.http.base.internal.runtime;
 
+import java.util.Arrays;
 import java.util.EventListener;
 import java.util.HashSet;
 import java.util.Set;
@@ -98,4 +99,16 @@ public class ListenerInfo extends 
WhiteboardServiceInfo<EventListener>
         }
         return false;
     }
+
+    @Override
+    public boolean isSame(AbstractInfo<EventListener> other) {
+        if (!super.isSame(other)) {
+            return false;
+        }
+        final ListenerInfo o = (ListenerInfo) other;
+        if (!Arrays.deepEquals(this.types, o.types)) {
+            return false;
+        }
+        return this.enabled == o.enabled;
+    }
 }
diff --git 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/PreprocessorInfo.java
 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/PreprocessorInfo.java
index 158eb0d4c8..3f1086de9d 100644
--- 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/PreprocessorInfo.java
+++ 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/PreprocessorInfo.java
@@ -19,6 +19,8 @@
 package org.apache.felix.http.base.internal.runtime;
 
 import java.util.Map;
+import java.util.Objects;
+
 
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
@@ -51,4 +53,13 @@ public final class PreprocessorInfo extends 
WhiteboardServiceInfo<Preprocessor>
     {
         return initParams;
     }
+
+    @Override
+    public boolean isSame(AbstractInfo<Preprocessor> other) {
+        if (!super.isSame(other)) {
+            return false;
+        }
+        final PreprocessorInfo o = (PreprocessorInfo) other;
+        return Objects.equals(this.initParams, o.initParams);
+    }
 }
diff --git 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ResourceInfo.java
 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ResourceInfo.java
index abd07d9ab0..38e83b4eb6 100644
--- 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ResourceInfo.java
+++ 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ResourceInfo.java
@@ -18,6 +18,9 @@
  */
 package org.apache.felix.http.base.internal.runtime;
 
+import java.util.Arrays;
+import java.util.Objects;
+
 import org.apache.felix.http.base.internal.util.PatternUtil;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
@@ -86,4 +89,14 @@ public final class ResourceInfo extends 
WhiteboardServiceInfo<Object>
     {
         return this.servletInfo;
     }
+
+    @Override
+    public boolean isSame(AbstractInfo<Object> other) {
+        if (!super.isSame(other)) {
+            return false;
+        }
+        final ResourceInfo o = (ResourceInfo) other;
+        return Arrays.equals(this.patterns, o.patterns)
+            && Objects.equals(this.prefix, o.prefix);
+    }
 }
diff --git 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextHelperInfo.java
 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextHelperInfo.java
index 6d0de3eea2..174d61ec66 100644
--- 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextHelperInfo.java
+++ 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextHelperInfo.java
@@ -20,6 +20,7 @@ package org.apache.felix.http.base.internal.runtime;
 
 import java.util.Collections;
 import java.util.Map;
+import java.util.Objects;
 
 import org.apache.felix.http.base.internal.service.HttpServiceFactory;
 import org.apache.felix.http.base.internal.util.PatternUtil;
@@ -106,4 +107,15 @@ public final class ServletContextHelperInfo extends 
AbstractInfo<ServletContextH
     {
         return initParams;
     }
+
+    @Override
+    public boolean isSame(AbstractInfo<ServletContextHelper> other) {
+        if (!super.isSame(other)) {
+            return false;
+        }
+        final ServletContextHelperInfo o = (ServletContextHelperInfo) other;
+        return Objects.equals(this.name, o.name)
+            && Objects.equals(this.path, o.path)
+            && Objects.equals(this.initParams, o.initParams);
+    }
 }
diff --git 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
index ae1114b7cf..ceeb06f1f6 100644
--- 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
+++ 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
@@ -18,8 +18,10 @@
  */
 package org.apache.felix.http.base.internal.runtime;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Map;
+import java.util.Objects;
 
 import javax.servlet.Servlet;
 
@@ -253,4 +255,21 @@ public class ServletInfo extends 
WhiteboardServiceInfo<Servlet>
     {
         return multipartConfig;
     }
+
+
+    @Override
+    public boolean isSame(AbstractInfo<Servlet> other) {
+        if (!super.isSame(other)) {
+            return false;
+        }
+        final ServletInfo o = (ServletInfo) other;
+        return Objects.equals(this.name, o.name)
+            && Arrays.equals(this.patterns, o.patterns)
+            && Arrays.equals(this.errorPage, o.errorPage)
+            && this.asyncSupported == o.asyncSupported
+            && this.isResource == o.isResource
+            && Objects.equals(this.multipartConfig, o.multipartConfig)
+            && Objects.equals(this.prefix, o.prefix)
+            && Objects.equals(this.initParams, o.initParams);
+    }
 }
diff --git 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceInfo.java
 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceInfo.java
index 990b8ddc44..f92d12a95a 100644
--- 
a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceInfo.java
+++ 
b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceInfo.java
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.http.base.internal.runtime;
 
+import java.util.Objects;
+
 import org.apache.felix.http.base.internal.util.InternalIdFactory;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -99,4 +101,13 @@ public abstract class WhiteboardServiceInfo<T> extends 
AbstractInfo<T>
     {
         return this.filter;
     }
+
+    @Override
+    public boolean isSame(AbstractInfo<T> other) {
+        if (!super.isSame(other)) {
+            return false;
+        }
+        final WhiteboardServiceInfo<T> o = (WhiteboardServiceInfo<T>) other;
+        return Objects.equals(this.contextSelection, o.contextSelection);
+    }
 }
diff --git 
a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextHelperTracker.java
 
b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextHelperTracker.java
index 913c46f5f9..35ab7a737d 100644
--- 
a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextHelperTracker.java
+++ 
b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextHelperTracker.java
@@ -76,8 +76,12 @@ public final class ServletContextHelperTracker extends 
ServiceTracker<ServletCon
     @Override
     public final void modifiedService(@NotNull final 
ServiceReference<ServletContextHelper> ref, @NotNull final 
ServiceReference<ServletContextHelper> service)
     {
-        this.removed(ref);
-        this.added(ref);
+        final ServletContextHelperInfo newInfo = new 
ServletContextHelperInfo(ref);
+        final ServletContextHelperInfo oldInfo = 
this.allInfos.get(ref.getProperty(Constants.SERVICE_ID));
+        if (oldInfo == null || !newInfo.isSame(oldInfo)) {
+            this.removed(ref);
+            this.added(ref);
+        }
     }
 
     @Override
diff --git 
a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/WhiteboardServiceTracker.java
 
b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/WhiteboardServiceTracker.java
index d673d2312b..0f129693a3 100644
--- 
a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/WhiteboardServiceTracker.java
+++ 
b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/WhiteboardServiceTracker.java
@@ -94,8 +94,12 @@ public abstract class WhiteboardServiceTracker<T> extends 
ServiceTracker<T, Serv
 
     private void modified(final ServiceReference<T> ref)
     {
-        removed(ref);
-        added(ref);
+        final WhiteboardServiceInfo<T> newInfo = this.getServiceInfo(ref);
+        final WhiteboardServiceInfo<T> oldInfo = 
this.allInfos.get(ref.getProperty(Constants.SERVICE_ID));
+        if (oldInfo == null || !newInfo.isSame(oldInfo)) {
+            removed(ref);
+            added(ref);
+        }
     }
 
     private void added(final ServiceReference<T> ref)
diff --git 
a/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/ListenerInfoTest.java
 
b/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/ListenerInfoTest.java
index 51edb747eb..61a0bd50eb 100755
--- 
a/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/ListenerInfoTest.java
+++ 
b/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/ListenerInfoTest.java
@@ -73,4 +73,26 @@ public class ListenerInfoTest
         
when(ref.getProperty(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER)).thenReturn(Boolean.FALSE);
         assertFalse(new ListenerInfo(ref).isValid());
     }
+
+    @Test
+    public void testIsSame() {
+        final ServiceReference<EventListener> refOld = 
mock(ServiceReference.class);
+        when(refOld.getProperty(Constants.SERVICE_ID)).thenReturn(1L);
+        when(refOld.getProperty(Constants.OBJECTCLASS))
+                .thenReturn(new String[] { 
ServletContextListener.class.getName() });
+
+        final ServiceReference<EventListener> refNew = 
mock(ServiceReference.class);
+        when(refNew.getProperty(Constants.SERVICE_ID)).thenReturn(1L);
+        when(refNew.getProperty(Constants.OBJECTCLASS))
+                .thenReturn(new String[] { 
ServletContextListener.class.getName() });
+        when(refNew.getProperty("foo")).thenReturn("bar");
+
+        assertTrue(new ListenerInfo(refNew).isSame(new ListenerInfo(refOld)));
+        assertTrue(new ListenerInfo(refOld).isSame(new ListenerInfo(refNew)));
+
+        when(refNew.getProperty(Constants.SERVICE_RANKING)).thenReturn(1);
+
+        assertFalse(new ListenerInfo(refNew).isSame(new ListenerInfo(refOld)));
+        assertFalse(new ListenerInfo(refOld).isSame(new ListenerInfo(refNew)));
+    }
 }

Reply via email to