FELIX-4060 : Clarify init parameter handling and init work for getting failure dtos
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1663205 13f79535-47bb-0310-9956-ffa450edef68
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 d454ce2..9c87be4 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
@@ -19,6 +19,7 @@
package org.apache.felix.http.base.internal.runtime;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -176,7 +177,7 @@
}
}
}
- return result;
+ return Collections.unmodifiableMap(result);
}
public int getRanking()
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 4ecc318..07722c9 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,6 +18,7 @@
*/
package org.apache.felix.http.base.internal.runtime;
+import java.util.Collections;
import java.util.Map;
import javax.servlet.DispatcherType;
@@ -132,7 +133,7 @@
this.patterns = null;
this.servletNames = null;
this.regexs = new String[] {regex};
- this.initParams = initParams;
+ this.initParams = Collections.unmodifiableMap(initParams);
this.asyncSupported = false;
this.dispatcher = new DispatcherType[] {DispatcherType.REQUEST};
}
@@ -154,7 +155,7 @@
this.regexs = regexs;
this.asyncSupported = asyncSupported;
this.dispatcher = dispatcher;
- this.initParams = initParams;
+ this.initParams = Collections.unmodifiableMap(initParams);
}
@Override
@@ -193,6 +194,9 @@
return dispatcher;
}
+ /**
+ * Returns an immutable map of the init parameters.
+ */
public Map<String, String> getInitParameters()
{
return initParams;
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/RegistryRuntime.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/RegistryRuntime.java
index 8f83d67..749df65 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/RegistryRuntime.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/RegistryRuntime.java
@@ -21,7 +21,9 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import org.apache.felix.http.base.internal.whiteboard.ContextHandler;
import org.osgi.framework.ServiceReference;
@@ -31,14 +33,17 @@
private final Collection<ContextHandler> contexts;
private final Map<Long, Collection<ServiceReference<?>>> listenerRuntimes;
private final Map<Long, HandlerRuntime> handlerRuntimes;
+ private final Collection<AbstractInfo<?>> invalidServices;
- public RegistryRuntime(Collection<ContextHandler> contexts,
- Collection<HandlerRuntime> contextRuntimes,
- Map<Long, Collection<ServiceReference<?>>> listenerRuntimes)
+ public RegistryRuntime(final Collection<ContextHandler> contexts,
+ final Collection<HandlerRuntime> contextRuntimes,
+ final Map<Long, Collection<ServiceReference<?>>> listenerRuntimes,
+ final Set<AbstractInfo<?>> invalidServices)
{
this.contexts = contexts;
this.handlerRuntimes = createServiceIdMap(contextRuntimes);
this.listenerRuntimes = listenerRuntimes;
+ this.invalidServices = new HashSet<AbstractInfo<?>>(invalidServices);
}
private static Map<Long, HandlerRuntime> createServiceIdMap(Collection<HandlerRuntime> contextRuntimes)
@@ -75,4 +80,9 @@
{
return contexts;
}
+
+ public Collection<AbstractInfo<?>> getInvalidServices()
+ {
+ return this.invalidServices;
+ }
}
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 0df24f7..2d0aa11 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
@@ -18,6 +18,7 @@
*/
package org.apache.felix.http.base.internal.runtime;
+import java.util.Collections;
import java.util.Map;
import org.apache.felix.http.base.internal.util.PatternUtil;
@@ -53,6 +54,7 @@
this.initParams = getInitParams(ref, CONTEXT_INIT_PREFIX);
}
+ @SuppressWarnings("unchecked")
ServletContextHelperInfo(int serviceRanking,
long serviceId,
String name,
@@ -62,7 +64,7 @@
super(serviceRanking, serviceId);
this.name = name;
this.path = path;
- this.initParams = initParams;
+ this.initParams = initParams == null ? (Map<String, String>)Collections.EMPTY_MAP : Collections.unmodifiableMap(initParams);
}
private boolean isValidPath()
@@ -100,6 +102,10 @@
return this.path;
}
+ /**
+ * Returns an unmodifiable map of the parameters.
+ * @return
+ */
public Map<String, String> getInitParameters()
{
return 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 ec139e7..147e858 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
@@ -129,7 +129,7 @@
{
this.patterns = new String[] {pattern, pattern + "/*"};
}
- this.initParams = initParams;
+ this.initParams = Collections.unmodifiableMap(initParams);
this.asyncSupported = true;
this.errorPage = null;
this.isResource = false;
@@ -149,7 +149,7 @@
this.patterns = patterns;
this.errorPage = errorPage;
this.asyncSupported = asyncSupported;
- this.initParams = initParams;
+ this.initParams = Collections.unmodifiableMap(initParams);
this.isResource = false;
this.prefix = null;
}
@@ -180,6 +180,10 @@
return asyncSupported;
}
+ /**
+ * Returns an unmodifiable map of the init parameters.
+ * @return
+ */
public Map<String, String> getInitParameters()
{
return initParams;
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilder.java
index 7a03b83..7bc35c5 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilder.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilder.java
@@ -20,17 +20,21 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.felix.http.base.internal.handler.FilterHandler;
import org.apache.felix.http.base.internal.handler.ServletHandler;
+import org.apache.felix.http.base.internal.runtime.AbstractInfo;
import org.apache.felix.http.base.internal.runtime.HandlerRuntime;
import org.apache.felix.http.base.internal.runtime.HandlerRuntime.ErrorPage;
import org.apache.felix.http.base.internal.runtime.RegistryRuntime;
+import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
import org.apache.felix.http.base.internal.whiteboard.ContextHandler;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.runtime.dto.DTOConstants;
import org.osgi.service.http.runtime.dto.ErrorPageDTO;
import org.osgi.service.http.runtime.dto.FailedErrorPageDTO;
import org.osgi.service.http.runtime.dto.FailedFilterDTO;
@@ -68,13 +72,39 @@
{
RuntimeDTO runtimeDTO = new RuntimeDTO();
runtimeDTO.attributes = createAttributes();
+ final List<FailedErrorPageDTO> failedErrorPageDTOs = new ArrayList<FailedErrorPageDTO>();
+ final List<FailedFilterDTO> failedFilterDTOs = new ArrayList<FailedFilterDTO>();
+ final List<FailedListenerDTO> failedListenerDTOs = new ArrayList<FailedListenerDTO>();
+ final List<FailedResourceDTO> failedResourceDTOs = new ArrayList<FailedResourceDTO>();
+ final List<FailedServletContextDTO> failedServletContextDTOs = new ArrayList<FailedServletContextDTO>();
+ final List<FailedServletDTO> failedServletDTOs = new ArrayList<FailedServletDTO>();
+
+ for(final AbstractInfo<?> info : this.registry.getInvalidServices())
+ {
+ if ( info instanceof ServletContextHelperInfo )
+ {
+ final ServletContextHelperInfo sch = (ServletContextHelperInfo)info;
+ final FailedServletContextDTO dto = new FailedServletContextDTO();
+ dto.attributes = Collections.emptyMap();
+ dto.contextPath = sch.getPath();
+ dto.errorPageDTOs = new ErrorPageDTO[0];
+ dto.failureReason = DTOConstants.FAILURE_REASON_VALIDATION_FAILED;
+ dto.filterDTOs = new FilterDTO[0];
+ dto.initParams = sch.getInitParameters();
+ dto.listenerDTOs = new ListenerDTO[0];
+ dto.name = sch.getName();
+ dto.resourceDTOs = new ResourceDTO[0];
+ dto.serviceId = sch.getServiceId();
+ dto.servletDTOs = new ServletDTO[0];
+ }
+ }
//TODO <**
- runtimeDTO.failedErrorPageDTOs = new FailedErrorPageDTO[0];
- runtimeDTO.failedFilterDTOs = new FailedFilterDTO[0];
- runtimeDTO.failedListenerDTOs = new FailedListenerDTO[0];
- runtimeDTO.failedResourceDTOs = new FailedResourceDTO[0];
- runtimeDTO.failedServletContextDTOs = new FailedServletContextDTO[0];
- runtimeDTO.failedServletDTOs = new FailedServletDTO[0];
+ runtimeDTO.failedErrorPageDTOs = failedErrorPageDTOs.toArray(new FailedErrorPageDTO[failedErrorPageDTOs.size()]);
+ runtimeDTO.failedFilterDTOs = failedFilterDTOs.toArray(new FailedFilterDTO[failedFilterDTOs.size()]);
+ runtimeDTO.failedListenerDTOs = failedListenerDTOs.toArray(new FailedListenerDTO[failedListenerDTOs.size()]);
+ runtimeDTO.failedResourceDTOs = failedResourceDTOs.toArray(new FailedResourceDTO[failedResourceDTOs.size()]);
+ runtimeDTO.failedServletContextDTOs = failedServletContextDTOs.toArray(new FailedServletContextDTO[failedServletContextDTOs.size()]);
+ runtimeDTO.failedServletDTOs = failedServletDTOs.toArray(new FailedServletDTO[failedServletDTOs.size()]);
//**>
runtimeDTO.servletContextDTOs = createContextDTOs();
return runtimeDTO;
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
index d756fe2..6ef65dc 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
@@ -521,6 +521,6 @@
handlerRuntimes = registry.getRuntime();
listenerRuntimes = listenerRegistry.getContextRuntimes();
}
- return new RegistryRuntime(contextHandlers, handlerRuntimes, listenerRuntimes);
+ return new RegistryRuntime(contextHandlers, handlerRuntimes, listenerRuntimes, this.invalidRegistrations);
}
}
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 d5e3a85..3818437 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
@@ -28,8 +28,6 @@
/**
* Tracks all {@link ServletContextHelper} services.
- * Only services with the required properties are tracker, services missing these
- * properties are ignored.
*/
public final class ServletContextHelperTracker extends ServiceTracker<ServletContextHelper, ServiceReference<ServletContextHelper>>
{
diff --git a/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java b/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java
index a78d8b0..d495076 100644
--- a/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java
+++ b/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java
@@ -186,7 +186,7 @@
List<HandlerRuntime> contextRuntimes,
Map<Long, Collection<ServiceReference<?>>> listenerRuntimes)
{
- registry = new RegistryRuntime(contexts, contextRuntimes, listenerRuntimes);
+ registry = new RegistryRuntime(contexts, contextRuntimes, listenerRuntimes, Collections.EMPTY_SET);
}
@Test