Java 类com.sun.net.httpserver.Filter 实例源码

项目:jpt-exercises    文件:Main.java   
private void start() throws IOException {
  HttpServer server = HttpServer.create(new InetSocketAddress(portNumber), queueSize);

  SessionRegistry sessionRegistry = new SessionRegistry();
  SessionFilter sessionFilter = new SessionFilter(sessionRegistry, "/login");
  AccessLogFilter accessLogFilter = new AccessLogFilter();

  List<Filter> defaultFilters = Arrays.asList(new Filter[] { accessLogFilter, sessionFilter });

  server.createContext("/", new StaticHandler()).getFilters().addAll(defaultFilters);
  server.createContext("/login", new LoginHandler(sessionRegistry, "/", "home")).getFilters().add(accessLogFilter); // no session filter or else infinite redirect loop!
  server.createContext("/search", new SearchHandler()).getFilters().addAll(defaultFilters);
  server.createContext("/language", new LanguageHandler()).getFilters().addAll(defaultFilters);
  final ExecutorService threadPool = Executors.newFixedThreadPool(poolSize);
  server.setExecutor(threadPool);
  server.start();
  LOG.info(() -> "Server is listening on port " + portNumber);
}
项目:Cricket    文件:Kernel.java   
private void setSecurityFilter(String filterName) {
    try {
        Class c = Class.forName(filterName);
        securityFilter = (Filter) c.newInstance();
    } catch (ClassCastException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        e.printStackTrace();
        securityFilter = new SecurityFilter();
    }
}
项目:Equella    文件:Main.java   
public Main() throws Exception
{
    filters = new ArrayList<Filter>();
    filters.add(new SuperDuperFilter());

    try( InputStream in = Main.class.getResourceAsStream("/version.properties") ) //$NON-NLS-1$
    {
        config = new ManagerConfig(new File(findInstall()), in);
    }
}
项目:RouterLogger    文件:HttpServerConfig.java   
@Override
public Filter[] getFilters() {
    final Filter[] defaultFilters = super.getFilters();
    if (isSslEnabled() && configuration.getBoolean("server.ssl.hsts.enabled", DEFAULT_SSL_HSTS_ENABLED)) {
        final Filter[] filters = Arrays.copyOf(defaultFilters, defaultFilters.length + 1);
        filters[filters.length - 1] = new HSTSResponseFilter(new ISupplier<Integer>() {
            @Override
            public Integer get() {
                return configuration.getInt("server.ssl.hsts.maxage", DEFAULT_SSL_HSTS_MAX_AGE);
            }
        }, new ISupplier<Boolean>() {
            @Override
            public Boolean get() {
                return configuration.getBoolean("server.ssl.hsts.includesubdomains", DEFAULT_SSL_HSTS_INCLUDESUBDOMAINS);
            }
        }, new ISupplier<Boolean>() {
            @Override
            public Boolean get() {
                return configuration.getBoolean("server.ssl.hsts.preload", DEFAULT_SSL_HSTS_PRELOAD);
            }
        });
        return filters;
    }
    else {
        return defaultFilters;
    }
}
项目:JFaceUtils    文件:LightweightHttpServer.java   
protected Collection<HttpContext> createContexts() {
    final Filter[] filtersArray = createFilters();
    final Collection<Filter> filtersList;
    if (filtersArray != null && filtersArray.length != 0) {
        filtersList = Arrays.asList(filtersArray);
    }
    else {
        filtersList = Collections.emptyList();
    }

    final Collection<HttpContext> httpContexts = new ArrayList<HttpContext>();
    final Authenticator authenticator = httpServerConfiguration.getAuthenticator();
    final HttpPathHandler[] handlersArray = createHandlers();
    if (handlersArray != null && handlersArray.length > 0) {
        for (final HttpPathHandler handler : handlersArray) {
            final HttpContext httpContext = server.createContext(handler.getPath(), handler);
            if (filtersArray != null && filtersArray.length != 0) {
                httpContext.getFilters().addAll(filtersList);
            }
            if (authenticator != null) {
                httpContext.setAuthenticator(authenticator);
            }
            httpContexts.add(httpContext);
        }
    }
    else {
        logger.log(Level.WARNING, JFaceMessages.get("msg.httpserver.configuration.handlers.none"));
    }
    return httpContexts;
}
项目:JFaceUtils    文件:LightweightHttpServerTest.java   
@Override
protected void service(HttpExchange exchange) throws IOException {
    for (final Filter filter : exchange.getHttpContext().getFilters()) {
        logger.fine(filter.description());
    }
    super.service(exchange);
}
项目:pi    文件:SimpleHttpServerFactoryBeanTest.java   
@Test
public void shouldSetFiltersAndAuthenticatorsOnHttpContext() throws Exception {
    // setup
    Map<String, HttpHandler> contexts = new HashMap<String, HttpHandler>();
    HttpHandler httpHandler = mock(HttpHandler.class);
    contexts.put("test1", httpHandler);

    Filter filter = mock(Filter.class);
    List<Filter> filters = new ArrayList<Filter>();
    filters.add(filter);

    Authenticator authenticator = mock(Authenticator.class);

    simpleHttpServerFactoryBean.setContexts(contexts);
    simpleHttpServerFactoryBean.setFilters(filters);
    simpleHttpServerFactoryBean.setAuthenticator(authenticator);

    List<Filter> httpContextFilters = new ArrayList<Filter>();

    HttpContext httpContext = mock(HttpContext.class);
    when(httpContext.getFilters()).thenReturn(httpContextFilters);
    when(httpServer.createContext("test1", httpHandler)).thenReturn(httpContext);

    // act
    simpleHttpServerFactoryBean.afterPropertiesSet();

    // assert
    verify(httpContext).setAuthenticator(authenticator);
    assertThat(httpContextFilters.contains(filter), is(true));
}
项目:mil-sym-java    文件:MultiPointServer.java   
@Override
public void doFilter(HttpExchange exchange, Filter.Chain chain)
    throws IOException {
    parseGetParameters(exchange);
    parsePostParameters(exchange);
    chain.doFilter(exchange);
}
项目:openbravo-pos    文件:JettyHttpContext.java   
@Override
public List<Filter> getFilters()
{
    return _filters;
}
项目:oreva    文件:ODataJerseyServer.java   
public ODataJerseyServer addHttpServerFilter(Filter filter) {
  httpServerFilters.add(filter);
  return this;
}
项目:Cricket    文件:Kernel.java   
public Filter getSecurityFilter() {
    return securityFilter;
}
项目:JFaceUtils    文件:IHttpServerConfig.java   
@Nullable
Filter[] getFilters();
项目:JFaceUtils    文件:HttpServerDefaultConfig.java   
@Override
public Filter[] getFilters() {
    return new Filter[] { new GzipRequestFilter(), new DateResponseFilter() };
}
项目:OpenbravoPOS    文件:JettyHttpContext.java   
@Override
public List<Filter> getFilters()
{
    return _filters;
}
项目:lams    文件:SimpleHttpServerFactoryBean.java   
/**
 * Register common {@link com.sun.net.httpserver.Filter Filters} to be
 * applied to all locally registered {@link #setContexts contexts}.
 */
public void setFilters(List<Filter> filters) {
    this.filters = filters;
}
项目:lams    文件:SimpleHttpServerJaxWsServiceExporter.java   
/**
 * Register common {@link com.sun.net.httpserver.Filter Filters} to be
 * applied to all detected {@link javax.jws.WebService} annotated beans.
 */
public void setFilters(List<Filter> filters) {
    this.filters = filters;
}
项目:spring4-understanding    文件:SimpleHttpServerFactoryBean.java   
/**
 * Register common {@link com.sun.net.httpserver.Filter Filters} to be
 * applied to all locally registered {@link #setContexts contexts}.
 */
public void setFilters(List<Filter> filters) {
    this.filters = filters;
}
项目:spring4-understanding    文件:SimpleHttpServerJaxWsServiceExporter.java   
/**
 * Register common {@link com.sun.net.httpserver.Filter Filters} to be
 * applied to all detected {@link javax.jws.WebService} annotated beans.
 */
public void setFilters(List<Filter> filters) {
    this.filters = filters;
}
项目:my-spring-cache-redis    文件:SimpleHttpServerFactoryBean.java   
/**
 * Register common {@link com.sun.net.httpserver.Filter Filters} to be
 * applied to all locally registered {@link #setContexts contexts}.
 */
public void setFilters(List<Filter> filters) {
    this.filters = filters;
}
项目:spring    文件:SimpleHttpServerFactoryBean.java   
/**
 * Register common {@link com.sun.net.httpserver.Filter Filters} to be
 * applied to all locally registered {@link #setContexts contexts}.
 */
public void setFilters(List<Filter> filters) {
    this.filters = filters;
}
项目:JFaceUtils    文件:LightweightHttpServer.java   
/**
 * Creates {@link com.sun.net.httpserver.Filter Filter} objects.
 * 
 * @return the array containing the filters.
 */
protected Filter[] createFilters() {
    return httpServerConfiguration.getFilters();
}
项目:class-guard    文件:SimpleHttpServerFactoryBean.java   
/**
 * Register common {@link com.sun.net.httpserver.Filter Filters} to be
 * applied to all locally registered {@link #setContexts contexts}.
 */
public void setFilters(List<Filter> filters) {
    this.filters = filters;
}
项目:class-guard    文件:SimpleHttpServerJaxWsServiceExporter.java   
/**
 * Register common {@link com.sun.net.httpserver.Filter Filters} to be
 * applied to all detected {@link javax.jws.WebService} annotated beans.
 */
public void setFilters(List<Filter> filters) {
    this.filters = filters;
}
项目:pi    文件:SimpleHttpServerFactoryBean.java   
/**
 * Register common {@link com.sun.net.httpserver.Filter Filters} to be applied to all locally registered
 * {@link #setContexts contexts}.
 */
public void setFilters(List<Filter> aFilters) {
    this.filters = aFilters;
}