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 5c1188f2a9 FELIX-6618 : Check relevant registration properties for
whiteboard services
5c1188f2a9 is described below
commit 5c1188f2a925ae7e34f798077f0a42e96baf2095
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Wed Jul 19 15:16:17 2023 +0200
FELIX-6618 : Check relevant registration properties for whiteboard services
---
.../base/internal/dispatch/MultipartConfig.java | 24 ++++++++++++++++++++++
.../http/base/internal/runtime/AbstractInfo.java | 14 +++++++++++++
.../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 | 18 ++++++++++++++++
.../internal/runtime/WhiteboardServiceInfo.java | 12 +++++++++++
.../tracker/JavaxServletContextHelperTracker.java | 8 ++++++--
.../tracker/ServletContextHelperTracker.java | 8 ++++++--
.../tracker/WhiteboardServiceTracker.java | 8 ++++++--
.../base/internal/runtime/ListenerInfoTest.java | 22 ++++++++++++++++++++
13 files changed, 174 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 ec9f7cdf9d..cfa29d389b 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.apache.felix.http.base.internal.util.ServiceUtils;
import org.jetbrains.annotations.NotNull;
@@ -98,6 +99,19 @@ public abstract class AbstractInfo<T> implements
Comparable<AbstractInfo<T>>
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 f6fd606014..c74ff95edb 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;
@@ -225,4 +227,19 @@ public class FilterInfo extends
WhiteboardServiceInfo<Filter>
}
return filter.getClass().getName();
}
+
+ @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 61c1bb74bd..eb34ec62a4 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
@@ -20,6 +20,7 @@ package org.apache.felix.http.base.internal.runtime;
import java.util.EventListener;
import java.util.HashSet;
+import java.util.Objects;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
@@ -141,4 +142,16 @@ public class ListenerInfo extends
WhiteboardServiceInfo<EventListener>
public @NotNull String getType() {
return "Listener";
}
+
+ @Override
+ public boolean isSame(AbstractInfo<EventListener> other) {
+ if (!super.isSame(other)) {
+ return false;
+ }
+ final ListenerInfo o = (ListenerInfo) other;
+ if (!Objects.equals(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 51b7e8f7f6..531ec280a0 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,7 @@
package org.apache.felix.http.base.internal.runtime;
import java.util.Map;
+import java.util.Objects;
import org.apache.felix.http.base.internal.jakartawrappers.PreprocessorWrapper;
import org.jetbrains.annotations.NotNull;
@@ -71,4 +72,14 @@ public class PreprocessorInfo extends
WhiteboardServiceInfo<Preprocessor>
}
return preprocessor.getClass().getName();
}
+
+
+ @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 2d10da8ad3..ebabdf0e74 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.jetbrains.annotations.NotNull;
import org.osgi.framework.ServiceReference;
@@ -91,4 +94,14 @@ public final class ResourceInfo extends
WhiteboardServiceInfo<Object>
public @NotNull String getType() {
return "Resource";
}
+
+ @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 c04c505948..5a7b068fec 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
@@ -21,6 +21,7 @@ package org.apache.felix.http.base.internal.runtime;
import java.util.Collections;
import java.util.HashMap;
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;
@@ -133,4 +134,15 @@ public class ServletContextHelperInfo extends
AbstractInfo<ServletContextHelper>
}
return info.getContextSelectionFilter().matches(props);
}
+
+ @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 dcdbbe6c5c..3d18f5d677 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 org.apache.felix.http.base.internal.dispatch.MultipartConfig;
import org.apache.felix.http.base.internal.jakartawrappers.ServletWrapper;
@@ -272,4 +274,20 @@ public class ServletInfo extends
WhiteboardServiceInfo<Servlet>
}
return servlet.getClass().getName();
}
+
+ @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 aff18d3f90..2da0ac6318 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,14 @@ 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/JavaxServletContextHelperTracker.java
b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/JavaxServletContextHelperTracker.java
index c209eae404..01fd03d2bf 100644
---
a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/JavaxServletContextHelperTracker.java
+++
b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/JavaxServletContextHelperTracker.java
@@ -86,8 +86,12 @@ public final class JavaxServletContextHelperTracker extends
ServiceTracker<Servl
@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/ServletContextHelperTracker.java
b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextHelperTracker.java
index 5604116409..13de9f8cb1 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
@@ -75,8 +75,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 b643b31267..d01ca4deb2 100644
---
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)));
+ }
}