当前位置: 首页>>代码示例>>Java>>正文


Java Filter类代码示例

本文整理汇总了Java中com.sun.net.httpserver.Filter的典型用法代码示例。如果您正苦于以下问题:Java Filter类的具体用法?Java Filter怎么用?Java Filter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Filter类属于com.sun.net.httpserver包,在下文中一共展示了Filter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
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);
}
 
开发者ID:arnauldvm,项目名称:jpt-exercises,代码行数:19,代码来源:Main.java

示例2: setSecurityFilter

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
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();
    }
}
 
开发者ID:gskorupa,项目名称:Cricket,代码行数:10,代码来源:Kernel.java

示例3: Main

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
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);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:11,代码来源:Main.java

示例4: getFilters

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
@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;
	}
}
 
开发者ID:Albertus82,项目名称:RouterLogger,代码行数:28,代码来源:HttpServerConfig.java

示例5: createContexts

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
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;
}
 
开发者ID:Albertus82,项目名称:JFaceUtils,代码行数:31,代码来源:LightweightHttpServer.java

示例6: service

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
@Override
protected void service(HttpExchange exchange) throws IOException {
	for (final Filter filter : exchange.getHttpContext().getFilters()) {
		logger.fine(filter.description());
	}
	super.service(exchange);
}
 
开发者ID:Albertus82,项目名称:JFaceUtils,代码行数:8,代码来源:LightweightHttpServerTest.java

示例7: shouldSetFiltersAndAuthenticatorsOnHttpContext

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
@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));
}
 
开发者ID:barnyard,项目名称:pi,代码行数:31,代码来源:SimpleHttpServerFactoryBeanTest.java

示例8: doFilter

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
@Override
public void doFilter(HttpExchange exchange, Filter.Chain chain)
    throws IOException {
    parseGetParameters(exchange);
    parsePostParameters(exchange);
    chain.doFilter(exchange);
}
 
开发者ID:missioncommand,项目名称:mil-sym-java,代码行数:8,代码来源:MultiPointServer.java

示例9: getFilters

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
@Override
public List<Filter> getFilters()
{
    return _filters;
}
 
开发者ID:iMartinezMateu,项目名称:openbravo-pos,代码行数:6,代码来源:JettyHttpContext.java

示例10: addHttpServerFilter

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
public ODataJerseyServer addHttpServerFilter(Filter filter) {
  httpServerFilters.add(filter);
  return this;
}
 
开发者ID:teiid,项目名称:oreva,代码行数:5,代码来源:ODataJerseyServer.java

示例11: getSecurityFilter

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
public Filter getSecurityFilter() {
    return securityFilter;
}
 
开发者ID:gskorupa,项目名称:Cricket,代码行数:4,代码来源:Kernel.java

示例12: getFilters

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
@Nullable
Filter[] getFilters();
 
开发者ID:Albertus82,项目名称:JFaceUtils,代码行数:3,代码来源:IHttpServerConfig.java

示例13: getFilters

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
@Override
public Filter[] getFilters() {
	return new Filter[] { new GzipRequestFilter(), new DateResponseFilter() };
}
 
开发者ID:Albertus82,项目名称:JFaceUtils,代码行数:5,代码来源:HttpServerDefaultConfig.java

示例14: setFilters

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:SimpleHttpServerFactoryBean.java

示例15: setFilters

import com.sun.net.httpserver.Filter; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:SimpleHttpServerJaxWsServiceExporter.java


注:本文中的com.sun.net.httpserver.Filter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。