Search in sources :

Example 1 with HttpServiceFilterHandler

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);
}
Also used : ExtServletContext(org.apache.felix.http.base.internal.context.ExtServletContext) Filter(javax.servlet.Filter) HttpServiceFilterHandler(org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler) FilterInfo(org.apache.felix.http.base.internal.runtime.FilterInfo)

Example 2 with HttpServiceFilterHandler

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);
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) Enumeration(java.util.Enumeration) ExtServletContext(org.apache.felix.http.base.internal.context.ExtServletContext) HashMap(java.util.HashMap) HttpServiceFilterHandler(org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler) FilterInfo(org.apache.felix.http.base.internal.runtime.FilterInfo) FilterHandler(org.apache.felix.http.base.internal.handler.FilterHandler) HttpServiceFilterHandler(org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler)

Aggregations

ExtServletContext (org.apache.felix.http.base.internal.context.ExtServletContext)2 HttpServiceFilterHandler (org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler)2 FilterInfo (org.apache.felix.http.base.internal.runtime.FilterInfo)2 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Filter (javax.servlet.Filter)1 ServletException (javax.servlet.ServletException)1 FilterHandler (org.apache.felix.http.base.internal.handler.FilterHandler)1