use of org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler in project felix by apache.
the class EventListenerRegistryTest method createFilterHandler.
private static FilterHandler createFilterHandler(final long id, final int ranking, final String... paths) throws InvalidSyntaxException {
final FilterInfo si = createFilterInfo(id, ranking, paths);
final ExtServletContext ctx = mock(ExtServletContext.class);
final Filter filter = mock(Filter.class);
return new HttpServiceFilterHandler(ctx, si, filter);
}
use of org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler in project felix by apache.
the class PerBundleHttpServiceImpl method registerFilter.
/**
* @see org.apache.felix.http.api.ExtHttpService#registerFilter(javax.servlet.Filter, java.lang.String, java.util.Dictionary, int, org.osgi.service.http.HttpContext)
*/
@Override
public void registerFilter(final Filter filter, final String pattern, final Dictionary initParams, final int ranking, final HttpContext context) throws ServletException {
if (filter == null) {
throw new IllegalArgumentException("Filter must not be null");
}
final Map<String, String> paramMap = new HashMap<String, String>();
if (initParams != null && initParams.size() > 0) {
Enumeration e = initParams.keys();
while (e.hasMoreElements()) {
Object key = e.nextElement();
Object value = initParams.get(key);
if ((key instanceof String) && (value instanceof String)) {
paramMap.put((String) key, (String) value);
}
}
}
final FilterInfo filterInfo = new FilterInfo(String.format("%s_%d", filter.getClass(), this.hashCode()), pattern, ranking, paramMap);
if (!filterInfo.isValid()) {
throw new ServletException("Invalid registration information for filter.");
}
final ExtServletContext httpContext = getServletContext(context);
final FilterHandler holder = new HttpServiceFilterHandler(httpContext, filterInfo, filter);
if (this.sharedHttpService.registerFilter(holder)) {
synchronized (this.localFilters) {
this.localFilters.add(holder);
}
}
}
Aggregations