コード例 #1
0
    /** @since servlet-api-3.0 */
    @Override
    public FilterRegistration.Dynamic addFilter(String filterName, Filter filter) {
      if (isStarted()) throw new IllegalStateException();

      if (filterName == null || "".equals(filterName.trim()))
        throw new IllegalStateException("Missing filter name");

      if (!_enabled) throw new UnsupportedOperationException();

      final ServletHandler handler = ServletContextHandler.this.getServletHandler();
      FilterHolder holder = handler.getFilter(filterName);
      if (holder == null) {
        // new filter
        holder = handler.newFilterHolder(Source.JAVAX_API);
        holder.setName(filterName);
        holder.setFilter(filter);
        handler.addFilter(holder);
        return holder.getRegistration();
      }

      if (holder.getClassName() == null && holder.getHeldClass() == null) {
        // preliminary filter registration completion
        holder.setFilter(filter);
        return holder.getRegistration();
      } else return null; // existing filter
    }
コード例 #2
0
    @Override
    public FilterRegistration getFilterRegistration(String filterName) {
      if (!_enabled) throw new UnsupportedOperationException();

      final FilterHolder holder =
          ServletContextHandler.this.getServletHandler().getFilter(filterName);
      return (holder == null) ? null : holder.getRegistration();
    }
コード例 #3
0
    @Override
    public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
      if (!_enabled) throw new UnsupportedOperationException();

      HashMap<String, FilterRegistration> registrations = new HashMap<String, FilterRegistration>();
      ServletHandler handler = ServletContextHandler.this.getServletHandler();
      FilterHolder[] holders = handler.getFilters();
      if (holders != null) {
        for (FilterHolder holder : holders)
          registrations.put(holder.getName(), holder.getRegistration());
      }
      return registrations;
    }