FELIX-4888 : ServletHandler's are not sorted by longest matching path. Finish error page registry. Start DTO handling (WiP)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1679975 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
index e533580..d37d7dd 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
@@ -51,10 +51,10 @@
import javax.servlet.http.HttpSession;
import org.apache.felix.http.base.internal.context.ExtServletContext;
+import org.apache.felix.http.base.internal.handler.FilterHandler;
import org.apache.felix.http.base.internal.handler.HandlerRegistry;
import org.apache.felix.http.base.internal.handler.HttpSessionWrapper;
-import org.apache.felix.http.base.internal.handler.holder.FilterHolder;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
import org.apache.felix.http.base.internal.registry.PathResolution;
import org.apache.felix.http.base.internal.registry.ServletResolution;
import org.apache.felix.http.base.internal.util.UriUtils;
@@ -138,14 +138,14 @@
private final String servletName;
public ServletResponseWrapper(final HttpServletRequest req, final HttpServletResponse res,
- final ServletHolder servletHolder)
+ final ServletHandler servletHandler)
{
super(res);
this.request = req;
- if ( servletHolder != null )
+ if ( servletHandler != null )
{
- this.serviceId = servletHolder.getContextServiceId();
- this.servletName = servletHolder.getName();
+ this.serviceId = servletHandler.getContextServiceId();
+ this.servletName = servletHandler.getName();
}
else
{
@@ -201,10 +201,10 @@
final RequestInfo requestInfo = new RequestInfo(servletPath, pathInfo, queryString);
- final FilterHolder[] filterHolders = handlerRegistry.getFilters(errorResolution, DispatcherType.ERROR, request.getRequestURI());
+ final FilterHandler[] filterHandlers = handlerRegistry.getFilters(errorResolution, DispatcherType.ERROR, request.getRequestURI());
// TODO - is async = false correct?
- invokeChain(errorResolution.holder, filterHolders, new ServletRequestWrapper(request, errorResolution.holder.getContext(), requestInfo, this.serviceId, false), this);
+ invokeChain(errorResolution.holder, filterHandlers, new ServletRequestWrapper(request, errorResolution.holder.getContext(), requestInfo, this.serviceId, false), this);
invokeSuper = false;
}
@@ -607,7 +607,7 @@
final HttpServletRequest wrappedRequest = new ServletRequestWrapper(req, servletContext, requestInfo,
pr.holder.getContextServiceId(),
pr.holder.getServletInfo().isAsyncSupported());
- final FilterHolder[] filterHolders = this.handlerRegistry.getFilters(pr, req.getDispatcherType(), pr.requestURI);
+ final FilterHandler[] filterHandlers = this.handlerRegistry.getFilters(pr, req.getDispatcherType(), pr.requestURI);
try
{
@@ -615,7 +615,7 @@
{
servletContext.getServletRequestListener().requestInitialized(new ServletRequestEvent(servletContext, wrappedRequest));
}
- invokeChain(pr.holder, filterHolders, wrappedRequest, wrappedResponse);
+ invokeChain(pr.holder, filterHandlers, wrappedRequest, wrappedResponse);
}
catch ( final Exception e)
{
@@ -681,9 +681,9 @@
void forward(final ServletResolution resolution, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String requestURI = getRequestURI(request);
- FilterHolder[] filterHolders = this.handlerRegistry.getFilters(resolution, DispatcherType.FORWARD, requestURI);
+ FilterHandler[] filterHandlers = this.handlerRegistry.getFilters(resolution, DispatcherType.FORWARD, requestURI);
- invokeChain(resolution.holder, filterHolders, request, response);
+ invokeChain(resolution.holder, filterHandlers, request, response);
}
/**
@@ -694,9 +694,9 @@
void include(final ServletResolution resolution, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String requestURI = getRequestURI(request);
- FilterHolder[] filterHolders = this.handlerRegistry.getFilters(resolution, DispatcherType.INCLUDE, requestURI);
+ FilterHandler[] filterHandlers = this.handlerRegistry.getFilters(resolution, DispatcherType.INCLUDE, requestURI);
- invokeChain(resolution.holder, filterHolders, request, response);
+ invokeChain(resolution.holder, filterHandlers, request, response);
}
private String getRequestURI(HttpServletRequest req)
@@ -704,13 +704,13 @@
return UriUtils.relativePath(req.getContextPath(), req.getRequestURI());
}
- private void invokeChain(final ServletHolder servletHolder,
- final FilterHolder[] filterHolders,
+ private void invokeChain(final ServletHandler servletHandler,
+ final FilterHandler[] filterHandlers,
final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException
{
- final FilterChain filterChain = new InvocationChain(servletHolder, filterHolders);
+ final FilterChain filterChain = new InvocationChain(servletHandler, filterHandlers);
filterChain.doFilter(request, response);
}
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/InvocationChain.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/InvocationChain.java
index 991b276..eda9509 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/InvocationChain.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/InvocationChain.java
@@ -29,20 +29,20 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.http.base.internal.handler.holder.FilterHolder;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
+import org.apache.felix.http.base.internal.handler.FilterHandler;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
public class InvocationChain implements FilterChain
{
- private final ServletHolder servletHolder;
- private final FilterHolder[] filterHolders;
+ private final ServletHandler servletHandler;
+ private final FilterHandler[] filterHandlers;
private int index = -1;
- public InvocationChain(@Nonnull final ServletHolder servletHolder, @Nonnull final FilterHolder[] filterHolders)
+ public InvocationChain(@Nonnull final ServletHandler servletHandler, @Nonnull final FilterHandler[] filterHandlers)
{
- this.filterHolders = filterHolders;
- this.servletHolder = servletHolder;
+ this.filterHandlers = filterHandlers;
+ this.servletHandler = servletHandler;
}
@Override
@@ -54,7 +54,7 @@
final HttpServletResponse hRes = (HttpServletResponse) res;
// invoke security
- if ( !servletHolder.getContext().handleSecurity(hReq, hRes))
+ if ( !servletHandler.getContext().handleSecurity(hReq, hRes))
{
// FELIX-3988: If the response is not yet committed and still has the default
// status, we're going to override this and send an error instead.
@@ -69,14 +69,14 @@
}
this.index++;
- if (this.index < this.filterHolders.length)
+ if (this.index < this.filterHandlers.length)
{
- this.filterHolders[this.index].handle(req, res, this);
+ this.filterHandlers[this.index].handle(req, res, this);
}
else
{
// Last entry in the chain...
- this.servletHolder.handle(req, res);
+ this.servletHandler.handle(req, res);
}
}
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/AbstractHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/AbstractHandler.java
deleted file mode 100644
index ccef7a0..0000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/AbstractHandler.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.felix.http.base.internal.handler;
-
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import javax.servlet.Filter;
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-
-public abstract class AbstractHandler<T extends AbstractHandler<?>> implements Comparable<T>
-{
- private final String name;
- private final ExtServletContext context;
- private final Map<String, String> initParams;
-
- public AbstractHandler(final ExtServletContext context,
- final Map<String, String> initParams,
- final String name)
- {
- this.context = context;
- this.name = name;
- this.initParams = initParams;
- }
-
- public final Map<String, String> getInitParams()
- {
- return this.initParams;
- }
-
- public final String getName()
- {
- String name = this.name;
- if (name == null)
- {
- name = getSubject().getClass().getName();
- }
- return name;
- }
-
- public ExtServletContext getContext()
- {
- return this.context;
- }
-
- public abstract void init() throws ServletException;
-
- public abstract void destroy();
-
- /**
- * @return the {@link Servlet} or {@link Filter} this handler handles.
- */
- protected abstract Object getSubject();
-
- protected abstract long getServiceId();
-
- public abstract Pattern[] getPatterns();
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java
index a8eb611..138a8d0 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java
@@ -21,6 +21,7 @@
import java.util.List;
import java.util.regex.Pattern;
+import javax.annotation.Nonnull;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
@@ -28,23 +29,35 @@
import javax.servlet.ServletResponse;
import org.apache.felix.http.base.internal.context.ExtServletContext;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
import org.apache.felix.http.base.internal.runtime.FilterInfo;
-import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
import org.apache.felix.http.base.internal.runtime.dto.FilterRuntime;
import org.apache.felix.http.base.internal.util.PatternUtil;
+import org.osgi.service.http.runtime.dto.DTOConstants;
-public final class FilterHandler extends AbstractHandler<FilterHandler> implements FilterRuntime
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class FilterHandler implements Comparable<FilterHandler>, FilterRuntime
{
- private final Filter filter;
- private final FilterInfo filterInfo;
- private final Pattern[] patterns;
-
private final long contextServiceId;
- public FilterHandler(final ServletContextHelperInfo contextInfo, ExtServletContext context, Filter filter, FilterInfo filterInfo)
+ private final FilterInfo filterInfo;
+
+ private final ExtServletContext context;
+
+ private volatile Filter filter;
+
+ protected volatile int useCount;
+
+ private final Pattern[] patterns;
+
+ public FilterHandler(final long contextServiceId,
+ final ExtServletContext context,
+ final FilterInfo filterInfo)
{
- super(context, filterInfo.getInitParameters(), filterInfo.getName());
- this.filter = filter;
+ this.contextServiceId = contextServiceId;
+ this.context = context;
this.filterInfo = filterInfo;
// Compose a single array of all patterns & regexs the filter must represent...
String[] patterns = getFilterPatterns(filterInfo);
@@ -54,59 +67,6 @@
{
this.patterns[i] = Pattern.compile(patterns[i]);
}
- if ( contextInfo != null )
- {
- this.contextServiceId = contextInfo.getServiceId();
- }
- else
- {
- this.contextServiceId = 0;
- }
- }
-
- @Override
- public int compareTo(FilterHandler other)
- {
- return this.filterInfo.compareTo(other.filterInfo);
- }
-
- @Override
- public void destroy()
- {
- this.filter.destroy();
- }
-
- public Filter getFilter()
- {
- return this.filter;
- }
-
- @Override
- public FilterInfo getFilterInfo()
- {
- return this.filterInfo;
- }
-
- public int getRanking()
- {
- return filterInfo.getRanking();
- }
-
- public void handle(ServletRequest req, ServletResponse res, FilterChain chain) throws ServletException, IOException
- {
- this.filter.doFilter(req, res, chain);
- }
-
- @Override
- public void init() throws ServletException
- {
- this.filter.init(new FilterConfigImpl(getName(), getContext(), getInitParams()));
- }
-
- @Override
- protected Object getSubject()
- {
- return this.filter;
}
private static String[] getFilterPatterns(FilterInfo filterInfo)
@@ -129,20 +89,124 @@
return result.toArray(new String[result.size()]);
}
- @Override
public Pattern[] getPatterns() {
return this.patterns;
}
@Override
+ public int compareTo(final FilterHandler other)
+ {
+ return this.filterInfo.compareTo(other.filterInfo);
+ }
+
+ @Override
public long getContextServiceId()
{
return this.contextServiceId;
}
- @Override
- protected long getServiceId()
+ public ExtServletContext getContext()
{
- return this.filterInfo.getServiceId();
+ return this.context;
+ }
+
+ public Filter getFilter()
+ {
+ return filter;
+ }
+
+ protected void setFilter(final Filter f)
+ {
+ this.filter = f;
+ }
+
+ @Override
+ public FilterInfo getFilterInfo()
+ {
+ return this.filterInfo;
+ }
+
+ public String getName()
+ {
+ String name = this.filterInfo.getName();
+ if (name == null)
+ {
+ name = filter.getClass().getName();
+ }
+ return name;
+ }
+
+ /**
+ * Initialize the object
+ * @return {code -1} on success, a failure reason according to {@link DTOConstants} otherwise.
+ */
+ public int init()
+ {
+ if ( this.useCount > 0 )
+ {
+ this.useCount++;
+ return -1;
+ }
+
+ if (this.filter == null)
+ {
+ return DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE;
+ }
+
+ try
+ {
+ filter.init(new FilterConfigImpl(getName(), getContext(), getFilterInfo().getInitParameters()));
+ }
+ catch (final ServletException e)
+ {
+ SystemLogger.error(this.getFilterInfo().getServiceReference(),
+ "Error during calling init() on filter " + this.filter,
+ e);
+ return DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT;
+ }
+ this.useCount++;
+ return -1;
+ }
+
+ public void handle(@Nonnull final ServletRequest req,
+ @Nonnull final ServletResponse res,
+ @Nonnull final FilterChain chain) throws ServletException, IOException
+ {
+ this.filter.doFilter(req, res, chain);
+ }
+
+ public boolean destroy()
+ {
+ if (this.filter == null)
+ {
+ return false;
+ }
+
+ this.useCount--;
+ if ( this.useCount == 0 )
+ {
+ try
+ {
+ filter.destroy();
+ }
+ catch ( final Exception ignore )
+ {
+ // we ignore this
+ SystemLogger.error(this.getFilterInfo().getServiceReference(),
+ "Error during calling destroy() on filter " + this.filter,
+ ignore);
+ }
+
+ filter = null;
+ return true;
+ }
+ return false;
+ }
+
+ public boolean dispose()
+ {
+ // fully destroy the filter
+ this.useCount = 1;
+ return this.destroy();
}
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerMapping.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerMapping.java
deleted file mode 100644
index ee9066f..0000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerMapping.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
- * 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.felix.http.base.internal.handler;
-
-import static java.util.Collections.unmodifiableCollection;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.felix.http.base.internal.util.PatternUtil;
-import org.apache.felix.http.base.internal.util.PatternUtil.PatternComparator;
-
-/**
- * Represents a Map-like structure that can map path-patterns to servlet/filter handlers, allowing
- * for easy access to those handlers, based on the match rules defined in section 12.1 of Servlet
- * 3.0 specification.
- * <p>
- * {@link HandlerMapping} instances are immutable.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public final class HandlerMapping<V extends AbstractHandler<V>>
-{
- private final SortedMap<Pattern, Set<V>> exactMap;
- private final SortedMap<Pattern, Set<V>> wildcardMap;
- private final Set<V> mappedHandlers;
-
- /**
- * Creates a new, empty, {@link HandlerMapping} instance.
- */
- public HandlerMapping()
- {
- this(Collections.<Pattern, Collection<V>>emptyMap());
- }
-
- /**
- * Creates a new {@link HandlerMapping} instance for the given elements.
- *
- * @param mappings the elements to map.
- */
- private HandlerMapping(Map<Pattern, Collection<V>> mappings)
- {
- this.exactMap = new TreeMap<Pattern, Set<V>>(PatternComparator.INSTANCE);
- this.wildcardMap = new TreeMap<Pattern, Set<V>>(PatternComparator.INSTANCE);
- this.mappedHandlers = new TreeSet<V>();
-
- for (Map.Entry<Pattern, Collection<V>> mapping : mappings.entrySet())
- {
- Pattern pattern = mapping.getKey();
- Collection<V> handlers = mapping.getValue();
-
- mappedHandlers.addAll(handlers);
-
- if (PatternUtil.isWildcardPattern(pattern))
- {
- Set<V> vs = this.wildcardMap.get(pattern);
- if (vs == null)
- {
- vs = new TreeSet<V>();
- this.wildcardMap.put(pattern, vs);
- }
- vs.addAll(handlers);
- }
- else
- {
- Set<V> vs = this.exactMap.get(pattern);
- if (vs == null)
- {
- vs = new TreeSet<V>();
- this.exactMap.put(pattern, vs);
- }
- vs.addAll(handlers);
- }
- }
- }
-
- /**
- * Returns a new {@link HandlerMapping} instance with a mapping for the
- * given handler.
- *
- * @param handler the handler to be added to the mapping.
- * @return a new {@link HandlerMapping} instance with a mapping for the
- * given handler.
- */
- public HandlerMapping<V> add(V handler)
- {
- Map<Pattern, V> mappings = new TreeMap<Pattern, V>(PatternComparator.INSTANCE);
- for (Pattern pattern : handler.getPatterns())
- {
- mappings.put(pattern, handler);
- }
- return add(mappings);
- }
-
- HandlerMapping<V> add(Map<Pattern, V> mappings)
- {
- Map<Pattern, Collection<V>> newMappings = getAllMappings();
- addMappings(mappings, newMappings);
- return new HandlerMapping<V>(newMappings);
- }
-
- /**
- * Returns a new {@link HandlerMapping} instance without a mapping for the
- * given handler.
- *
- * @param subject the handled element to be removed from the mapping
- * @return a new {@link HandlerMapping} instance without a mapping for the
- * given handler.
- */
- public HandlerMapping<V> remove(V handler)
- {
- Map<Pattern, V> mappings = new TreeMap<Pattern, V>(PatternComparator.INSTANCE);
- for (Pattern pattern : handler.getPatterns())
- {
- mappings.put(pattern, handler);
- }
- return remove(mappings);
- }
-
- HandlerMapping<V> remove(Map<Pattern, V> mappings)
- {
- Map<Pattern, Collection<V>> newMappings = getAllMappings();
- removeMappings(mappings, newMappings);
- return new HandlerMapping<V>(newMappings);
- }
-
- HandlerMapping<V> update(Map<Pattern, V> add, Map<Pattern, V> remove)
- {
- Map<Pattern, Collection<V>> newMappings = getAllMappings();
- removeMappings(remove, newMappings);
- addMappings(add, newMappings);
- return new HandlerMapping<V>(newMappings);
- }
-
- private void addMappings(Map<Pattern, V> mappings, Map<Pattern, Collection<V>> target)
- {
- for (Map.Entry<Pattern, V> mapping : mappings.entrySet())
- {
- if (!target.containsKey(mapping.getKey()))
- {
- target.put(mapping.getKey(), new TreeSet<V>());
- }
- target.get(mapping.getKey()).add(mapping.getValue());
- }
- }
-
- private void removeMappings(Map<Pattern, V> mappings, Map<Pattern, Collection<V>> target)
- {
- for (Map.Entry<Pattern, V> mapping : mappings.entrySet())
- {
- Collection<V> mappedHandlers = target.get(mapping.getKey());
- if (mappedHandlers == null)
- {
- continue;
- }
- mappedHandlers.remove(mapping.getValue());
- if (mappedHandlers.isEmpty())
- {
- target.remove(mapping.getKey());
- }
- }
- }
-
- private Map<Pattern, Collection<V>> getAllMappings()
- {
- Map<Pattern, Collection<V>> newMappings = new TreeMap<Pattern, Collection<V>>(PatternComparator.INSTANCE);
- newMappings.putAll(exactMap);
- newMappings.putAll(wildcardMap);
- return newMappings;
- }
-
- /**
- * Returns all mapped handlers.
- *
- * @return the handlers contained in this mapping. The returned
- * <code>Collection</code> is unmodifiable and never
- * <code>null</code>.
- */
- public Collection<V> values()
- {
- return unmodifiableCollection(mappedHandlers);
- }
-
- /**
- * Returns whether this mapping contains the specified handler.
- *
- * @return <code>true</code> if the handlers contains the specified handler,
- * <code>false</code> otherwise
- */
- public boolean contains(V handler)
- {
- return mappedHandlers.contains(handler);
- }
-
- /**
- * Returns all matching handlers for the given path.
- *
- * @param path the path that should match, cannot be <code>null</code>.
- * @return a {@link Collection} of all matching handlers, never <code>null</code>.
- */
- public List<V> getAllMatches(String path)
- {
- return getAllMatches(path, false /* firstOnly */);
- }
-
- /**
- * Returns the best matching handler for the given path, according to the rules defined in section 12.1 of Servlet 3.0 specification:
- * <ul>
- * <li>find an exact match of the path of the request to the path of the handler. A successful match selects the handler;</li>
- * <li>recursively try to match the longest path-prefix. This is done by stepping down the path tree a directory at a time, using the
- * '/' character as a path separator. The longest match determines the servlet selected;</li>
- * <li>if the last segment in the URL path contains an extension (e.g. .jsp), the servlet container will try to match a servlet that
- * handles requests for the extension. An extension is defined as the part of the last segment after the last '.' character.</li>
- * </ul>
- *
- * @param path the path that should match, cannot be <code>null</code>.
- * @return the best matching handler for the given path, or <code>null</code> in case no handler matched.
- */
- V getBestMatch(String path)
- {
- List<V> allMatches = getAllMatches(path, true /* firstOnly */);
- return allMatches.isEmpty() ? null : allMatches.get(0);
- }
-
- /**
- * Returns the (first) handler identified by the given name.
- *
- * @param name the name of the handler to return, can be <code>null</code> in which case this method will return <code>null</code>.
- * @return the element with the given name, or <code>null</code> if not found, or the given argument was <code>null</code>.
- */
- V getByName(String name)
- {
- if (name == null)
- {
- return null;
- }
-
- for (V element : this.mappedHandlers)
- {
- if (name.equals(element.getName()))
- {
- return element;
- }
- }
-
- return null;
- }
-
- /**
- * Provides information on whether there are elements mapped or not.
- *
- * @return <code>false</code> if there is at least one element mapped, <code>true</code> otherwise.
- */
- boolean isEmpty()
- {
- return this.mappedHandlers.isEmpty();
- }
-
- /**
- * Performs the actual matching, yielding a list of either the first or all matching patterns.
- *
- * @param path the path to match, can be <code>null</code> in which case an empty string is
- * used;
- * @param firstOnly <code>true</code> if only the first matching pattern should be returned,
- * <code>false</code> if all matching patterns should be returned.
- * @return a list with matching elements, never <code>null</code>.
- */
- private List<V> getAllMatches(String path, boolean firstOnly)
- {
- path = (path == null) ? "" : path.trim();
-
- Set<V> result = new TreeSet<V>();
- // Look for exact matches only, that is, those patterns without wildcards...
- for (Entry<Pattern, Set<V>> entry : this.exactMap.entrySet())
- {
- Matcher matcher = entry.getKey().matcher(path);
- // !!! we should always match the *entire* pattern, instead of the longest prefix...
- if (matcher.matches())
- {
- Set<V> vs = entry.getValue();
- for (V v : vs)
- {
- result.add(v);
- if (firstOnly)
- {
- return new ArrayList<V>(result);
- }
- }
- }
- }
-
- // Try to apply the wildcard patterns...
- for (Entry<Pattern, Set<V>> entry : this.wildcardMap.entrySet())
- {
- Matcher matcher = entry.getKey().matcher(path);
- if (matcher.find(0))
- {
- Set<V> vs = entry.getValue();
- for (V v : vs)
- {
- result.add(v);
-
- if (firstOnly)
- {
- break;
- }
- }
- }
- }
-
- return new ArrayList<V>(result);
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRankingMultimap.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRankingMultimap.java
deleted file mode 100644
index 70322cc..0000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRankingMultimap.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * 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.felix.http.base.internal.handler;
-
-import static java.util.Arrays.asList;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.PriorityQueue;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-
-public final class HandlerRankingMultimap<K>
-{
- private final Map<ServletHandler, Integer> useCounts = new TreeMap<ServletHandler, Integer>();
-
- private final Map<K, PriorityQueue<ServletHandler>> handlerMultimap;
- private final Comparator<ServletHandler> handlerComparator;
- private final Comparator<K> keyComparator;
-
- private int size = 0;
-
- public HandlerRankingMultimap()
- {
- this.handlerMultimap = new HashMap<K, PriorityQueue<ServletHandler>>();
- this.keyComparator = null;
- this.handlerComparator = null;
- }
-
- public HandlerRankingMultimap(Comparator<K> keyComparator)
- {
- this(keyComparator, null);
- }
-
- public HandlerRankingMultimap(Comparator<K> keyComparator, Comparator<ServletHandler> handlerComparator)
- {
- this.keyComparator = keyComparator;
- this.handlerMultimap = new TreeMap<K, PriorityQueue<ServletHandler>>(keyComparator);
- this.handlerComparator = handlerComparator;
- }
-
- boolean isActive(ServletHandler handler)
- {
- return useCounts.containsKey(handler);
- }
-
- public Update<K> add(K[] keys, ServletHandler handler)
- {
- return add(asList(keys), handler);
- }
-
- Update<K> add(Collection<K> keys, ServletHandler handler)
- {
- if (handler == null)
- {
- throw new NullPointerException("handler must not be null");
- }
- Map<K, ServletHandler> activate = createMap();
- Map<K, ServletHandler> deactivate = createMap();
- Set<ServletHandler> destroy = new TreeSet<ServletHandler>();
- for (K key : keys)
- {
- PriorityQueue<ServletHandler> queue = getQueue(key);
-
- if (queue.isEmpty() || compareHandlers(queue.peek(), handler) > 0)
- {
- activateEntry(key, handler, activate, null);
-
- if (!queue.isEmpty())
- {
- ServletHandler currentHead = queue.peek();
- deactivateEntry(key, currentHead, deactivate, destroy);
- }
- }
-
- queue.add(handler);
- }
-
- size += 1;
-
- return Update.forAdd(activate, deactivate, destroy);
- }
-
- public Update<K> remove(K[] keys, ServletHandler handler)
- {
- return remove(asList(keys), handler);
- }
-
- Update<K> remove(Collection<K> keys, ServletHandler handler)
- {
- Map<K, ServletHandler> activate = createMap();
- Map<K, ServletHandler> deactivate = createMap();
- Set<ServletHandler> init = new TreeSet<ServletHandler>();
- for (K key : keys)
- {
- PriorityQueue<ServletHandler> queue = handlerMultimap.get(key);
- if (queue == null)
- {
- throw new IllegalArgumentException("Map does not contain key: " + key);
- }
-
- boolean isDeactivate = !queue.isEmpty() && compareHandlers(queue.peek(), handler) == 0;
- queue.remove(handler);
-
- if (isDeactivate)
- {
- deactivateEntry(key, handler, deactivate, null);
-
- if (!queue.isEmpty())
- {
- ServletHandler newHead = queue.peek();
- activateEntry(key, newHead, activate, init);
- }
- }
-
- if (queue.isEmpty())
- {
- handlerMultimap.remove(key);
- }
- }
-
- size -= 1;
-
- return Update.forRemove(activate, deactivate, init);
- }
-
- private PriorityQueue<ServletHandler> getQueue(K key)
- {
- PriorityQueue<ServletHandler> queue = handlerMultimap.get(key);
- if (queue == null)
- {
- queue = new PriorityQueue<ServletHandler>(1, handlerComparator);
- handlerMultimap.put(key, queue);
- }
- return queue;
- }
-
- private void activateEntry(K key, ServletHandler handler, Map<K, ServletHandler> activate, Set<ServletHandler> init)
- {
- activate.put(key, handler);
- if (incrementUseCount(handler) == 1 && init != null)
- {
- init.add(handler);
- };
- }
-
- private void deactivateEntry(K key, ServletHandler handler, Map<K, ServletHandler> deactivate, Set<ServletHandler> destroy)
- {
- deactivate.put(key, handler);
- if (decrementUseCount(handler) == 0 && destroy != null)
- {
- destroy.add(handler);
- }
- }
-
- private int incrementUseCount(ServletHandler handler)
- {
- Integer currentCount = useCounts.get(handler);
- Integer newCount = currentCount == null ? 1 : currentCount + 1;
-
- useCounts.put(handler, newCount);
-
- return newCount;
- }
-
- private int decrementUseCount(ServletHandler handler)
- {
- int currentCount = useCounts.get(handler);
- if (currentCount == 1)
- {
- useCounts.remove(handler);
- return 0;
- }
-
- int newCount = currentCount - 1;
- useCounts.put(handler, newCount);
- return newCount;
- }
-
- public void clear()
- {
- handlerMultimap.clear();
- useCounts.clear();
- }
-
- public Collection<ServletHandler> getActiveValues()
- {
- TreeSet<ServletHandler> activeValues = new TreeSet<ServletHandler>();
- for (PriorityQueue<ServletHandler> queue : handlerMultimap.values())
- {
- activeValues.add(queue.peek());
- }
- return activeValues;
- }
-
- public Collection<ServletHandler> getShadowedValues()
- {
- TreeSet<ServletHandler> shadowedValues = new TreeSet<ServletHandler>();
- for (PriorityQueue<ServletHandler> queue : handlerMultimap.values())
- {
- ServletHandler head = queue.element();
- for (ServletHandler value : queue)
- {
- if (compareHandlers(value, head) != 0)
- {
- shadowedValues.add(value);
- }
- }
- }
- return shadowedValues;
- }
-
- int size()
- {
- return size;
- }
-
- private int compareHandlers(ServletHandler one, ServletHandler two)
- {
- if (handlerComparator == null)
- {
- return one.compareTo(two);
- }
- return handlerComparator.compare(one, two);
- }
-
- private Map<K,ServletHandler> createMap()
- {
- return keyComparator == null ? new HashMap<K, ServletHandler>() : new TreeMap<K, ServletHandler>(keyComparator);
- }
-
- public static final class Update<K>
- {
- private final Map<K, ServletHandler> activate;
- private final Map<K, ServletHandler> deactivate;
- private final Collection<ServletHandler> init;
- private final Collection<ServletHandler> destroy;
-
- Update(Map<K, ServletHandler> activate,
- Map<K, ServletHandler> deactivate,
- Collection<ServletHandler> init,
- Collection<ServletHandler> destroy)
- {
- this.activate = activate;
- this.deactivate = deactivate;
- this.init = init;
- this.destroy = destroy;
- }
-
- private static <K> Update<K> forAdd(Map<K, ServletHandler> activate,
- Map<K, ServletHandler> deactivate,
- Collection<ServletHandler> destroy)
- {
- // activate contains at most one value, mapped to multiple keys
- Collection<ServletHandler> init = valueAsCollection(activate);
- return new Update<K>(activate, deactivate, init, destroy);
- }
-
- private static <K> Update<K> forRemove(Map<K, ServletHandler> activate,
- Map<K, ServletHandler> deactivate,
- Collection<ServletHandler> init)
- {
- // deactivate contains at most one value, mapped to multiple keys
- Collection<ServletHandler> destroy = valueAsCollection(deactivate);
- return new Update<K>(activate, deactivate, init, destroy);
- }
-
- private static <K> Collection<ServletHandler> valueAsCollection(Map<K, ServletHandler> valueMap)
- {
- if (valueMap.isEmpty())
- {
- return Collections.emptyList();
- }
-
- Collection<ServletHandler> valueSet = new ArrayList<ServletHandler>(1);
- valueSet.add(valueMap.values().iterator().next());
- return valueSet;
- }
-
- public Map<K, ServletHandler> getActivated()
- {
- return activate;
- }
-
- public Map<K, ServletHandler> getDeactivated()
- {
- return deactivate;
- }
-
- public Collection<ServletHandler> getInit()
- {
- return init;
- }
-
- public Collection<ServletHandler> getDestroy()
- {
- return destroy;
- }
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
index ac025d2..160d3af 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
@@ -24,8 +24,6 @@
import javax.annotation.Nonnull;
import javax.servlet.DispatcherType;
-import org.apache.felix.http.base.internal.handler.holder.FilterHolder;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
import org.apache.felix.http.base.internal.registry.PathResolution;
import org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry;
import org.apache.felix.http.base.internal.registry.ServletResolution;
@@ -44,20 +42,17 @@
*/
public final class HandlerRegistry
{
- private static FilterHolder[] EMPTY_FILTER_HOLDER = new FilterHolder[0];
+ private static FilterHandler[] EMPTY_FILTER_HOLDER = new FilterHandler[0];
/** Current list of context registrations. */
private volatile List<PerContextHandlerRegistry> registrations = Collections.emptyList();
- private final ServletHandlerRegistry servletRegistry = new ServletHandlerRegistry();
-
/**
* Register default context registry for Http Service
*/
public void init()
{
this.add(new PerContextHandlerRegistry());
- servletRegistry.init();
}
/**
@@ -74,7 +69,6 @@
}
- servletRegistry.shutdown();
for(final PerContextHandlerRegistry r : list)
{
r.removeAll();
@@ -90,7 +84,6 @@
synchronized ( this )
{
this.add(new PerContextHandlerRegistry(info));
- this.servletRegistry.add(info);
}
}
@@ -102,7 +95,6 @@
{
synchronized ( this )
{
- this.servletRegistry.remove(info);
final List<PerContextHandlerRegistry> updatedList = new ArrayList<PerContextHandlerRegistry>(this.registrations);
final Iterator<PerContextHandlerRegistry> i = updatedList.iterator();
while ( i.hasNext() )
@@ -134,7 +126,7 @@
}
}
- public void addFilter(@Nonnull final FilterHolder holder)
+ public void addFilter(@Nonnull final FilterHandler holder)
{
final PerContextHandlerRegistry reg = this.getRegistry(holder.getContextServiceId());
// TODO - check whether we need to handle the null case as well
@@ -194,7 +186,7 @@
}
if ( reg != null )
{
- final ServletHolder holder = reg.getErrorHandler(code, exception);
+ final ServletHandler holder = reg.getErrorHandler(code, exception);
if ( holder != null )
{
final ServletResolution res = new ServletResolution();
@@ -207,18 +199,18 @@
return null;
}
- public FilterHolder[] getFilters(@Nonnull final ServletResolution pr,
+ public FilterHandler[] getFilters(@Nonnull final ServletResolution pr,
final DispatcherType dispatcherType,
@Nonnull String requestURI)
{
if ( pr != null && pr.handlerRegistry != null )
{
- return pr.handlerRegistry.getFilterHolders(pr.holder, dispatcherType, requestURI);
+ return pr.handlerRegistry.getFilterHandlers(pr.holder, dispatcherType, requestURI);
}
return EMPTY_FILTER_HOLDER;
}
- public void addServlet(final ServletHolder holder)
+ public void addServlet(final ServletHandler holder)
{
final PerContextHandlerRegistry reg = this.getRegistry(holder.getContextServiceId());
// TODO - check whether we need to handle the null case as well
@@ -274,7 +266,7 @@
final PerContextHandlerRegistry reg = (contextId == null ? null : this.getRegistry(contextId));
if ( reg != null )
{
- final ServletHolder holder = reg.resolveServletByName(name);
+ final ServletHandler holder = reg.resolveServletByName(name);
if ( holder != null )
{
final ServletResolution resolution = new ServletResolution();
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceFilterHolder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceFilterHandler.java
similarity index 86%
rename from http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceFilterHolder.java
rename to http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceFilterHandler.java
index 68b1a38..a2139f3 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceFilterHolder.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceFilterHandler.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.felix.http.base.internal.handler.holder;
+package org.apache.felix.http.base.internal.handler;
import javax.servlet.Filter;
@@ -24,9 +24,9 @@
/**
* Servlet holder for filters registered through the ext http service.
*/
-public final class HttpServiceFilterHolder extends FilterHolder
+public final class HttpServiceFilterHandler extends FilterHandler
{
- public HttpServiceFilterHolder(final long contextServiceId,
+ public HttpServiceFilterHandler(final long contextServiceId,
final ExtServletContext context,
final FilterInfo filterInfo,
final Filter filter)
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceServletHolder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceServletHandler.java
similarity index 81%
rename from http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceServletHolder.java
rename to http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceServletHandler.java
index 8c3cdd1..92fce74 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceServletHolder.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceServletHandler.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.felix.http.base.internal.handler.holder;
+package org.apache.felix.http.base.internal.handler;
import javax.servlet.Servlet;
@@ -22,11 +22,11 @@
import org.apache.felix.http.base.internal.runtime.ServletInfo;
/**
- * Servlet holder for servlets registered through the http service.
+ * Servlet handler for servlets registered through the http service.
*/
-public final class HttpServiceServletHolder extends ServletHolder
+public final class HttpServiceServletHandler extends ServletHandler
{
- public HttpServiceServletHolder(final long contextServiceId,
+ public HttpServiceServletHandler(final long contextServiceId,
final ExtServletContext context,
final ServletInfo servletInfo,
final Servlet servlet)
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ResourceServletHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ResourceServletHandler.java
deleted file mode 100644
index a4c2de4..0000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ResourceServletHandler.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.felix.http.base.internal.handler;
-
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.apache.felix.http.base.internal.whiteboard.ResourceServlet;
-
-public final class ResourceServletHandler extends ServletHandler
-{
- private Servlet servlet;
-
- public ResourceServletHandler(ServletContextHelperInfo contextInfo,
- ExtServletContext context,
- ServletInfo servletInfo)
- {
- super(contextInfo.getServiceId(), context, checkIsResource(servletInfo, true));
- }
-
- @Override
- public Servlet getServlet()
- {
- return servlet;
- }
-
- @Override
- public void init() throws ServletException
- {
- if (servlet != null)
- {
- return;
- }
-
- servlet = new ResourceServlet(getServletInfo().getPrefix());
- servlet.init(new ServletConfigImpl(getName(), getContext(), getInitParams()));
- }
-
- @Override
- public void destroy()
- {
- if (servlet == null)
- {
- return;
- }
-
- servlet.destroy();
- servlet = null;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
index 5d10a1a..9872ec1 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
@@ -17,47 +17,40 @@
package org.apache.felix.http.base.internal.handler;
import java.io.IOException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.felix.http.base.internal.context.ExtServletContext;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
import org.apache.felix.http.base.internal.runtime.dto.ServletRuntime;
-import org.apache.felix.http.base.internal.util.PatternUtil;
+import org.osgi.service.http.runtime.dto.DTOConstants;
/**
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public abstract class ServletHandler extends AbstractHandler<ServletHandler> implements ServletRuntime
+public abstract class ServletHandler implements Comparable<ServletHandler>, ServletRuntime
{
- private final ServletInfo servletInfo;
- private final Pattern[] patterns;
private final long contextServiceId;
+ private final ServletInfo servletInfo;
+
+ private final ExtServletContext context;
+
+ private volatile Servlet servlet;
+
+ protected volatile int useCount;
+
public ServletHandler(final long contextServiceId,
final ExtServletContext context,
final ServletInfo servletInfo)
{
- super(context, servletInfo.getInitParameters(), servletInfo.getName());
-
- this.servletInfo = servletInfo;
-
- // Can be null in case of error-handling servlets...
- String[] patterns = this.servletInfo.getPatterns();
- final int length = patterns == null ? 0 : patterns.length;
-
- this.patterns = new Pattern[length];
- for (int i = 0; i < length; i++)
- {
- final String pattern = patterns[i];
- this.patterns[i] = Pattern.compile(PatternUtil.convertToRegEx(pattern));
- }
-
this.contextServiceId = contextServiceId;
+ this.context = context;
+ this.servletInfo = servletInfo;
}
@Override
@@ -66,35 +59,32 @@
return this.servletInfo.compareTo(other.servletInfo);
}
- public void handle(ServletRequest req, ServletResponse res) throws ServletException, IOException
+ @Override
+ public long getContextServiceId()
{
- getServlet().service(req, res);
+ return this.contextServiceId;
}
- public String determineServletPath(String uri)
+ public ExtServletContext getContext()
{
- if (uri == null)
- {
- uri = "/";
- }
-
- // Patterns are sorted on length in descending order, so we should get the longest match first...
- for (int i = 0; i < this.patterns.length; i++)
- {
- Matcher matcher = this.patterns[i].matcher(uri);
- if (matcher.find(0))
- {
- return matcher.groupCount() > 0 ? matcher.group(1) : matcher.group();
- }
- }
-
- return null;
+ return this.context;
}
@Override
- public Pattern[] getPatterns()
+ public Servlet getServlet()
{
- return this.patterns;
+ return servlet;
+ }
+
+ protected void setServlet(final Servlet s)
+ {
+ this.servlet = s;
+ }
+
+ public void handle(final ServletRequest req, final ServletResponse res)
+ throws ServletException, IOException
+ {
+ this.servlet.service(req, res);
}
@Override
@@ -103,31 +93,81 @@
return this.servletInfo;
}
- @Override
- public long getContextServiceId()
+ public String getName()
{
- return this.contextServiceId;
- }
-
- @Override
- protected long getServiceId()
- {
- return this.servletInfo.getServiceId();
- }
-
- @Override
- protected Object getSubject()
- {
- return getServlet();
- }
-
- protected static ServletInfo checkIsResource(ServletInfo servletInfo, boolean checkTrue)
- {
- if (checkTrue != servletInfo.isResource())
+ String name = this.servletInfo.getName();
+ if (name == null)
{
- String message = "ServletInfo must " + (checkTrue ? "" : "not") + " represent a resource";
- throw new IllegalArgumentException(message);
+ name = servlet.getClass().getName();
}
- return servletInfo;
+ return name;
+ }
+
+ /**
+ * Initialize the object
+ * @return {code -1} on success, a failure reason according to {@link DTOConstants} otherwise.
+ */
+ public int init()
+ {
+ if ( this.useCount > 0 )
+ {
+ this.useCount++;
+ return -1;
+ }
+
+ if (this.servlet == null)
+ {
+ return DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE;
+ }
+
+ try
+ {
+ servlet.init(new ServletConfigImpl(getName(), getContext(), getServletInfo().getInitParameters()));
+ }
+ catch (final ServletException e)
+ {
+ SystemLogger.error(this.getServletInfo().getServiceReference(),
+ "Error during calling init() on servlet " + this.servlet,
+ e);
+ return DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT;
+ }
+ this.useCount++;
+ return -1;
+ }
+
+
+ public boolean destroy()
+ {
+ if (this.servlet == null)
+ {
+ return false;
+ }
+
+ this.useCount--;
+ if ( this.useCount == 0 )
+ {
+ try
+ {
+ servlet.destroy();
+ }
+ catch ( final Exception ignore )
+ {
+ // we ignore this
+ SystemLogger.error(this.getServletInfo().getServiceReference(),
+ "Error during calling destroy() on servlet " + this.servlet,
+ ignore);
+ }
+
+ servlet = null;
+ return true;
+ }
+ return false;
+ }
+
+ public boolean dispose()
+ {
+ // fully destroy the servlet
+ this.useCount = 1;
+ return this.destroy();
}
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandlerRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandlerRegistry.java
deleted file mode 100644
index 200634a..0000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandlerRegistry.java
+++ /dev/null
@@ -1,532 +0,0 @@
-/*
- * 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.felix.http.base.internal.handler;
-
-import static java.util.Arrays.asList;
-import static org.osgi.service.http.runtime.dto.DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT;
-import static org.osgi.service.http.runtime.dto.DTOConstants.FAILURE_REASON_SERVICE_IN_USE;
-import static org.osgi.service.http.runtime.dto.DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
-import static org.osgi.service.http.runtime.dto.DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.regex.Pattern;
-
-import javax.annotation.Nonnull;
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-
-import org.apache.felix.http.base.internal.handler.HandlerRankingMultimap.Update;
-import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.apache.felix.http.base.internal.runtime.dto.FailureRuntime;
-import org.apache.felix.http.base.internal.runtime.dto.ServletRegistryRuntime;
-import org.apache.felix.http.base.internal.runtime.dto.ServletRuntime;
-import org.apache.felix.http.base.internal.util.PatternUtil;
-import org.apache.felix.http.base.internal.util.PatternUtil.PatternComparator;
-import org.apache.felix.http.base.internal.whiteboard.RegistrationFailureException;
-
-final class ServletHandlerRegistry
-{
- private final HandlerRankingMultimap<String> registeredServletHandlers;
- private final SortedSet<ServletHandler> allServletHandlers = new TreeSet<ServletHandler>();
- private final Set<ServletHandler> initFailures = new TreeSet<ServletHandler>();
-
- private volatile ContextRegistry contextRegistry;
-
- ServletHandlerRegistry()
- {
- this.contextRegistry = new ContextRegistry();
- this.registeredServletHandlers = new HandlerRankingMultimap<String>(null, new ServletHandlerComparator());
- }
-
- /**
- * Register default context registry for Http Service
- */
- synchronized void init()
- {
- contextRegistry = contextRegistry.add(0L, new ContextRanking());
- }
-
- synchronized void shutdown()
- {
- removeAll();
- }
-
- synchronized void add(@Nonnull ServletContextHelperInfo info)
- {
- contextRegistry = contextRegistry.add(info);
- }
-
- synchronized void remove(@Nonnull ServletContextHelperInfo info)
- {
- contextRegistry = contextRegistry.remove(info);
- }
-
- synchronized void addServlet(final ServletHandler handler) throws RegistrationFailureException
- {
- if (this.allServletHandlers.contains(handler))
- {
- throw new RegistrationFailureException(handler.getServletInfo(), FAILURE_REASON_SERVICE_IN_USE,
- "Servlet instance " + handler.getName() + " already registered");
- }
-
- registerServlet(handler);
-
- this.allServletHandlers.add(handler);
- }
-
- private void registerServlet(ServletHandler handler) throws RegistrationFailureException
- {
- long contextId = handler.getContextServiceId();
- List<String> patterns = getFullPathsChecked(handler);
-
- Update<String> update = this.registeredServletHandlers.add(patterns, handler);
- initFirstHandler(update.getInit());
- contextRegistry = contextRegistry.updateServletMapping(update.getActivated(), update.getDeactivated(), contextId);
- destroyHandlers(update.getDestroy());
- }
-
- synchronized void removeAll()
- {
- Collection<ServletHandler> servletHandlers = this.contextRegistry.getServletHandlers();
-
- this.contextRegistry = new ContextRegistry();
-
- destroyHandlers(servletHandlers);
-
- this.allServletHandlers.clear();
- this.registeredServletHandlers.clear();
- }
-
- synchronized Servlet removeServlet(ServletInfo servletInfo)
- {
- return removeServlet(0L, servletInfo, true);
- }
-
- synchronized Servlet removeServlet(Long contextId, ServletInfo servletInfo)
- {
- return removeServlet(contextId, servletInfo, true);
- }
-
- synchronized Servlet removeServlet(Long contextId, ServletInfo servletInfo, final boolean destroy)
- {
- ServletHandler handler = getServletHandler(servletInfo);
- if (handler == null)
- {
- return null;
- }
-
- Servlet servlet = handler.getServlet();
-
- removeServlet(handler, destroy);
-
- if (destroy)
- {
- handler.destroy();
- }
-
-
- return servlet;
- }
-
- private ServletHandler getServletHandler(final ServletInfo servletInfo)
- {
- Iterator<ServletHandler> it = this.allServletHandlers.iterator();
- while (it.hasNext())
- {
- ServletHandler handler = it.next();
- if (handler.getServletInfo().compareTo(servletInfo) == 0)
- {
- return handler;
- }
- }
- return null;
- }
-
- synchronized void removeServlet(Servlet servlet, final boolean destroy)
- {
- Iterator<ServletHandler> it = this.allServletHandlers.iterator();
- List<ServletHandler> removals = new ArrayList<ServletHandler>();
- while (it.hasNext())
- {
- ServletHandler handler = it.next();
- if (handler.getServlet() != null && handler.getServlet() == servlet)
- {
- removals.add(handler);
- }
- }
-
- for (ServletHandler servletHandler : removals)
- {
- removeServlet(0L, servletHandler.getServletInfo(), destroy);
- }
- }
-
- private void removeServlet(ServletHandler handler, boolean destroy)
- {
- long contextId = handler.getContextServiceId();
- List<String> patterns = getFullPaths(handler);
- Update<String> update = this.registeredServletHandlers.remove(patterns, handler);
- Set<ServletHandler> initializedHandlers = initHandlers(update.getInit());
- Map<String, ServletHandler> activated = update.getActivated();
- activated = removeFailures(activated, initializedHandlers);
- contextRegistry = contextRegistry.updateServletMapping(activated, update.getDeactivated(), contextId);
- if (destroy)
- {
- destroyHandlers(update.getDestroy());
- }
- this.initFailures.remove(handler);
- this.allServletHandlers.remove(handler);
- }
-
- private Map<String, ServletHandler> removeFailures(Map<String, ServletHandler> activated,
- Set<ServletHandler> initializedHandlers)
- {
- if (activated.size() == initializedHandlers.size())
- {
- return activated;
- }
-
- Map<String, ServletHandler> result = new HashMap<String, ServletHandler>();
- for (Map.Entry<String, ServletHandler> entry : activated.entrySet())
- {
- if (initializedHandlers.contains(entry.getValue()))
- {
- result.put(entry.getKey(), entry.getValue());
- }
- }
- return result;
- }
-
- private List<String> getFullPathsChecked(ServletHandler handler) throws RegistrationFailureException
- {
- String contextPath = contextRegistry.getPath(handler.getContextServiceId());
- if (contextPath == null)
- {
- throw new RegistrationFailureException(handler.getServletInfo(), FAILURE_REASON_SERVLET_CONTEXT_FAILURE);
- }
- return getFullPaths(contextPath, handler);
- }
-
- private List<String> getFullPaths(ServletHandler handler)
- {
- String contextPath = contextRegistry.getPath(handler.getContextServiceId());
- return getFullPaths(contextPath, handler);
- }
-
- private List<String> getFullPaths(String contextPath, ServletHandler handler)
- {
- contextPath = contextPath.equals("/") ? "" : contextPath;
-
- List<String> patterns = new ArrayList<String>(asList(handler.getServletInfo().getPatterns()));
- for (int i = 0; i < patterns.size(); i++)
- {
- patterns.set(i, contextPath + patterns.get(i));
- }
- return patterns;
- }
-
- private void initFirstHandler(Collection<ServletHandler> handlers) throws RegistrationFailureException
- {
- if (handlers.isEmpty())
- {
- return;
- }
-
- ServletHandler handler = handlers.iterator().next();
- try
- {
- handler.init();
- }
- catch (ServletException e)
- {
- throw new RegistrationFailureException(handler.getServletInfo(), FAILURE_REASON_EXCEPTION_ON_INIT, e);
- }
- }
-
- private Set<ServletHandler> initHandlers(Collection<ServletHandler> handlers)
- {
- Set<ServletHandler> success = new TreeSet<ServletHandler>();
- List<ServletHandler> failure = new ArrayList<ServletHandler>();
- for (ServletHandler servletHandler : handlers)
- {
- try
- {
- servletHandler.init();
- success.add(servletHandler);
- }
- catch (ServletException e)
- {
- failure.add(servletHandler);
- }
- }
-
- this.initFailures.addAll(failure);
-
- return success;
- }
-
- private void destroyHandlers(Collection<? extends AbstractHandler<?>> servletHandlers)
- {
- for (AbstractHandler<?> handler : servletHandlers)
- {
- handler.destroy();
- }
- }
-
- ServletHandler getServletHandler(String requestURI)
- {
- return contextRegistry.getServletHandler(requestURI);
- }
-
- ServletHandler getServletHandlerByName(final Long contextId, @Nonnull final String name)
- {
- HandlerMapping<ServletHandler> servletMapping = contextRegistry.getServletMapping(contextId);
- return servletMapping != null ? servletMapping.getByName(name) : null;
- }
-
- synchronized ServletRegistryRuntime getRuntime(FailureRuntime.Builder failureRuntimeBuilder)
- {
- addFailures(failureRuntimeBuilder, this.registeredServletHandlers.getShadowedValues(), FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE);
- addFailures(failureRuntimeBuilder, this.initFailures, FAILURE_REASON_EXCEPTION_ON_INIT);
-
- Collection<ServletRuntime> servletRuntimes = new TreeSet<ServletRuntime>(ServletRuntime.COMPARATOR);
- Collection<ServletRuntime> resourceRuntimes = new TreeSet<ServletRuntime>(ServletRuntime.COMPARATOR);
- for (ServletHandler activeHandler : this.registeredServletHandlers.getActiveValues())
- {
- if (activeHandler.getServletInfo().isResource())
- {
- resourceRuntimes.add(activeHandler);
- }
- else
- {
- servletRuntimes.add(activeHandler);
- }
- }
- return new ServletRegistryRuntime(servletRuntimes, resourceRuntimes);
- }
-
- private void addFailures(FailureRuntime.Builder failureRuntimeBuilder, Collection<ServletHandler> handlers, int failureCode)
- {
- for (ServletHandler handler : handlers)
- {
- failureRuntimeBuilder.add(handler.getServletInfo(), failureCode);
- }
- }
-
- private class ServletHandlerComparator implements Comparator<ServletHandler>
- {
- @Override
- public int compare(ServletHandler o1, ServletHandler o2)
- {
- ContextRanking contextRankingOne = contextRegistry.getContextRanking(o1.getContextServiceId());
- ContextRanking contextRankingTwo = contextRegistry.getContextRanking(o2.getContextServiceId());
- int contextComparison = contextRankingOne.compareTo(contextRankingTwo);
- return contextComparison == 0 ? o1.compareTo(o2) : contextComparison;
- }
- }
-
- private static class ContextRegistry
- {
- private final Map<Long, ContextRanking> contextRankingsPerId;
- private final TreeSet<ContextRanking> contextRankings;
- private final Map<Long, HandlerMapping<ServletHandler>> servletMappingsPerContext;
-
- ContextRegistry()
- {
- this(new HashMap<Long, ContextRanking>(),
- new TreeSet<ContextRanking>(),
- new HashMap<Long, HandlerMapping<ServletHandler>>());
- }
-
- ContextRegistry(Map<Long, ContextRanking> contextRankingsPerId, TreeSet<ContextRanking> contextRankings, Map<Long, HandlerMapping<ServletHandler>> servletMappingsPerContext)
- {
- this.contextRankingsPerId = contextRankingsPerId;
- this.contextRankings = contextRankings;
- this.servletMappingsPerContext = servletMappingsPerContext;
- }
-
- ContextRanking getContextRanking(long contextServiceId)
- {
- return contextRankingsPerId.get(contextServiceId);
- }
-
- ServletHandler getServletHandler(String requestURI)
- {
- List<Long> contextIds = getContextId(requestURI);
- for (Long contextId : contextIds)
- {
- HandlerMapping<ServletHandler> servletMapping = this.servletMappingsPerContext.get(contextId);
- if (servletMapping != null)
- {
- ServletHandler bestMatch = servletMapping.getBestMatch(requestURI);
- if (bestMatch != null)
- {
- return bestMatch;
- }
- }
- }
- return null;
- }
-
- HandlerMapping<ServletHandler> getServletMapping(Long contextId)
- {
- return servletMappingsPerContext.get(contextId);
- }
-
- ContextRegistry add(long id, ContextRanking contextRanking)
- {
- Map<Long, ContextRanking> newContextRankingsPerId = new HashMap<Long, ContextRanking>(contextRankingsPerId);
- TreeSet<ContextRanking> newContextRankings = new TreeSet<ContextRanking>(contextRankings);
- Map<Long, HandlerMapping<ServletHandler>> newServletMappingsPerContext = new HashMap<Long, HandlerMapping<ServletHandler>>(servletMappingsPerContext);
- newContextRankingsPerId.put(id, contextRanking);
- newContextRankings.add(contextRanking);
- newServletMappingsPerContext.put(id, new HandlerMapping<ServletHandler>());
-
- return new ContextRegistry(newContextRankingsPerId, newContextRankings, newServletMappingsPerContext);
- }
-
- ContextRegistry add(ServletContextHelperInfo info)
- {
- return add(info.getServiceId(), new ContextRanking(info));
- }
-
- ContextRegistry remove(ServletContextHelperInfo info)
- {
- Map<Long, ContextRanking> newContextRankingsPerId = new HashMap<Long, ContextRanking>(contextRankingsPerId);
- TreeSet<ContextRanking> newContextRankings = new TreeSet<ContextRanking>(contextRankings);
- Map<Long, HandlerMapping<ServletHandler>> newServletMappingsPerContext = new HashMap<Long, HandlerMapping<ServletHandler>>(servletMappingsPerContext);
- newContextRankingsPerId.remove(info.getServiceId());
- newContextRankings.remove(new ContextRanking(info));
- newServletMappingsPerContext.remove(info.getServiceId());
-
- return new ContextRegistry(newContextRankingsPerId, newContextRankings, newServletMappingsPerContext);
- }
-
- String getPath(long contextId)
- {
- return contextRankingsPerId.get(contextId).path;
- }
-
- private List<Long> getContextId(String path)
- {
- List<Long> ids = new ArrayList<Long>();
- for (ContextRanking contextRanking : contextRankings)
- {
- if (contextRanking.isMatching(path))
- {
- ids.add(contextRanking.serviceId);
- }
- }
- return ids;
- }
-
- ContextRegistry updateServletMapping(Map<String, ServletHandler> activated, Map<String, ServletHandler> deactivated, long contextId)
- {
- Map<Long, HandlerMapping<ServletHandler>> newServletMappingsPerContext = new HashMap<Long, HandlerMapping<ServletHandler>>(servletMappingsPerContext);
- HandlerMapping<ServletHandler> servletMapping = newServletMappingsPerContext.get(contextId);
- if (servletMapping == null)
- {
- servletMapping = new HandlerMapping<ServletHandler>();
- }
- newServletMappingsPerContext.put(contextId, servletMapping.update(convert(activated), convert(deactivated)));
- return new ContextRegistry(contextRankingsPerId, contextRankings, newServletMappingsPerContext);
- }
-
- private Map<Pattern, ServletHandler> convert(Map<String, ServletHandler> mapping)
- {
- TreeMap<Pattern, ServletHandler> converted = new TreeMap<Pattern, ServletHandler>(PatternComparator.INSTANCE);
- for (Map.Entry<String, ServletHandler> entry : mapping.entrySet())
- {
- Pattern pattern = Pattern.compile(PatternUtil.convertToRegEx(entry.getKey()));
- converted.put(pattern, entry.getValue());
- }
- return converted;
- }
-
- Collection<ServletHandler> getServletHandlers()
- {
- Collection<ServletHandler> servletHandlers = new ArrayList<ServletHandler>();
- for (HandlerMapping<ServletHandler> servletMapping : this.servletMappingsPerContext.values())
- {
- servletHandlers.addAll(servletMapping.values());
- }
-
- return servletHandlers;
- }
- }
-
- // TODO combine with PerContextHandlerRegistry
- private static class ContextRanking implements Comparable<ContextRanking>
- {
- private final long serviceId;
- private final int ranking;
- private final String path;
-
- ContextRanking()
- {
- this.serviceId = 0;
- this.ranking = Integer.MAX_VALUE;
- this.path = "/";
- }
-
- ContextRanking(ServletContextHelperInfo info)
- {
- this.serviceId = info.getServiceId();
- this.ranking = info.getRanking();
- this.path = info.getPath();
- }
-
- @Override
- public int compareTo(ContextRanking other)
- {
- // the context of the HttpService is the least element
- if (this.serviceId == 0 ^ other.serviceId == 0)
- {
- return this.serviceId == 0 ? -1 : 1;
- }
-
- final int result = Integer.compare(other.path.length(), this.path.length());
- if ( result == 0 ) {
- if (this.ranking == other.ranking)
- {
- // 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 * Long.compare(this.serviceId, other.serviceId);
- }
-
- return Integer.compare(other.ranking, this.ranking);
- }
- return result;
- }
-
- boolean isMatching(final String requestURI)
- {
- return "".equals(path) || "/".equals(path) || requestURI.startsWith(path);
- }
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/SimpleServletHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/SimpleServletHandler.java
deleted file mode 100644
index fe1d962..0000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/SimpleServletHandler.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.felix.http.base.internal.handler;
-
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-
-public final class SimpleServletHandler extends ServletHandler
-{
- private final Servlet servlet;
-
- public SimpleServletHandler(ExtServletContext context,
- ServletInfo servletInfo,
- Servlet servlet)
- {
- this(0, context, servletInfo, servlet);
- }
-
- public SimpleServletHandler(long contextServiceId,
- ExtServletContext context,
- ServletInfo servletInfo,
- Servlet servlet)
- {
- super(contextServiceId, context, servletInfo);
- this.servlet = servlet;
- }
-
- @Override
- public Servlet getServlet()
- {
- return servlet;
- }
-
- @Override
- public void init() throws ServletException
- {
- servlet.init(new ServletConfigImpl(getName(), getContext(), getInitParams()));
- }
-
- @Override
- public void destroy()
- {
- servlet.destroy();
- }
-
- @Override
- protected Object getSubject()
- {
- return servlet;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardFilterHolder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardFilterHandler.java
similarity index 92%
rename from http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardFilterHolder.java
rename to http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardFilterHandler.java
index cc794c8..698cbf4 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardFilterHolder.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardFilterHandler.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.felix.http.base.internal.handler.holder;
+package org.apache.felix.http.base.internal.handler;
import javax.servlet.Filter;
@@ -27,11 +27,11 @@
/**
* Filter holder for filters registered through the http whiteboard.
*/
-public final class WhiteboardFilterHolder extends FilterHolder
+public final class WhiteboardFilterHandler extends FilterHandler
{
private final BundleContext bundleContext;
- public WhiteboardFilterHolder(final long contextServiceId,
+ public WhiteboardFilterHandler(final long contextServiceId,
final ExtServletContext context,
final FilterInfo filterInfo,
final BundleContext bundleContext)
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardServletHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardServletHandler.java
index 920f7b7..25d8792 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardServletHandler.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardServletHandler.java
@@ -17,85 +17,69 @@
package org.apache.felix.http.base.internal.handler;
import javax.servlet.Servlet;
-import javax.servlet.ServletException;
import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceObjects;
import org.osgi.framework.ServiceReference;
+/**
+ * Servlet handler for servlets registered through the http whiteboard.
+ */
public final class WhiteboardServletHandler extends ServletHandler
{
private final BundleContext bundleContext;
- private Servlet servlet;
-
- public WhiteboardServletHandler(ServletContextHelperInfo contextInfo,
- ExtServletContext context,
- ServletInfo servletInfo,
- BundleContext bundleContext)
+ public WhiteboardServletHandler(final long contextServiceId,
+ final ExtServletContext context,
+ final ServletInfo servletInfo,
+ final BundleContext bundleContext)
{
- super(contextInfo.getServiceId(), context, checkIsResource(servletInfo, false));
+ super(contextServiceId, context, servletInfo);
this.bundleContext = bundleContext;
}
@Override
- public Servlet getServlet()
+ public int init()
{
- return servlet;
+ if ( this.useCount > 0 )
+ {
+ this.useCount++;
+ return -1;
+ }
+
+ final ServiceReference<Servlet> serviceReference = getServletInfo().getServiceReference();
+ final ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(serviceReference);
+
+ this.setServlet((so == null ? null : so.getService()));
+
+ final int reason = super.init();
+ if ( reason != -1 )
+ {
+ so.ungetService(this.getServlet());
+ this.setServlet(null);
+ }
+ return reason;
}
@Override
- protected Object getSubject()
+ public boolean destroy()
{
- return getServlet();
- }
-
- @Override
- public void init() throws ServletException
- {
- if (servlet != null)
+ final Servlet s = this.getServlet();
+ if ( s != null )
{
- return;
+ if ( super.destroy() )
+ {
+
+ final ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(getServletInfo().getServiceReference());
+ if (so != null)
+ {
+ so.ungetService(s);
+ }
+ return true;
+ }
}
-
- ServiceReference<Servlet> serviceReference = getServletInfo().getServiceReference();
- ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(serviceReference);
-
- servlet = so.getService();
-
- if (servlet == null)
- {
- // TODO throw Exception - service ungettable ?
- return;
- }
-
- try {
- servlet.init(new ServletConfigImpl(getName(), getContext(), getInitParams()));
- } catch (ServletException e) {
- so.ungetService(servlet);
- throw e;
- }
- }
-
- @Override
- public void destroy()
- {
- if (servlet == null)
- {
- return;
- }
-
- servlet.destroy();
-
- ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(getServletInfo().getServiceReference());
- // TODO check if this is needed
- if (so != null)
- {
- so.ungetService(servlet);
- }
- servlet = null;
+ return false;
}
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/FilterHolder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/FilterHolder.java
deleted file mode 100644
index 71261f2..0000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/FilterHolder.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * 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.felix.http.base.internal.handler.holder;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import javax.annotation.Nonnull;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.handler.FilterConfigImpl;
-import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.apache.felix.http.base.internal.runtime.FilterInfo;
-import org.apache.felix.http.base.internal.runtime.dto.FilterRuntime;
-import org.apache.felix.http.base.internal.util.PatternUtil;
-import org.osgi.service.http.runtime.dto.DTOConstants;
-
-/**
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class FilterHolder implements Comparable<FilterHolder>, FilterRuntime
-{
- private final long contextServiceId;
-
- private final FilterInfo filterInfo;
-
- private final ExtServletContext context;
-
- private volatile Filter filter;
-
- protected volatile int useCount;
-
- private final Pattern[] patterns;
-
- public FilterHolder(final long contextServiceId,
- final ExtServletContext context,
- final FilterInfo filterInfo)
- {
- this.contextServiceId = contextServiceId;
- this.context = context;
- this.filterInfo = filterInfo;
- // Compose a single array of all patterns & regexs the filter must represent...
- String[] patterns = getFilterPatterns(filterInfo);
-
- this.patterns = new Pattern[patterns.length];
- for (int i = 0; i < patterns.length; i++)
- {
- this.patterns[i] = Pattern.compile(patterns[i]);
- }
- }
-
- private static String[] getFilterPatterns(FilterInfo filterInfo)
- {
- List<String> result = new ArrayList<String>();
- if (filterInfo.getPatterns() != null)
- {
- for (int i = 0; i < filterInfo.getPatterns().length; i++)
- {
- result.add(PatternUtil.convertToRegEx(filterInfo.getPatterns()[i]));
- }
- }
- if (filterInfo.getRegexs() != null)
- {
- for (int i = 0; i < filterInfo.getRegexs().length; i++)
- {
- result.add(filterInfo.getRegexs()[i]);
- }
- }
- return result.toArray(new String[result.size()]);
- }
-
- public Pattern[] getPatterns() {
- return this.patterns;
- }
-
- @Override
- public int compareTo(final FilterHolder other)
- {
- return this.filterInfo.compareTo(other.filterInfo);
- }
-
- @Override
- public long getContextServiceId()
- {
- return this.contextServiceId;
- }
-
- public ExtServletContext getContext()
- {
- return this.context;
- }
-
- public Filter getFilter()
- {
- return filter;
- }
-
- protected void setFilter(final Filter f)
- {
- this.filter = f;
- }
-
- @Override
- public FilterInfo getFilterInfo()
- {
- return this.filterInfo;
- }
-
- public String getName()
- {
- String name = this.filterInfo.getName();
- if (name == null)
- {
- name = filter.getClass().getName();
- }
- return name;
- }
-
- /**
- * Initialize the object
- * @return {code -1} on success, a failure reason according to {@link DTOConstants} otherwise.
- */
- public int init()
- {
- if ( this.useCount > 0 )
- {
- this.useCount++;
- return -1;
- }
-
- if (this.filter == null)
- {
- return DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE;
- }
-
- try
- {
- filter.init(new FilterConfigImpl(getName(), getContext(), getFilterInfo().getInitParameters()));
- }
- catch (final ServletException e)
- {
- SystemLogger.error(this.getFilterInfo().getServiceReference(),
- "Error during calling init() on filter " + this.filter,
- e);
- return DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT;
- }
- this.useCount++;
- return -1;
- }
-
- public void handle(@Nonnull final ServletRequest req,
- @Nonnull final ServletResponse res,
- @Nonnull final FilterChain chain) throws ServletException, IOException
- {
- this.filter.doFilter(req, res, chain);
- }
-
- public boolean destroy()
- {
- if (this.filter == null)
- {
- return false;
- }
-
- this.useCount--;
- if ( this.useCount == 0 )
- {
- try
- {
- filter.destroy();
- }
- catch ( final Exception ignore )
- {
- // we ignore this
- SystemLogger.error(this.getFilterInfo().getServiceReference(),
- "Error during calling destroy() on filter " + this.filter,
- ignore);
- }
-
- filter = null;
- return true;
- }
- return false;
- }
-
- public boolean dispose()
- {
- // fully destroy the filter
- this.useCount = 1;
- return this.destroy();
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/ServletHolder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/ServletHolder.java
deleted file mode 100644
index ead0b94..0000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/ServletHolder.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * 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.felix.http.base.internal.handler.holder;
-
-import java.io.IOException;
-
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.handler.ServletConfigImpl;
-import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.apache.felix.http.base.internal.runtime.dto.ServletRuntime;
-import org.osgi.service.http.runtime.dto.DTOConstants;
-
-/**
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public abstract class ServletHolder implements Comparable<ServletHolder>, ServletRuntime
-{
- private final long contextServiceId;
-
- private final ServletInfo servletInfo;
-
- private final ExtServletContext context;
-
- private volatile Servlet servlet;
-
- protected volatile int useCount;
-
- public ServletHolder(final long contextServiceId,
- final ExtServletContext context,
- final ServletInfo servletInfo)
- {
- this.contextServiceId = contextServiceId;
- this.context = context;
- this.servletInfo = servletInfo;
- }
-
- @Override
- public int compareTo(final ServletHolder other)
- {
- return this.servletInfo.compareTo(other.servletInfo);
- }
-
- @Override
- public long getContextServiceId()
- {
- return this.contextServiceId;
- }
-
- public ExtServletContext getContext()
- {
- return this.context;
- }
-
- @Override
- public Servlet getServlet()
- {
- return servlet;
- }
-
- protected void setServlet(final Servlet s)
- {
- this.servlet = s;
- }
-
- public void handle(final ServletRequest req, final ServletResponse res)
- throws ServletException, IOException
- {
- this.servlet.service(req, res);
- }
-
- @Override
- public ServletInfo getServletInfo()
- {
- return this.servletInfo;
- }
-
- public String getName()
- {
- String name = this.servletInfo.getName();
- if (name == null)
- {
- name = servlet.getClass().getName();
- }
- return name;
- }
-
- /**
- * Initialize the object
- * @return {code -1} on success, a failure reason according to {@link DTOConstants} otherwise.
- */
- public int init()
- {
- if ( this.useCount > 0 )
- {
- this.useCount++;
- return -1;
- }
-
- if (this.servlet == null)
- {
- return DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE;
- }
-
- try
- {
- servlet.init(new ServletConfigImpl(getName(), getContext(), getServletInfo().getInitParameters()));
- }
- catch (final ServletException e)
- {
- SystemLogger.error(this.getServletInfo().getServiceReference(),
- "Error during calling init() on servlet " + this.servlet,
- e);
- return DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT;
- }
- this.useCount++;
- return -1;
- }
-
-
- public boolean destroy()
- {
- if (this.servlet == null)
- {
- return false;
- }
-
- this.useCount--;
- if ( this.useCount == 0 )
- {
- try
- {
- servlet.destroy();
- }
- catch ( final Exception ignore )
- {
- // we ignore this
- SystemLogger.error(this.getServletInfo().getServiceReference(),
- "Error during calling destroy() on servlet " + this.servlet,
- ignore);
- }
-
- servlet = null;
- return true;
- }
- return false;
- }
-
- public boolean dispose()
- {
- // fully destroy the servlet
- this.useCount = 1;
- return this.destroy();
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardServletHolder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardServletHolder.java
deleted file mode 100644
index 8aea9b0..0000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardServletHolder.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.felix.http.base.internal.handler.holder;
-
-import javax.servlet.Servlet;
-
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceObjects;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Servlet holder for servlets registered through the http whiteboard.
- */
-public final class WhiteboardServletHolder extends ServletHolder
-{
- private final BundleContext bundleContext;
-
- public WhiteboardServletHolder(final long contextServiceId,
- final ExtServletContext context,
- final ServletInfo servletInfo,
- final BundleContext bundleContext)
- {
- super(contextServiceId, context, servletInfo);
- this.bundleContext = bundleContext;
- }
-
- @Override
- public int init()
- {
- if ( this.useCount > 0 )
- {
- this.useCount++;
- return -1;
- }
-
- final ServiceReference<Servlet> serviceReference = getServletInfo().getServiceReference();
- final ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(serviceReference);
-
- this.setServlet((so == null ? null : so.getService()));
-
- final int reason = super.init();
- if ( reason != -1 )
- {
- so.ungetService(this.getServlet());
- this.setServlet(null);
- }
- return reason;
- }
-
- @Override
- public boolean destroy()
- {
- final Servlet s = this.getServlet();
- if ( s != null )
- {
- if ( super.destroy() )
- {
-
- final ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(getServletInfo().getServiceReference());
- if (so != null)
- {
- so.ungetService(s);
- }
- return true;
- }
- }
- return false;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ErrorPageRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ErrorPageRegistry.java
index b544653..abd1b16 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ErrorPageRegistry.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ErrorPageRegistry.java
@@ -30,7 +30,7 @@
import javax.annotation.Nonnull;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
import org.apache.felix.http.base.internal.runtime.dto.ErrorPageRuntime;
import org.apache.felix.http.base.internal.runtime.dto.ServletRuntime;
@@ -76,8 +76,8 @@
return null;
}
- private final Map<Long, List<ServletHolder>> errorCodesMap = new ConcurrentHashMap<Long, List<ServletHolder>>();
- private final Map<String, List<ServletHolder>> exceptionsMap = new ConcurrentHashMap<String, List<ServletHolder>>();
+ private final Map<Long, List<ServletHandler>> errorCodesMap = new ConcurrentHashMap<Long, List<ServletHandler>>();
+ private final Map<String, List<ServletHandler>> exceptionsMap = new ConcurrentHashMap<String, List<ServletHandler>>();
private final Map<ServletInfo, ErrorRegistrationStatus> statusMapping = new ConcurrentHashMap<ServletInfo, ErrorRegistrationStatus>();
@@ -87,7 +87,7 @@
}
private static final class ErrorRegistrationStatus {
- ServletHolder holder;
+ ServletHandler holder;
final Map<Long, Integer> errorCodeMapping = new ConcurrentHashMap<Long, Integer>();
final Map<String, Integer> exceptionMapping = new ConcurrentHashMap<String, Integer>();
}
@@ -114,7 +114,7 @@
* Add the servlet for error handling
* @param holder The servlet holder.
*/
- public void addServlet(@Nonnull final ServletHolder holder)
+ public void addServlet(@Nonnull final ServletHandler holder)
{
final ErrorRegistration reg = getErrorRegistration(holder.getServletInfo());
if ( reg != null )
@@ -123,20 +123,20 @@
status.holder = holder;
for(final long code : reg.errorCodes)
{
- List<ServletHolder> list = errorCodesMap.get(code);
+ List<ServletHandler> list = errorCodesMap.get(code);
if ( list == null )
{
// activate
if ( tryToActivate(code, holder, status) )
{
- final List<ServletHolder> newList = new ArrayList<ServletHolder>(1);
+ final List<ServletHandler> newList = new ArrayList<ServletHandler>(1);
newList.add(holder);
errorCodesMap.put(code, newList);
}
}
else
{
- final List<ServletHolder> newList = new ArrayList<ServletHolder>(list);
+ final List<ServletHandler> newList = new ArrayList<ServletHandler>(list);
newList.add(holder);
Collections.sort(newList);
@@ -145,7 +145,7 @@
// activate and reactive
if ( tryToActivate(code, holder, status) )
{
- final ServletHolder old = list.get(0);
+ final ServletHandler old = list.get(0);
old.destroy();
errorCodesMap.put(code, newList);
}
@@ -160,20 +160,20 @@
}
for(final String exception : reg.exceptions)
{
- List<ServletHolder> list = exceptionsMap.get(exception);
+ List<ServletHandler> list = exceptionsMap.get(exception);
if ( list == null )
{
// activate
if ( tryToActivate(exception, holder, status) )
{
- final List<ServletHolder> newList = new ArrayList<ServletHolder>(1);
+ final List<ServletHandler> newList = new ArrayList<ServletHandler>(1);
newList.add(holder);
exceptionsMap.put(exception, newList);
}
}
else
{
- final List<ServletHolder> newList = new ArrayList<ServletHolder>(list);
+ final List<ServletHandler> newList = new ArrayList<ServletHandler>(list);
newList.add(holder);
Collections.sort(newList);
@@ -182,7 +182,7 @@
// activate and reactive
if ( tryToActivate(exception, holder, status) )
{
- final ServletHolder old = list.get(0);
+ final ServletHandler old = list.get(0);
old.destroy();
exceptionsMap.put(exception, newList);
}
@@ -211,19 +211,19 @@
this.statusMapping.remove(info);
for(final long code : reg.errorCodes)
{
- final List<ServletHolder> list = errorCodesMap.get(code);
+ final List<ServletHandler> list = errorCodesMap.get(code);
if ( list != null )
{
int index = 0;
- final Iterator<ServletHolder> i = list.iterator();
+ final Iterator<ServletHandler> i = list.iterator();
while ( i.hasNext() )
{
- final ServletHolder holder = i.next();
+ final ServletHandler holder = i.next();
if ( holder.getServletInfo().equals(info) )
{
holder.destroy();
- final List<ServletHolder> newList = new ArrayList<ServletHolder>(list);
+ final List<ServletHandler> newList = new ArrayList<ServletHandler>(list);
newList.remove(holder);
if ( index == 0 )
@@ -231,7 +231,7 @@
index++;
while ( index < list.size() )
{
- final ServletHolder next = list.get(index);
+ final ServletHandler next = list.get(index);
if ( tryToActivate(code, next, statusMapping.get(next.getServletInfo())) )
{
break;
@@ -259,19 +259,19 @@
}
for(final String exception : reg.exceptions)
{
- final List<ServletHolder> list = exceptionsMap.get(exception);
+ final List<ServletHandler> list = exceptionsMap.get(exception);
if ( list != null )
{
int index = 0;
- final Iterator<ServletHolder> i = list.iterator();
+ final Iterator<ServletHandler> i = list.iterator();
while ( i.hasNext() )
{
- final ServletHolder holder = i.next();
+ final ServletHandler holder = i.next();
if ( holder.getServletInfo().equals(info) )
{
holder.destroy();
- final List<ServletHolder> newList = new ArrayList<ServletHolder>(list);
+ final List<ServletHandler> newList = new ArrayList<ServletHandler>(list);
newList.remove(holder);
if ( index == 0 )
@@ -279,7 +279,7 @@
index++;
while ( index < list.size() )
{
- final ServletHolder next = list.get(index);
+ final ServletHandler next = list.get(index);
if ( tryToActivate(exception, next, statusMapping.get(next.getServletInfo())) )
{
break;
@@ -314,9 +314,9 @@
* @param errorCode Error code
* @return The servlet handling the error or {@code null}
*/
- public ServletHolder get(final Throwable exception, final int errorCode)
+ public ServletHandler get(final Throwable exception, final int errorCode)
{
- ServletHolder errorHandler = this.get(exception);
+ ServletHandler errorHandler = this.get(exception);
if (errorHandler != null)
{
return errorHandler;
@@ -325,9 +325,9 @@
return get(errorCode);
}
- private ServletHolder get(final int errorCode)
+ private ServletHandler get(final int errorCode)
{
- final List<ServletHolder> list = this.errorCodesMap.get(errorCode);
+ final List<ServletHandler> list = this.errorCodesMap.get(errorCode);
if ( list != null )
{
return list.get(0);
@@ -335,18 +335,18 @@
return null;
}
- private ServletHolder get(final Throwable exception)
+ private ServletHandler get(final Throwable exception)
{
if (exception == null)
{
return null;
}
- ServletHolder servletHandler = null;
+ ServletHandler servletHandler = null;
Class<?> throwableClass = exception.getClass();
while ( servletHandler == null && throwableClass != null )
{
- final List<ServletHolder> list = this.errorCodesMap.get(throwableClass.getName());
+ final List<ServletHandler> list = this.errorCodesMap.get(throwableClass.getName());
if ( list != null )
{
servletHandler = list.get(0);
@@ -364,7 +364,7 @@
return servletHandler;
}
- private boolean tryToActivate(final Long code, final ServletHolder holder, final ErrorRegistrationStatus status)
+ private boolean tryToActivate(final Long code, final ServletHandler holder, final ErrorRegistrationStatus status)
{
// add to active
final int result = holder.init();
@@ -373,7 +373,7 @@
return result == -1;
}
- private boolean tryToActivate(final String exception, final ServletHolder holder, final ErrorRegistrationStatus status)
+ private boolean tryToActivate(final String exception, final ServletHandler holder, final ErrorRegistrationStatus status)
{
// add to active
final int result = holder.init();
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/FilterRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/FilterRegistry.java
index 830977e..f003b35 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/FilterRegistry.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/FilterRegistry.java
@@ -29,8 +29,8 @@
import javax.annotation.Nonnull;
import javax.servlet.DispatcherType;
-import org.apache.felix.http.base.internal.handler.holder.FilterHolder;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
+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.FilterInfo;
import org.apache.felix.http.base.internal.runtime.dto.FailureRuntime;
import org.apache.felix.http.base.internal.runtime.dto.FilterRuntime;
@@ -44,10 +44,10 @@
private static final class FilterRegistrationStatus
{
public int result;
- public FilterHolder holder;
+ public FilterHandler holder;
}
- public void addFilter(@Nonnull final FilterHolder holder)
+ public void addFilter(@Nonnull final FilterHandler holder)
{
final int result = holder.init();
if ( result == -1 )
@@ -77,16 +77,16 @@
}
}
- public FilterHolder[] getFilterHolders(@CheckForNull final ServletHolder holder,
+ public FilterHandler[] getFilterHandlers(@CheckForNull final ServletHandler holder,
@CheckForNull DispatcherType dispatcherType,
@Nonnull String requestURI)
{
// See Servlet 3.0 specification, section 6.2.4...
- final List<FilterHolder> result = new ArrayList<FilterHolder>();
+ final List<FilterHandler> result = new ArrayList<FilterHandler>();
result.addAll(this.filterMapping.getAllMatches(requestURI));
// TODO this is not the most efficient/fastest way of doing this...
- Iterator<FilterHolder> iter = result.iterator();
+ Iterator<FilterHandler> iter = result.iterator();
while (iter.hasNext())
{
if (!referencesDispatcherType(iter.next(), dispatcherType))
@@ -97,7 +97,7 @@
final String servletName = (holder != null) ? holder.getName() : null;
// TODO this is not the most efficient/fastest way of doing this...
- for (FilterHolder filterHandler : this.filterMapping.values())
+ for (FilterHandler filterHandler : this.filterMapping.values())
{
if (referencesServletByName(filterHandler, servletName))
{
@@ -105,10 +105,10 @@
}
}
- return result.toArray(new FilterHolder[result.size()]);
+ return result.toArray(new FilterHandler[result.size()]);
}
- private boolean referencesDispatcherType(FilterHolder holder, DispatcherType dispatcherType)
+ private boolean referencesDispatcherType(FilterHandler holder, DispatcherType dispatcherType)
{
if (dispatcherType == null)
{
@@ -117,7 +117,7 @@
return Arrays.asList(holder.getFilterInfo().getDispatcher()).contains(dispatcherType);
}
- private boolean referencesServletByName(FilterHolder handler, String servletName)
+ private boolean referencesServletByName(FilterHandler handler, String servletName)
{
if (servletName == null)
{
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerMapping.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerMapping.java
index db3d367..c8bf74e 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerMapping.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerMapping.java
@@ -35,7 +35,7 @@
import javax.annotation.Nonnull;
-import org.apache.felix.http.base.internal.handler.holder.FilterHolder;
+import org.apache.felix.http.base.internal.handler.FilterHandler;
import org.apache.felix.http.base.internal.util.PatternUtil;
import org.apache.felix.http.base.internal.util.PatternUtil.PatternComparator;
@@ -50,16 +50,16 @@
*/
public final class HandlerMapping
{
- private final SortedMap<Pattern, Set<FilterHolder>> exactMap;
- private final SortedMap<Pattern, Set<FilterHolder>> wildcardMap;
- private final Set<FilterHolder> mappedHandlers;
+ private final SortedMap<Pattern, Set<FilterHandler>> exactMap;
+ private final SortedMap<Pattern, Set<FilterHandler>> wildcardMap;
+ private final Set<FilterHandler> mappedHandlers;
/**
* Creates a new, empty, {@link HandlerMapping} instance.
*/
public HandlerMapping()
{
- this(Collections.<Pattern, Collection<FilterHolder>>emptyMap());
+ this(Collections.<Pattern, Collection<FilterHandler>>emptyMap());
}
/**
@@ -67,35 +67,35 @@
*
* @param mappings the elements to map.
*/
- private HandlerMapping(@Nonnull final Map<Pattern, Collection<FilterHolder>> mappings)
+ private HandlerMapping(@Nonnull final Map<Pattern, Collection<FilterHandler>> mappings)
{
- this.exactMap = new TreeMap<Pattern, Set<FilterHolder>>(PatternComparator.INSTANCE);
- this.wildcardMap = new TreeMap<Pattern, Set<FilterHolder>>(PatternComparator.INSTANCE);
- this.mappedHandlers = new TreeSet<FilterHolder>();
+ this.exactMap = new TreeMap<Pattern, Set<FilterHandler>>(PatternComparator.INSTANCE);
+ this.wildcardMap = new TreeMap<Pattern, Set<FilterHandler>>(PatternComparator.INSTANCE);
+ this.mappedHandlers = new TreeSet<FilterHandler>();
- for (Map.Entry<Pattern, Collection<FilterHolder>> mapping : mappings.entrySet())
+ for (Map.Entry<Pattern, Collection<FilterHandler>> mapping : mappings.entrySet())
{
Pattern pattern = mapping.getKey();
- Collection<FilterHolder> handlers = mapping.getValue();
+ Collection<FilterHandler> handlers = mapping.getValue();
mappedHandlers.addAll(handlers);
if (PatternUtil.isWildcardPattern(pattern))
{
- Set<FilterHolder> vs = this.wildcardMap.get(pattern);
+ Set<FilterHandler> vs = this.wildcardMap.get(pattern);
if (vs == null)
{
- vs = new TreeSet<FilterHolder>();
+ vs = new TreeSet<FilterHandler>();
this.wildcardMap.put(pattern, vs);
}
vs.addAll(handlers);
}
else
{
- Set<FilterHolder> vs = this.exactMap.get(pattern);
+ Set<FilterHandler> vs = this.exactMap.get(pattern);
if (vs == null)
{
- vs = new TreeSet<FilterHolder>();
+ vs = new TreeSet<FilterHandler>();
this.exactMap.put(pattern, vs);
}
vs.addAll(handlers);
@@ -111,9 +111,9 @@
* @return a new {@link HandlerMapping} instance with a mapping for the
* given handler.
*/
- public HandlerMapping add(@Nonnull final FilterHolder handler)
+ public HandlerMapping add(@Nonnull final FilterHandler handler)
{
- final Map<Pattern, FilterHolder> mappings = new TreeMap<Pattern, FilterHolder>(PatternComparator.INSTANCE);
+ final Map<Pattern, FilterHandler> mappings = new TreeMap<Pattern, FilterHandler>(PatternComparator.INSTANCE);
for (final Pattern pattern : handler.getPatterns())
{
mappings.put(pattern, handler);
@@ -121,9 +121,9 @@
return add(mappings);
}
- HandlerMapping add(@Nonnull final Map<Pattern, FilterHolder> mappings)
+ HandlerMapping add(@Nonnull final Map<Pattern, FilterHandler> mappings)
{
- final Map<Pattern, Collection<FilterHolder>> newMappings = getAllMappings();
+ final Map<Pattern, Collection<FilterHandler>> newMappings = getAllMappings();
addMappings(mappings, newMappings);
return new HandlerMapping(newMappings);
}
@@ -136,9 +136,9 @@
* @return a new {@link HandlerMapping} instance without a mapping for the
* given handler.
*/
- public HandlerMapping remove(FilterHolder handler)
+ public HandlerMapping remove(FilterHandler handler)
{
- Map<Pattern, FilterHolder> mappings = new TreeMap<Pattern, FilterHolder>(PatternComparator.INSTANCE);
+ Map<Pattern, FilterHandler> mappings = new TreeMap<Pattern, FilterHandler>(PatternComparator.INSTANCE);
for (Pattern pattern : handler.getPatterns())
{
mappings.put(pattern, handler);
@@ -146,38 +146,38 @@
return remove(mappings);
}
- HandlerMapping remove(Map<Pattern, FilterHolder> mappings)
+ HandlerMapping remove(Map<Pattern, FilterHandler> mappings)
{
- Map<Pattern, Collection<FilterHolder>> newMappings = getAllMappings();
+ Map<Pattern, Collection<FilterHandler>> newMappings = getAllMappings();
removeMappings(mappings, newMappings);
return new HandlerMapping(newMappings);
}
- HandlerMapping update(Map<Pattern, FilterHolder> add, Map<Pattern, FilterHolder> remove)
+ HandlerMapping update(Map<Pattern, FilterHandler> add, Map<Pattern, FilterHandler> remove)
{
- Map<Pattern, Collection<FilterHolder>> newMappings = getAllMappings();
+ Map<Pattern, Collection<FilterHandler>> newMappings = getAllMappings();
removeMappings(remove, newMappings);
addMappings(add, newMappings);
return new HandlerMapping(newMappings);
}
- private void addMappings(Map<Pattern, FilterHolder> mappings, Map<Pattern, Collection<FilterHolder>> target)
+ private void addMappings(Map<Pattern, FilterHandler> mappings, Map<Pattern, Collection<FilterHandler>> target)
{
- for (Map.Entry<Pattern, FilterHolder> mapping : mappings.entrySet())
+ for (Map.Entry<Pattern, FilterHandler> mapping : mappings.entrySet())
{
if (!target.containsKey(mapping.getKey()))
{
- target.put(mapping.getKey(), new TreeSet<FilterHolder>());
+ target.put(mapping.getKey(), new TreeSet<FilterHandler>());
}
target.get(mapping.getKey()).add(mapping.getValue());
}
}
- private void removeMappings(Map<Pattern, FilterHolder> mappings, Map<Pattern, Collection<FilterHolder>> target)
+ private void removeMappings(Map<Pattern, FilterHandler> mappings, Map<Pattern, Collection<FilterHandler>> target)
{
- for (Map.Entry<Pattern, FilterHolder> mapping : mappings.entrySet())
+ for (Map.Entry<Pattern, FilterHandler> mapping : mappings.entrySet())
{
- Collection<FilterHolder> mappedHandlers = target.get(mapping.getKey());
+ Collection<FilterHandler> mappedHandlers = target.get(mapping.getKey());
if (mappedHandlers == null)
{
continue;
@@ -190,9 +190,9 @@
}
}
- private Map<Pattern, Collection<FilterHolder>> getAllMappings()
+ private Map<Pattern, Collection<FilterHandler>> getAllMappings()
{
- Map<Pattern, Collection<FilterHolder>> newMappings = new TreeMap<Pattern, Collection<FilterHolder>>(PatternComparator.INSTANCE);
+ Map<Pattern, Collection<FilterHandler>> newMappings = new TreeMap<Pattern, Collection<FilterHandler>>(PatternComparator.INSTANCE);
newMappings.putAll(exactMap);
newMappings.putAll(wildcardMap);
return newMappings;
@@ -205,7 +205,7 @@
* <code>Collection</code> is unmodifiable and never
* <code>null</code>.
*/
- public Collection<FilterHolder> values()
+ public Collection<FilterHandler> values()
{
return unmodifiableCollection(mappedHandlers);
}
@@ -216,7 +216,7 @@
* @return <code>true</code> if the handlers contains the specified handler,
* <code>false</code> otherwise
*/
- public boolean contains(FilterHolder handler)
+ public boolean contains(FilterHandler handler)
{
return mappedHandlers.contains(handler);
}
@@ -227,7 +227,7 @@
* @param path the path that should match, cannot be <code>null</code>.
* @return a {@link Collection} of all matching handlers, never <code>null</code>.
*/
- public List<FilterHolder> getAllMatches(String path)
+ public List<FilterHandler> getAllMatches(String path)
{
return getAllMatches(path, false /* firstOnly */);
}
@@ -245,9 +245,9 @@
* @param path the path that should match, cannot be <code>null</code>.
* @return the best matching handler for the given path, or <code>null</code> in case no handler matched.
*/
- FilterHolder getBestMatch(String path)
+ FilterHandler getBestMatch(String path)
{
- List<FilterHolder> allMatches = getAllMatches(path, true /* firstOnly */);
+ List<FilterHandler> allMatches = getAllMatches(path, true /* firstOnly */);
return allMatches.isEmpty() ? null : allMatches.get(0);
}
@@ -257,14 +257,14 @@
* @param name the name of the handler to return, can be <code>null</code> in which case this method will return <code>null</code>.
* @return the element with the given name, or <code>null</code> if not found, or the given argument was <code>null</code>.
*/
- FilterHolder getByName(String name)
+ FilterHandler getByName(String name)
{
if (name == null)
{
return null;
}
- for (FilterHolder element : this.mappedHandlers)
+ for (FilterHandler element : this.mappedHandlers)
{
if (name.equals(element.getName()))
{
@@ -294,38 +294,38 @@
* <code>false</code> if all matching patterns should be returned.
* @return a list with matching elements, never <code>null</code>.
*/
- private List<FilterHolder> getAllMatches(String path, boolean firstOnly)
+ private List<FilterHandler> getAllMatches(String path, boolean firstOnly)
{
path = (path == null) ? "" : path.trim();
- Set<FilterHolder> result = new TreeSet<FilterHolder>();
+ Set<FilterHandler> result = new TreeSet<FilterHandler>();
// Look for exact matches only, that is, those patterns without wildcards...
- for (Entry<Pattern, Set<FilterHolder>> entry : this.exactMap.entrySet())
+ for (Entry<Pattern, Set<FilterHandler>> entry : this.exactMap.entrySet())
{
Matcher matcher = entry.getKey().matcher(path);
// !!! we should always match the *entire* pattern, instead of the longest prefix...
if (matcher.matches())
{
- Set<FilterHolder> vs = entry.getValue();
- for (FilterHolder v : vs)
+ Set<FilterHandler> vs = entry.getValue();
+ for (FilterHandler v : vs)
{
result.add(v);
if (firstOnly)
{
- return new ArrayList<FilterHolder>(result);
+ return new ArrayList<FilterHandler>(result);
}
}
}
}
// Try to apply the wildcard patterns...
- for (Entry<Pattern, Set<FilterHolder>> entry : this.wildcardMap.entrySet())
+ for (Entry<Pattern, Set<FilterHandler>> entry : this.wildcardMap.entrySet())
{
Matcher matcher = entry.getKey().matcher(path);
if (matcher.find(0))
{
- Set<FilterHolder> vs = entry.getValue();
- for (FilterHolder v : vs)
+ Set<FilterHandler> vs = entry.getValue();
+ for (FilterHandler v : vs)
{
result.add(v);
@@ -337,6 +337,6 @@
}
}
- return new ArrayList<FilterHolder>(result);
+ return new ArrayList<FilterHandler>(result);
}
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java
index 8c81895..d02dfaa 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java
@@ -19,8 +19,8 @@
import javax.annotation.Nonnull;
import javax.servlet.DispatcherType;
-import org.apache.felix.http.base.internal.handler.holder.FilterHolder;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
+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.FilterInfo;
import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
@@ -138,7 +138,7 @@
return this.servletRegistry.resolve(relativeRequestURI);
}
- public ServletHolder resolveServletByName(final String name)
+ public ServletHandler resolveServletByName(final String name)
{
return this.servletRegistry.resolveByName(name);
}
@@ -148,7 +148,7 @@
* @param holder The servlet holder
* @param info The servlet info
*/
- public void addServlet(@Nonnull final ServletHolder holder)
+ public void addServlet(@Nonnull final ServletHandler holder)
{
this.servletRegistry.addServlet(holder);
this.errorPageRegistry.addServlet(holder);
@@ -164,7 +164,7 @@
this.errorPageRegistry.removeServlet(info, destroy);
}
- public void addFilter(@Nonnull final FilterHolder holder)
+ public void addFilter(@Nonnull final FilterHandler holder)
{
this.filterRegistry.addFilter(holder);
}
@@ -174,13 +174,13 @@
this.filterRegistry.removeFilter(info, destroy);
}
- public FilterHolder[] getFilterHolders(final ServletHolder servletHolder,
+ public FilterHandler[] getFilterHandlers(final ServletHandler servletHandler,
DispatcherType dispatcherType, String requestURI)
{
- return this.filterRegistry.getFilterHolders(servletHolder, dispatcherType, requestURI);
+ return this.filterRegistry.getFilterHandlers(servletHandler, dispatcherType, requestURI);
}
- public ServletHolder getErrorHandler(int code, Throwable exception)
+ public ServletHandler getErrorHandler(int code, Throwable exception)
{
return this.errorPageRegistry.get(exception, code);
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistration.java
similarity index 80%
rename from http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletHandler.java
rename to http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistration.java
index cf88e06..805a487 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletHandler.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistration.java
@@ -21,26 +21,26 @@
import javax.annotation.Nonnull;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
import org.apache.felix.http.base.internal.util.UriUtils;
/**
* Servlet handler is registered with a pattern and a servlet holder
*/
-public class ServletHandler
+public class ServletRegistration
{
- private final ServletHolder holder;
+ private final ServletHandler handler;
private final Pattern pattern;
- public ServletHandler(@Nonnull final ServletHolder holder, @Nonnull final Pattern pattern)
+ public ServletRegistration(@Nonnull final ServletHandler handler, @Nonnull final Pattern pattern)
{
- this.holder = holder;
+ this.handler = handler;
this.pattern = pattern;
}
- public ServletHolder getServletHolder()
+ public ServletHandler getServletHandler()
{
- return this.holder;
+ return this.handler;
}
public PathResolution resolve(@Nonnull final String requestURI)
@@ -51,7 +51,7 @@
final PathResolution pr = new PathResolution();
pr.servletPath = matcher.groupCount() > 0 ? matcher.group(1) : matcher.group();
pr.pathInfo = UriUtils.compactPath(UriUtils.relativePath(pr.servletPath, requestURI));
- pr.holder = this.holder;
+ pr.holder = this.handler;
return pr;
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
index 1b8032b..7cba12b 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
@@ -27,7 +27,7 @@
import javax.annotation.Nonnull;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
import org.apache.felix.http.base.internal.util.PatternUtil;
import org.osgi.service.http.runtime.dto.DTOConstants;
@@ -42,9 +42,9 @@
*/
public final class ServletRegistry
{
- private final Map<String, ServletHandler> activeServletMappings = new ConcurrentHashMap<String, ServletHandler>();
+ private final Map<String, ServletRegistration> activeServletMappings = new ConcurrentHashMap<String, ServletRegistration>();
- private final Map<String, List<ServletHolder>> inactiveServletMappings = new HashMap<String, List<ServletHolder>>();
+ private final Map<String, List<ServletHandler>> inactiveServletMappings = new HashMap<String, List<ServletHandler>>();
private final Map<ServletInfo, ServletRegistrationStatus> statusMapping = new ConcurrentHashMap<ServletInfo, ServletRegistry.ServletRegistrationStatus>();
@@ -53,9 +53,9 @@
private static final class ServletNameStatus implements Comparable<ServletNameStatus>
{
public volatile boolean isActive = false;
- public final ServletHolder holder;
+ public final ServletHandler holder;
- public ServletNameStatus(final ServletHolder h)
+ public ServletNameStatus(final ServletHandler h)
{
this.holder = h;
}
@@ -76,7 +76,7 @@
{
int len = -1;
PathResolution candidate = null;
- for(final Map.Entry<String, ServletHandler> entry : this.activeServletMappings.entrySet())
+ for(final Map.Entry<String, ServletRegistration> entry : this.activeServletMappings.entrySet())
{
final PathResolution pr = entry.getValue().resolve(relativeRequestURI);
if ( pr != null && entry.getKey().length() > len )
@@ -93,7 +93,7 @@
*
* @param holder The servlet holder
*/
- public void addServlet(@Nonnull final ServletHolder holder)
+ public void addServlet(@Nonnull final ServletHandler holder)
{
// we have to check for every pattern in the info
// Can be null in case of error-handling servlets...
@@ -103,18 +103,18 @@
for(final String pattern : holder.getServletInfo().getPatterns())
{
- final ServletHandler regHandler = this.activeServletMappings.get(pattern);
+ final ServletRegistration regHandler = this.activeServletMappings.get(pattern);
if ( regHandler != null )
{
- if ( regHandler.getServletHolder().getServletInfo().getServiceReference().compareTo(holder.getServletInfo().getServiceReference()) < 0 )
+ if ( regHandler.getServletHandler().getServletInfo().getServiceReference().compareTo(holder.getServletInfo().getServiceReference()) < 0 )
{
// replace if no error with new servlet
if ( this.tryToActivate(pattern, holder, status) )
{
// nameStatus.isActive = true;
- regHandler.getServletHolder().destroy();
+ regHandler.getServletHandler().destroy();
- this.addToInactiveList(pattern, regHandler.getServletHolder(), this.statusMapping.get(regHandler.getServletHolder().getServletInfo()));
+ this.addToInactiveList(pattern, regHandler.getServletHandler(), this.statusMapping.get(regHandler.getServletHandler().getServletInfo()));
}
}
else
@@ -145,16 +145,16 @@
if ( info.getPatterns() != null )
{
this.statusMapping.remove(info);
- ServletHolder cleanupHolder = null;
+ ServletHandler cleanupHolder = null;
for(final String pattern : info.getPatterns())
{
- final ServletHandler regHandler = this.activeServletMappings.get(pattern);
- if ( regHandler != null && regHandler.getServletHolder().getServletInfo().equals(info) )
+ final ServletRegistration regHandler = this.activeServletMappings.get(pattern);
+ if ( regHandler != null && regHandler.getServletHandler().getServletInfo().equals(info) )
{
- cleanupHolder = regHandler.getServletHolder();
- final List<ServletHolder> inactiveList = this.inactiveServletMappings.get(pattern);
+ cleanupHolder = regHandler.getServletHandler();
+ final List<ServletHandler> inactiveList = this.inactiveServletMappings.get(pattern);
if ( inactiveList == null )
{
this.activeServletMappings.remove(pattern);
@@ -164,7 +164,7 @@
boolean done = false;
while ( !done )
{
- final ServletHolder h = inactiveList.remove(0);
+ final ServletHandler h = inactiveList.remove(0);
done = this.tryToActivate(pattern, h, this.statusMapping.get(h.getServletInfo()));
if ( !done )
{
@@ -179,13 +179,13 @@
}
else
{
- final List<ServletHolder> inactiveList = this.inactiveServletMappings.get(pattern);
+ final List<ServletHandler> inactiveList = this.inactiveServletMappings.get(pattern);
if ( inactiveList != null )
{
- final Iterator<ServletHolder> i = inactiveList.iterator();
+ final Iterator<ServletHandler> i = inactiveList.iterator();
while ( i.hasNext() )
{
- final ServletHolder h = i.next();
+ final ServletHandler h = i.next();
if ( h.getServletInfo().equals(info) )
{
i.remove();
@@ -208,12 +208,12 @@
}
}
- private void addToInactiveList(final String pattern, final ServletHolder holder, final ServletRegistrationStatus status)
+ private void addToInactiveList(final String pattern, final ServletHandler holder, final ServletRegistrationStatus status)
{
- List<ServletHolder> inactiveList = this.inactiveServletMappings.get(pattern);
+ List<ServletHandler> inactiveList = this.inactiveServletMappings.get(pattern);
if ( inactiveList == null )
{
- inactiveList = new ArrayList<ServletHolder>();
+ inactiveList = new ArrayList<ServletHandler>();
this.inactiveServletMappings.put(pattern, inactiveList);
}
inactiveList.add(holder);
@@ -221,14 +221,14 @@
status.pathToStatus.put(pattern, DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE);
}
- private boolean tryToActivate(final String pattern, final ServletHolder holder, final ServletRegistrationStatus status)
+ private boolean tryToActivate(final String pattern, final ServletHandler holder, final ServletRegistrationStatus status)
{
// add to active
final int result = holder.init();
if ( result == -1 )
{
final Pattern p = Pattern.compile(PatternUtil.convertToRegEx(pattern));
- final ServletHandler handler = new ServletHandler(holder, p);
+ final ServletRegistration handler = new ServletRegistration(holder, p);
this.activeServletMappings.put(pattern, handler);
// add ok
@@ -248,7 +248,7 @@
return this.statusMapping;
}
- public ServletHolder resolveByName(@Nonnull String name)
+ public ServletHandler resolveByName(@Nonnull String name)
{
final List<ServletNameStatus> holderList = this.servletsByName.get(name);
if ( holderList != null )
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletResolution.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletResolution.java
index 300d5a4..c50cc14 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletResolution.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletResolution.java
@@ -16,11 +16,11 @@
*/
package org.apache.felix.http.base.internal.registry;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
public class ServletResolution {
- public ServletHolder holder;
+ public ServletHandler holder;
public PerContextHandlerRegistry handlerRegistry;
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RequestInfoDTOBuilder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RequestInfoDTOBuilder.java
index 05bc085..0091e59 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RequestInfoDTOBuilder.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RequestInfoDTOBuilder.java
@@ -18,8 +18,8 @@
import static java.util.Arrays.asList;
+import org.apache.felix.http.base.internal.handler.FilterHandler;
import org.apache.felix.http.base.internal.handler.HandlerRegistry;
-import org.apache.felix.http.base.internal.handler.holder.FilterHolder;
import org.apache.felix.http.base.internal.registry.PathResolution;
import org.osgi.service.http.runtime.dto.FilterDTO;
import org.osgi.service.http.runtime.dto.RequestInfoDTO;
@@ -61,9 +61,9 @@
.buildDTO(pr.holder, pr.holder.getContextServiceId());
}
- final FilterHolder[] filterHolders = registry.getFilters(pr, null, path);
+ final FilterHandler[] filterHandlers = registry.getFilters(pr, null, path);
requestInfoDTO.filterDTOs = FilterDTOBuilder.create()
- .build(asList(filterHolders), pr.holder.getContextServiceId())
+ .build(asList(filterHandlers), pr.holder.getContextServiceId())
.toArray(FILTER_DTO_ARRAY);
return requestInfoDTO;
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java b/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java
index 0fea14c..1dc95b2 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java
@@ -34,8 +34,8 @@
import org.apache.felix.http.api.ExtHttpService;
import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.handler.holder.FilterHolder;
-import org.apache.felix.http.base.internal.handler.holder.HttpServiceFilterHolder;
+import org.apache.felix.http.base.internal.handler.FilterHandler;
+import org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler;
import org.apache.felix.http.base.internal.logger.SystemLogger;
import org.apache.felix.http.base.internal.runtime.FilterInfo;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
@@ -52,7 +52,7 @@
{
private final Bundle bundle;
private final Set<Servlet> localServlets = new HashSet<Servlet>();
- private final Set<FilterHolder> localFilters = new HashSet<FilterHolder>();
+ private final Set<FilterHandler> localFilters = new HashSet<FilterHandler>();
private final ServletContextManager contextManager;
private final SharedHttpServiceImpl sharedHttpService;
@@ -123,7 +123,7 @@
}
final ExtServletContext httpContext = getServletContext(context);
- final FilterHolder holder = new HttpServiceFilterHolder(0, httpContext, filterInfo, filter);
+ final FilterHandler holder = new HttpServiceFilterHandler(0, httpContext, filterInfo, filter);
if ( this.sharedHttpService.registerFilter(holder) )
{
@@ -243,8 +243,8 @@
unregisterServlet(servlet, false);
}
- final Set<FilterHolder> filters = new HashSet<FilterHolder>(this.localFilters);
- for (final FilterHolder holder : filters)
+ final Set<FilterHandler> filters = new HashSet<FilterHandler>(this.localFilters);
+ for (final FilterHandler holder : filters)
{
this.sharedHttpService.unregisterFilter(holder, false);
}
@@ -298,10 +298,10 @@
{
synchronized ( this.localFilters )
{
- final Iterator<FilterHolder> i = this.localFilters.iterator();
+ final Iterator<FilterHandler> i = this.localFilters.iterator();
while ( i.hasNext() )
{
- final FilterHolder h = i.next();
+ final FilterHandler h = i.next();
if ( h.getFilter() == filter )
{
this.sharedHttpService.unregisterFilter(h, destroy);
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/service/SharedHttpServiceImpl.java b/http/base/src/main/java/org/apache/felix/http/base/internal/service/SharedHttpServiceImpl.java
index bd478f4..95d1842 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/service/SharedHttpServiceImpl.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/service/SharedHttpServiceImpl.java
@@ -25,10 +25,10 @@
import javax.servlet.ServletException;
import org.apache.felix.http.base.internal.context.ExtServletContext;
+import org.apache.felix.http.base.internal.handler.FilterHandler;
import org.apache.felix.http.base.internal.handler.HandlerRegistry;
-import org.apache.felix.http.base.internal.handler.holder.FilterHolder;
-import org.apache.felix.http.base.internal.handler.holder.HttpServiceServletHolder;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
+import org.apache.felix.http.base.internal.handler.HttpServiceServletHandler;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
import org.osgi.service.http.NamespaceException;
@@ -36,7 +36,7 @@
{
private final HandlerRegistry handlerRegistry;
- private final Map<String, ServletHolder> aliasMap = new HashMap<String, ServletHolder>();
+ private final Map<String, ServletHandler> aliasMap = new HashMap<String, ServletHandler>();
public SharedHttpServiceImpl(final HandlerRegistry handlerRegistry)
{
@@ -51,7 +51,7 @@
/**
* Register a filter
*/
- public boolean registerFilter(@Nonnull final FilterHolder holder)
+ public boolean registerFilter(@Nonnull final FilterHandler holder)
{
this.handlerRegistry.addFilter(holder);
return true;
@@ -65,7 +65,7 @@
@Nonnull final Servlet servlet,
@Nonnull final ServletInfo servletInfo) throws ServletException, NamespaceException
{
- final ServletHolder holder = new HttpServiceServletHolder(0, httpContext, servletInfo, servlet);
+ final ServletHandler holder = new HttpServiceServletHandler(0, httpContext, servletInfo, servlet);
synchronized (this.aliasMap)
{
@@ -86,7 +86,7 @@
{
synchronized (this.aliasMap)
{
- final ServletHolder holder = this.aliasMap.remove(alias);
+ final ServletHandler holder = this.aliasMap.remove(alias);
if (holder == null)
{
throw new IllegalArgumentException("Nothing registered at " + alias);
@@ -104,10 +104,10 @@
{
synchronized (this.aliasMap)
{
- final Iterator<Map.Entry<String, ServletHolder>> i = this.aliasMap.entrySet().iterator();
+ final Iterator<Map.Entry<String, ServletHandler>> i = this.aliasMap.entrySet().iterator();
while (i.hasNext())
{
- final Map.Entry<String, ServletHolder> entry = i.next();
+ final Map.Entry<String, ServletHandler> entry = i.next();
if (entry.getValue().getServlet() == servlet)
{
this.handlerRegistry.removeServlet(0, entry.getValue().getServletInfo(), destroy);
@@ -121,7 +121,7 @@
}
}
- public void unregisterFilter(final FilterHolder filter, final boolean destroy)
+ public void unregisterFilter(final FilterHandler filter, final boolean destroy)
{
if (filter != null)
{
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
index d14f591..40f25ae 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
@@ -18,12 +18,12 @@
import javax.annotation.Nonnull;
+import org.apache.felix.http.base.internal.handler.FilterHandler;
import org.apache.felix.http.base.internal.handler.HandlerRegistry;
-import org.apache.felix.http.base.internal.handler.holder.FilterHolder;
-import org.apache.felix.http.base.internal.handler.holder.HttpServiceServletHolder;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
-import org.apache.felix.http.base.internal.handler.holder.WhiteboardFilterHolder;
-import org.apache.felix.http.base.internal.handler.holder.WhiteboardServletHolder;
+import org.apache.felix.http.base.internal.handler.HttpServiceServletHandler;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
+import org.apache.felix.http.base.internal.handler.WhiteboardFilterHandler;
+import org.apache.felix.http.base.internal.handler.WhiteboardServletHandler;
import org.apache.felix.http.base.internal.runtime.FilterInfo;
import org.apache.felix.http.base.internal.runtime.ResourceInfo;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
@@ -56,7 +56,7 @@
public void registerServlet(@Nonnull final ContextHandler contextHandler,
@Nonnull final ServletInfo servletInfo)
{
- final ServletHolder holder = new WhiteboardServletHolder(
+ final ServletHandler holder = new WhiteboardServletHandler(
contextHandler.getContextInfo().getServiceId(),
contextHandler.getServletContext(servletInfo.getServiceReference().getBundle()),
servletInfo, bundleContext);
@@ -83,7 +83,7 @@
public void registerFilter(@Nonnull final ContextHandler contextHandler,
@Nonnull final FilterInfo filterInfo)
{
- final FilterHolder holder = new WhiteboardFilterHolder(
+ final FilterHandler holder = new WhiteboardFilterHandler(
contextHandler.getContextInfo().getServiceId(),
contextHandler.getServletContext(filterInfo.getServiceReference().getBundle()),
filterInfo, bundleContext);
@@ -112,7 +112,7 @@
{
final ServletInfo servletInfo = new ServletInfo(resourceInfo);
- final ServletHolder holder = new HttpServiceServletHolder(
+ final ServletHandler holder = new HttpServiceServletHandler(
contextHandler.getContextInfo().getServiceId(),
contextHandler.getServletContext(servletInfo.getServiceReference().getBundle()),
servletInfo, new ResourceServlet(resourceInfo.getPrefix()));
diff --git a/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java b/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java
deleted file mode 100644
index a820be3..0000000
--- a/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.felix.http.base.internal.handler;
-
-import java.util.Hashtable;
-import java.util.Map;
-
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-public abstract class AbstractHandlerTest
-{
- protected ExtServletContext context;
-
- protected abstract AbstractHandler createHandler();
-
- protected abstract AbstractHandler createHandler(Map<String, String> map);
-
- public void setUp()
- {
- this.context = Mockito.mock(ExtServletContext.class);
- }
-
- @Test
- public void testId()
- {
- AbstractHandler h1 = createHandler();
- AbstractHandler h2 = createHandler();
-
- Assert.assertTrue(h1.getServiceId() < 0);
- Assert.assertTrue(h2.getServiceId() < 0);
- Assert.assertFalse(h1.getServiceId() == h2.getServiceId());
- }
-
- @Test
- public void testInitParams()
- {
- AbstractHandler handler = createHandler();
- Assert.assertEquals(0, handler.getInitParams().size());
-
- Map<String, String> map = new Hashtable<String, String>();
- map.put("key1", "value1");
-
- handler = createHandler(map);
- Assert.assertEquals(1, handler.getInitParams().size());
- Assert.assertEquals("value1", handler.getInitParams().get("key1"));
- }
-}
diff --git a/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java b/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java
index f186e7b..d53a195 100644
--- a/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java
+++ b/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java
@@ -38,9 +38,6 @@
import org.apache.felix.http.base.internal.context.ExtServletContext;
import org.apache.felix.http.base.internal.dispatch.InvocationChain;
-import org.apache.felix.http.base.internal.handler.holder.FilterHolder;
-import org.apache.felix.http.base.internal.handler.holder.HttpServiceFilterHolder;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
import org.apache.felix.http.base.internal.runtime.FilterInfo;
import org.junit.Before;
import org.junit.Test;
@@ -62,9 +59,9 @@
@Test
public void testCompare()
{
- FilterHolder h1 = createHandler(0, "a");
- FilterHolder h2 = createHandler(10, "b");
- FilterHolder h3 = createHandler(10, "c");
+ FilterHandler h1 = createHandler(0, "a");
+ FilterHandler h2 = createHandler(10, "b");
+ FilterHandler h3 = createHandler(10, "c");
assertTrue(h1.compareTo(h1) == 0);
@@ -79,7 +76,7 @@
@Test
public void testDestroy()
{
- FilterHolder h1 = createHandler(0, "/a");
+ FilterHandler h1 = createHandler(0, "/a");
h1.init();
h1.destroy();
verify(this.filter).destroy();
@@ -88,7 +85,7 @@
@Test
public void testHandleFound() throws Exception
{
- FilterHolder h1 = createHandler(0, "/a");
+ FilterHandler h1 = createHandler(0, "/a");
HttpServletRequest req = createServletRequest();
HttpServletResponse res = createServletResponse();
FilterChain chain = mock(FilterChain.class);
@@ -104,7 +101,7 @@
@Test
public void testHandleFoundContextRoot() throws Exception
{
- FilterHolder h1 = createHandler(0, "/");
+ FilterHandler h1 = createHandler(0, "/");
HttpServletRequest req = createServletRequest();
HttpServletResponse res = createServletResponse();
FilterChain chain = mock(FilterChain.class);
@@ -123,10 +120,10 @@
@Test
public void testHandleFoundForbidden() throws Exception
{
- FilterHolder h1 = createHandler(0, "/a");
- final ServletHolder sc = mock(ServletHolder.class);
+ FilterHandler h1 = createHandler(0, "/a");
+ final ServletHandler sc = mock(ServletHandler.class);
when(sc.getContext()).thenReturn(this.context);
- final InvocationChain ic = new InvocationChain(sc, new FilterHolder[] {h1});
+ final InvocationChain ic = new InvocationChain(sc, new FilterHandler[] {h1});
HttpServletRequest req = createServletRequest();
HttpServletResponse res = createServletResponse();
@@ -149,10 +146,10 @@
@Test
public void testHandleFoundForbiddenCommittedOwnResponse() throws Exception
{
- FilterHolder h1 = createHandler(0, "/a");
- final ServletHolder sc = mock(ServletHolder.class);
+ FilterHandler h1 = createHandler(0, "/a");
+ final ServletHandler sc = mock(ServletHandler.class);
when(sc.getContext()).thenReturn(this.context);
- final InvocationChain ic = new InvocationChain(sc, new FilterHolder[] {h1});
+ final InvocationChain ic = new InvocationChain(sc, new FilterHandler[] {h1});
HttpServletRequest req = createServletRequest();
HttpServletResponse res = createServletResponse();
@@ -176,10 +173,10 @@
@Test
public void testHandleFoundForbiddenCustomStatusCode() throws Exception
{
- FilterHolder h1 = createHandler(0, "/a");
- final ServletHolder sc = mock(ServletHolder.class);
+ FilterHandler h1 = createHandler(0, "/a");
+ final ServletHandler sc = mock(ServletHandler.class);
when(sc.getContext()).thenReturn(this.context);
- final InvocationChain ic = new InvocationChain(sc, new FilterHolder[] {h1});
+ final InvocationChain ic = new InvocationChain(sc, new FilterHandler[] {h1});
HttpServletRequest req = createServletRequest();
HttpServletResponse res = createServletResponse();
@@ -200,10 +197,10 @@
@Test
public void testHandleNotFound() throws Exception
{
- FilterHolder h1 = createHandler(0, "/a");
- final ServletHolder sc = mock(ServletHolder.class);
+ FilterHandler h1 = createHandler(0, "/a");
+ final ServletHandler sc = mock(ServletHandler.class);
when(sc.getContext()).thenReturn(this.context);
- final InvocationChain ic = new InvocationChain(sc, new FilterHolder[] {h1});
+ final InvocationChain ic = new InvocationChain(sc, new FilterHandler[] {h1});
HttpServletRequest req = createServletRequest();
HttpServletResponse res = createServletResponse();
@@ -216,10 +213,10 @@
@Test
public void testHandleNotFoundContextRoot() throws Exception
{
- FilterHolder h1 = createHandler(0, "/a");
- final ServletHolder sc = mock(ServletHolder.class);
+ FilterHandler h1 = createHandler(0, "/a");
+ final ServletHandler sc = mock(ServletHandler.class);
when(sc.getContext()).thenReturn(this.context);
- final InvocationChain ic = new InvocationChain(sc, new FilterHolder[] {h1});
+ final InvocationChain ic = new InvocationChain(sc, new FilterHandler[] {h1});
HttpServletRequest req = createServletRequest();
HttpServletResponse res = createServletResponse();
@@ -232,24 +229,24 @@
@Test
public void testInit() throws Exception
{
- FilterHolder h1 = createHandler(0, "/a");
+ FilterHandler h1 = createHandler(0, "/a");
h1.init();
verify(this.filter).init(any(FilterConfig.class));
}
- private FilterHolder createHandler(int ranking, String pattern)
+ private FilterHandler createHandler(int ranking, String pattern)
{
return createHandler(pattern, ranking, null);
}
- private FilterHolder createHandler(String pattern, int ranking, Map<String, String> initParams)
+ private FilterHandler createHandler(String pattern, int ranking, Map<String, String> initParams)
{
if ( initParams == null )
{
initParams = Collections.emptyMap();
}
final FilterInfo info = new FilterInfo(null, pattern, ranking, initParams);
- return new HttpServiceFilterHolder(0, this.context, info, this.filter);
+ return new HttpServiceFilterHandler(0, this.context, info, this.filter);
}
private HttpServletRequest createServletRequest()
diff --git a/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HandlerRankingMultimapTest.java b/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HandlerRankingMultimapTest.java
deleted file mode 100644
index 5fc66b6..0000000
--- a/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HandlerRankingMultimapTest.java
+++ /dev/null
@@ -1,385 +0,0 @@
-/*
- * 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.felix.http.base.internal.handler;
-
-import static java.util.Arrays.asList;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.ServletException;
-
-import org.apache.felix.http.base.internal.handler.HandlerRankingMultimap.Update;
-import org.hamcrest.Matcher;
-import org.hamcrest.Matchers;
-import org.junit.Before;
-import org.junit.Test;
-
-@SuppressWarnings("unchecked")
-public class HandlerRankingMultimapTest
-{
- private HandlerRankingMultimap<String> handlerMultimap;
-
- @Before
- public void setup()
- {
- handlerMultimap = new HandlerRankingMultimap<String>();
- }
-
- @Test
- public void addedInfoIsUsed() throws ServletException
- {
- TestHandler<String> handler = TestHandler.create(asList("a"), 0);
- Update<String> update = handlerMultimap.add(handler.getKeys(), handler);
-
- assertEquals(1, handlerMultimap.size());
- assertTrue(handlerMultimap.isActive(handler));
-
- assertEquals(1, update.getActivated().size());
- assertThat(update.getActivated(), hasEntry("a", handler));
- assertTrue(update.getDeactivated().isEmpty());
-
- assertEquals(1, update.getInit().size());
- assertThat(update.getInit(), contains(handler));
- assertTrue(update.getDestroy().isEmpty());
- }
-
- @Test
- public void highestPriorityServiceIsUsed() throws ServletException
- {
- TestHandler<String> higher = TestHandler.create(asList("a"), 1);
- TestHandler<String> lower = TestHandler.create(asList("a"), 0);
-
- handlerMultimap.add(lower.getKeys(), lower);
-
- Update<String> updateAddingHigher = handlerMultimap.add(higher.getKeys(), higher);
-
- assertTrue(handlerMultimap.isActive(higher));
- assertFalse(handlerMultimap.isActive(lower));
-
- assertEquals(1, updateAddingHigher.getActivated().size());
- assertThat(updateAddingHigher.getActivated(), hasEntry("a", higher));
- assertEquals(1, updateAddingHigher.getDeactivated().size());
- assertThat(updateAddingHigher.getDeactivated(), hasEntry("a", lower));
-
- assertEquals(1, updateAddingHigher.getInit().size());
- assertThat(updateAddingHigher.getInit(), contains(higher));
- assertEquals(1, updateAddingHigher.getDestroy().size());
- assertThat(updateAddingHigher.getDestroy(), contains(lower));
- }
-
- @Test
- public void removeHighestPriorityService() throws ServletException
- {
- TestHandler<String> higher = TestHandler.create(asList("a"), 1);
- TestHandler<String> lower = TestHandler.create(asList("a"), 0);
-
- handlerMultimap.add(lower.getKeys(), lower);
- handlerMultimap.add(higher.getKeys(), higher);
-
- Update<String> update = handlerMultimap.remove(higher.getKeys(), higher);
-
- assertFalse(handlerMultimap.isActive(higher));
- assertTrue(handlerMultimap.isActive(lower));
-
- assertEquals(1, update.getActivated().size());
- assertThat(update.getActivated(), hasEntry("a", lower));
- assertEquals(1, update.getDeactivated().size());
- assertThat(update.getDeactivated(), hasEntry("a", higher));
-
- assertEquals(1, update.getInit().size());
- assertThat(update.getInit(), contains(lower));
- assertEquals(1, update.getDestroy().size());
- assertThat(update.getDestroy(), contains(higher));
- }
-
- @Test
- public void removeLowerPriorityService() throws ServletException
- {
- TestHandler<String> higher = TestHandler.create(asList("a"), 1);
- TestHandler<String> lower = TestHandler.create(asList("a"), 0);
-
- handlerMultimap.add(lower.getKeys(), higher);
- handlerMultimap.add(higher.getKeys(), lower);
-
- Update<String> update = handlerMultimap.remove(lower.getKeys(), lower);
-
- assertTrue(handlerMultimap.isActive(higher));
- assertFalse(handlerMultimap.isActive(lower));
-
- assertTrue(update.getActivated().isEmpty());
- assertTrue(update.getDeactivated().isEmpty());
-
- assertTrue(update.getInit().isEmpty());
- assertTrue(update.getDestroy().isEmpty());
- }
-
- @Test
- public void addServiceWithMultipleKeys() throws ServletException
- {
- TestHandler<String> handler = TestHandler.create(asList("a", "b"), 0);
-
- Update<String> update = handlerMultimap.add(handler.getKeys(), handler);
-
- assertTrue(handlerMultimap.isActive(handler));
-
- assertEquals(2, update.getActivated().size());
- assertThat(update.getActivated(), hasEntry("a", handler));
- assertThat(update.getActivated(), hasEntry("b", handler));
- assertTrue(update.getDeactivated().isEmpty());
-
- assertEquals(1, update.getInit().size());
- assertThat(update.getInit(), contains(handler));
- }
-
- @Test
- public void addServiceWithMultipleKeysShadowsAllKeys() throws ServletException
- {
- TestHandler<String> higher = TestHandler.create(asList("a", "b", "c"), 1);
- TestHandler<String> lower = TestHandler.create(asList("a", "b"), 0);
-
- handlerMultimap.add(lower.getKeys(), lower);
-
- Update<String> updateWithHigher = handlerMultimap.add(higher.getKeys(), higher);
-
- assertTrue(handlerMultimap.isActive(higher));
- assertFalse(handlerMultimap.isActive(lower));
-
- assertEquals(3, updateWithHigher.getActivated().size());
- assertThat(updateWithHigher.getActivated(), hasEntry("a", higher));
- assertThat(updateWithHigher.getActivated(), hasEntry("b", higher));
- assertThat(updateWithHigher.getActivated(), hasEntry("c", higher));
- assertEquals(2, updateWithHigher.getDeactivated().size());
- assertThat(updateWithHigher.getDeactivated(), hasEntry("a", lower));
- assertThat(updateWithHigher.getDeactivated(), hasEntry("b", lower));
-
- assertEquals(1, updateWithHigher.getInit().size());
- assertThat(updateWithHigher.getInit(), contains(higher));
- assertEquals(1, updateWithHigher.getDestroy().size());
- assertThat(updateWithHigher.getDestroy(), contains(lower));
- }
-
- @Test
- public void addServiceWithMultipleKeysShadowsPartially() throws ServletException
- {
- TestHandler<String> higher = TestHandler.create(asList("a", "c"), 1);
- TestHandler<String> lower = TestHandler.create(asList("a", "b"), 0);
-
- handlerMultimap.add(lower.getKeys(), lower);
-
- Update<String> updateWithHigher = handlerMultimap.add(higher.getKeys(), higher);
-
- assertTrue(handlerMultimap.isActive(higher));
- assertTrue(handlerMultimap.isActive(lower));
-
- assertEquals(2, updateWithHigher.getActivated().size());
- assertThat(updateWithHigher.getActivated(), hasEntry("a", higher));
- assertThat(updateWithHigher.getActivated(), hasEntry("c", higher));
- assertEquals(1, updateWithHigher.getDeactivated().size());
- assertThat(updateWithHigher.getDeactivated(), hasEntry("a", lower));
-
- assertEquals(1, updateWithHigher.getInit().size());
- assertThat(updateWithHigher.getInit(), contains(higher));
- assertTrue(updateWithHigher.getDestroy().isEmpty());
- }
-
- @Test
- public void addServiceWithMultipleKeysIsCompletelyShadowed() throws ServletException
- {
- TestHandler<String> higher = TestHandler.create(asList("a", "b", "c"), 1);
- TestHandler<String> lower = TestHandler.create(asList("a", "b"), 0);
-
- handlerMultimap.add(higher.getKeys(), higher);
-
- Update<String> updateWithLower = handlerMultimap.add(lower.getKeys(), lower);
-
- assertTrue(handlerMultimap.isActive(higher));
- assertFalse(handlerMultimap.isActive(lower));
-
- assertTrue(updateWithLower.getActivated().isEmpty());
- assertTrue(updateWithLower.getDeactivated().isEmpty());
-
- assertTrue(updateWithLower.getInit().isEmpty());
- assertTrue(updateWithLower.getDestroy().isEmpty());
- }
-
- @Test
- public void sizeReturnsAllEntries() throws ServletException
- {
- TestHandler<String> higher = TestHandler.create(asList("a", "b", "c"), 1);
- TestHandler<String> lower = TestHandler.create(asList("a", "b"), 0);
- TestHandler<String> third = TestHandler.create(asList("d"), 3);
-
- assertEquals(0 , handlerMultimap.size());
-
- handlerMultimap.add(lower.getKeys(), lower);
-
- assertEquals(1, handlerMultimap.size());
-
- handlerMultimap.add(higher.getKeys(), higher);
-
- assertEquals(2, handlerMultimap.size());
-
- handlerMultimap.add(third.getKeys(), third);
-
- assertEquals(3, handlerMultimap.size());
-
- handlerMultimap.remove(lower.getKeys(), lower);
-
- assertEquals(2, handlerMultimap.size());
-
- handlerMultimap.remove(higher.getKeys(), higher);
-
- assertEquals(1, handlerMultimap.size());
-
- handlerMultimap.remove(third.getKeys(), third);
-
- assertEquals(0, handlerMultimap.size());
- }
-
- public void getActiveValuesContainsAllHeads()
- {
- TestHandler<String> one = TestHandler.create(asList("a", "b", "c"), 1);
- TestHandler<String> two = TestHandler.create(asList("a", "b"), 0);
- TestHandler<String> three = TestHandler.create(asList("c, e"), 3);
- TestHandler<String> four = TestHandler.create(asList("d"), 3);
-
- handlerMultimap.add(one.getKeys(), one);
- handlerMultimap.add(two.getKeys(), two);
- handlerMultimap.add(three.getKeys(), three);
- handlerMultimap.add(four.getKeys(), four);
-
- assertEquals(3, handlerMultimap.getActiveValues());
- assertTrue(handlerMultimap.getActiveValues().contains(one));
- assertTrue(handlerMultimap.getActiveValues().contains(three));
- assertTrue(handlerMultimap.getActiveValues().contains(four));
- }
-
- public void getShadowedValuesContainsAllTails()
- {
- TestHandler<String> one = TestHandler.create(asList("a", "b", "c"), 1);
- TestHandler<String> two = TestHandler.create(asList("a", "b"), 0);
- TestHandler<String> three = TestHandler.create(asList("a"), -1);
- TestHandler<String> four = TestHandler.create(asList("c, e"), 3);
- TestHandler<String> five = TestHandler.create(asList("d"), 3);
-
- handlerMultimap.add(one.getKeys(), one);
- handlerMultimap.add(two.getKeys(), two);
- handlerMultimap.add(three.getKeys(), three);
- handlerMultimap.add(four.getKeys(), four);
- handlerMultimap.add(five.getKeys(), five);
-
- assertEquals(3, handlerMultimap.getActiveValues());
- assertTrue(handlerMultimap.getActiveValues().contains(one));
- assertTrue(handlerMultimap.getActiveValues().contains(two));
- assertTrue(handlerMultimap.getActiveValues().contains(three));
- }
-
- public void keyComparatorIsUsed()
- {
- final Object keyOne = new Object();
- final Object keyTwo = new Object();
-
- Comparator<Object> keyComparator = new Comparator<Object>()
- {
- @Override
- public int compare(Object o1, Object o2)
- {
- if (o1 == o2)
- {
- return 0;
- }
- if (o1 == keyOne && o2 == keyTwo)
- {
- return 1;
- }
- if (o1 == keyTwo && o2 == keyOne)
- {
- return -1;
- }
- throw new IllegalArgumentException();
- }
- };
-
- HandlerRankingMultimap<Object> multimap = new HandlerRankingMultimap<Object>(keyComparator);
-
- TestHandler<Object> handlerOne = TestHandler.create(asList(keyOne), 1);
- TestHandler<Object> handlerTwo = TestHandler.create(asList(keyOne, keyTwo), 0);
-
- multimap.add(handlerOne.getKeys(), handlerOne);
- multimap.add(handlerTwo.getKeys(), handlerTwo);
-
- assertEquals(2, multimap.size());
- assertEquals(2, multimap.getActiveValues().size());
- assertTrue(multimap.getActiveValues().contains(keyOne));
- assertTrue(multimap.getActiveValues().contains(keyTwo));
- assertEquals(1, multimap.getShadowedValues().size());
- assertTrue(multimap.getShadowedValues().contains(keyTwo));
- }
-
- private static Matcher<Map<? extends String, ? extends ServletHandler>> hasEntry(String key, ServletHandler servletHandler)
- {
- return Matchers.hasEntry(key, servletHandler);
- }
-
- private static Matcher<Iterable<? extends ServletHandler>> contains(ServletHandler servletHandler)
- {
- return Matchers.contains(servletHandler);
- }
-
- private static abstract class TestHandler<T> extends ServletHandler
- {
- static int idCount = 0;
-
- TestHandler(List<T> keys, int ranking)
- {
- super(0L, null, null);
- }
-
- static <T> TestHandler<T> create(List<T> keys, int ranking)
- {
- TestHandler<T> testHandler = mock(TestHandler.class);
- when(testHandler.getId()).thenReturn(++idCount);
- when(testHandler.getRanking()).thenReturn(ranking);
- when(testHandler.getKeys()).thenReturn(keys);
- when(testHandler.compareTo(any(TestHandler.class))).thenCallRealMethod();
- return testHandler;
- }
-
- @Override
- public int compareTo(ServletHandler o)
- {
- TestHandler<T> other = (TestHandler<T>) o;
- int rankCompare = Integer.compare(other.getRanking(), getRanking());
- return rankCompare != 0 ? rankCompare : Integer.compare(getId(), other.getId());
- }
-
- abstract int getRanking();
-
- abstract int getId();
-
- abstract List<T> getKeys();
- }
-}
diff --git a/http/base/src/test/java/org/apache/felix/http/base/internal/handler/SimpleServletHandlerTest.java b/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HttpServiceServletHandlerTest.java
similarity index 87%
rename from http/base/src/test/java/org/apache/felix/http/base/internal/handler/SimpleServletHandlerTest.java
rename to http/base/src/test/java/org/apache/felix/http/base/internal/handler/HttpServiceServletHandlerTest.java
index 4c7c4aa..ac0c519 100644
--- a/http/base/src/test/java/org/apache/felix/http/base/internal/handler/SimpleServletHandlerTest.java
+++ b/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HttpServiceServletHandlerTest.java
@@ -36,15 +36,12 @@
import org.apache.felix.http.base.internal.context.ExtServletContext;
import org.apache.felix.http.base.internal.dispatch.InvocationChain;
-import org.apache.felix.http.base.internal.handler.holder.FilterHolder;
-import org.apache.felix.http.base.internal.handler.holder.HttpServiceServletHolder;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
-public class SimpleServletHandlerTest
+public class HttpServiceServletHandlerTest
{
private Servlet servlet;
@@ -60,7 +57,7 @@
@Test
public void testDestroy()
{
- ServletHolder h1 = createHandler("/a");
+ ServletHandler h1 = createHandler("/a");
h1.init();
h1.destroy();
verify(this.servlet).destroy();
@@ -69,8 +66,8 @@
@Test
public void testHandleFound() throws Exception
{
- ServletHolder h1 = createHandler("/a");
- final InvocationChain ic = new InvocationChain(h1, new FilterHolder[0]);
+ ServletHandler h1 = createHandler("/a");
+ final InvocationChain ic = new InvocationChain(h1, new FilterHandler[0]);
HttpServletRequest req = mock(HttpServletRequest.class);
HttpServletResponse res = mock(HttpServletResponse.class);
when(this.context.handleSecurity(req, res)).thenReturn(true);
@@ -85,8 +82,8 @@
@Test
public void testHandleFoundContextRoot() throws Exception
{
- ServletHolder h1 = createHandler("/");
- final InvocationChain ic = new InvocationChain(h1, new FilterHolder[0]);
+ ServletHandler h1 = createHandler("/");
+ final InvocationChain ic = new InvocationChain(h1, new FilterHandler[0]);
HttpServletRequest req = mock(HttpServletRequest.class);
HttpServletResponse res = mock(HttpServletResponse.class);
when(this.context.handleSecurity(req, res)).thenReturn(true);
@@ -104,8 +101,8 @@
@Test
public void testHandleFoundForbidden() throws Exception
{
- ServletHolder h1 = createHandler("/a");
- final InvocationChain ic = new InvocationChain(h1, new FilterHolder[0]);
+ ServletHandler h1 = createHandler("/a");
+ final InvocationChain ic = new InvocationChain(h1, new FilterHandler[0]);
HttpServletRequest req = mock(HttpServletRequest.class);
HttpServletResponse res = mock(HttpServletResponse.class);
@@ -130,8 +127,8 @@
@Test
public void testHandleFoundForbiddenCommittedOwnResponse() throws Exception
{
- ServletHolder h1 = createHandler("/a");
- final InvocationChain ic = new InvocationChain(h1, new FilterHolder[0]);
+ ServletHandler h1 = createHandler("/a");
+ final InvocationChain ic = new InvocationChain(h1, new FilterHandler[0]);
HttpServletRequest req = mock(HttpServletRequest.class);
HttpServletResponse res = mock(HttpServletResponse.class);
@@ -156,8 +153,8 @@
@Test
public void testHandleFoundForbiddenCustomStatusCode() throws Exception
{
- ServletHolder h1 = createHandler("/a");
- final InvocationChain ic = new InvocationChain(h1, new FilterHolder[0]);
+ ServletHandler h1 = createHandler("/a");
+ final InvocationChain ic = new InvocationChain(h1, new FilterHandler[0]);
HttpServletRequest req = mock(HttpServletRequest.class);
HttpServletResponse res = mock(HttpServletResponse.class);
@@ -179,8 +176,8 @@
@Test
public void testHandleNotFound() throws Exception
{
- ServletHolder h1 = createHandler("/a");
- final InvocationChain ic = new InvocationChain(h1, new FilterHolder[0]);
+ ServletHandler h1 = createHandler("/a");
+ final InvocationChain ic = new InvocationChain(h1, new FilterHandler[0]);
HttpServletRequest req = mock(HttpServletRequest.class);
HttpServletResponse res = mock(HttpServletResponse.class);
@@ -193,7 +190,7 @@
@Test
public void testHandleNotFoundContextRoot() throws Exception
{
- ServletHolder h1 = createHandler("/a");
+ ServletHandler h1 = createHandler("/a");
HttpServletRequest req = mock(HttpServletRequest.class);
HttpServletResponse res = mock(HttpServletResponse.class);
when(this.context.handleSecurity(req, res)).thenReturn(true);
@@ -207,23 +204,23 @@
@Test
public void testInit() throws Exception
{
- ServletHolder h1 = createHandler("/a");
+ ServletHandler h1 = createHandler("/a");
h1.init();
verify(this.servlet).init(any(ServletConfig.class));
}
- private ServletHolder createHandler(String alias)
+ private ServletHandler createHandler(String alias)
{
return createHandler(alias, null);
}
- private ServletHolder createHandler(String alias, Map<String, String> map)
+ private ServletHandler createHandler(String alias, Map<String, String> map)
{
if ( map == null )
{
map = Collections.emptyMap();
}
final ServletInfo info = new ServletInfo(null, alias, 0, map);
- return new HttpServiceServletHolder(3, this.context, info, this.servlet);
+ return new HttpServiceServletHandler(3, this.context, info, this.servlet);
}
}
diff --git a/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java b/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java
index 3f050e4..bca0be2 100644
--- a/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java
+++ b/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java
@@ -30,8 +30,8 @@
import javax.servlet.ServletException;
import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.handler.holder.HttpServiceServletHolder;
-import org.apache.felix.http.base.internal.handler.holder.ServletHolder;
+import org.apache.felix.http.base.internal.handler.HttpServiceServletHandler;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
import org.junit.Test;
import org.mockito.Matchers;
@@ -54,7 +54,7 @@
assertEquals(0, status.size());
// register servlet
- final ServletHolder h1 = createServletHolder(1L, 0, "/foo");
+ final ServletHandler h1 = createServletHandler(1L, 0, "/foo");
reg.addServlet(h1);
verify(h1.getServlet()).init(Matchers.any(ServletConfig.class));
@@ -82,11 +82,11 @@
assertEquals(0, status.size());
// register servlets
- final ServletHolder h1 = createServletHolder(1L, 10, "/foo");
+ final ServletHandler h1 = createServletHandler(1L, 10, "/foo");
reg.addServlet(h1);
verify(h1.getServlet()).init(Matchers.any(ServletConfig.class));
- final ServletHolder h2 = createServletHolder(2L, 0, "/foo");
+ final ServletHandler h2 = createServletHandler(2L, 0, "/foo");
reg.addServlet(h2);
verify(h2.getServlet(), never()).init(Matchers.any(ServletConfig.class));
verify(h1.getServlet(), never()).destroy();
@@ -145,12 +145,12 @@
return si;
}
- private static ServletHolder createServletHolder(final long id, final int ranking, final String... paths) throws InvalidSyntaxException
+ private static ServletHandler createServletHandler(final long id, final int ranking, final String... paths) throws InvalidSyntaxException
{
final ServletInfo si = createServletInfo(id, ranking, paths);
final ExtServletContext ctx = mock(ExtServletContext.class);
final Servlet servlet = mock(Servlet.class);
- return new HttpServiceServletHolder(7, ctx, si, servlet);
+ return new HttpServiceServletHandler(7, ctx, si, servlet);
}
}
diff --git a/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java b/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java
index 14699c6..d7a85f0 100644
--- a/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java
+++ b/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java
@@ -32,8 +32,8 @@
import javax.servlet.Servlet;
import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.SimpleServletHandler;
+import org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler;
+import org.apache.felix.http.base.internal.handler.HttpServiceServletHandler;
import org.apache.felix.http.base.internal.runtime.dto.ErrorPageRuntime;
import org.apache.felix.http.base.internal.runtime.dto.FilterRuntime;
import org.apache.felix.http.base.internal.runtime.dto.ServletRuntime;
@@ -60,7 +60,7 @@
Long serviceId)
{
FilterInfo filterInfo = createFilterInfo(identifier, serviceId);
- return new FilterHandler(null, context, mock(Filter.class), filterInfo);
+ return new HttpServiceFilterHandler(0, context, filterInfo, mock(Filter.class));
}
private static FilterInfo createFilterInfo(String identifier,
@@ -117,7 +117,7 @@
ServletInfo servletInfo = createServletInfo(identifier, serviceId);
Servlet servlet = mock(Servlet.class);
when(servlet.getServletInfo()).thenReturn("info_" + identifier);
- return new SimpleServletHandler(contextServiceId, context, servletInfo, servlet);
+ return new HttpServiceServletHandler(contextServiceId, context, servletInfo, servlet);
}
private static ServletInfo createServletInfo(String identifier, Long serviceId)
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 5d9456c..652c2f7 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
@@ -56,8 +56,8 @@
import javax.servlet.ServletContext;
import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.SimpleServletHandler;
+import org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler;
+import org.apache.felix.http.base.internal.handler.HttpServiceServletHandler;
import org.apache.felix.http.base.internal.runtime.AbstractInfo;
import org.apache.felix.http.base.internal.runtime.FilterInfo;
import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
@@ -584,7 +584,7 @@
true,
Collections.<String, String>emptyMap());
Servlet servlet = mock(Servlet.class);
- ServletRuntime servletHandler = new SimpleServletHandler(context_0, servletInfo, servlet);
+ ServletRuntime servletHandler = new HttpServiceServletHandler(0, context_0, servletInfo, servlet);
when(servlet.getServletInfo()).thenReturn("info_0");
FilterInfo filterInfo = createFilterInfo(0,
@@ -596,7 +596,7 @@
true,
null,
Collections.<String, String>emptyMap());
- FilterRuntime filterHandler = new FilterHandler(null, context_0, mock(Filter.class), filterInfo);
+ FilterRuntime filterHandler = new HttpServiceFilterHandler(0, context_0, filterInfo, mock(Filter.class));
ServletInfo resourceInfo = createServletInfo(0,
ID_COUNTER.incrementAndGet(),
@@ -606,7 +606,7 @@
true,
Collections.<String, String>emptyMap());
Servlet resource = mock(Servlet.class);
- ServletRuntime resourceHandler = new SimpleServletHandler(ID_0, context_0, resourceInfo, resource);
+ ServletRuntime resourceHandler = new HttpServiceServletHandler(ID_0, context_0, resourceInfo, resource);
ContextRuntime contextRuntime = new ContextRuntime(asList(filterHandler),
Collections.<ErrorPageRuntime>emptyList(),
@@ -665,7 +665,7 @@
true,
Collections.<String, String>emptyMap());
Servlet servlet = mock(Servlet.class);
- ServletRuntime servletHandler = new SimpleServletHandler(ID_0, context_0, servletInfo, servlet);
+ ServletRuntime servletHandler = new HttpServiceServletHandler(ID_0, context_0, servletInfo, servlet);
when(servlet.getServletInfo()).thenReturn("info_0");
ContextRuntime contextRuntime = new ContextRuntime(Collections.<FilterRuntime>emptyList(),