本文整理汇总了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);
}
示例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();
}
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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);
}
示例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));
}
示例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);
}
示例9: getFilters
import com.sun.net.httpserver.Filter; //导入依赖的package包/类
@Override
public List<Filter> getFilters()
{
return _filters;
}
示例10: addHttpServerFilter
import com.sun.net.httpserver.Filter; //导入依赖的package包/类
public ODataJerseyServer addHttpServerFilter(Filter filter) {
httpServerFilters.add(filter);
return this;
}
示例11: getSecurityFilter
import com.sun.net.httpserver.Filter; //导入依赖的package包/类
public Filter getSecurityFilter() {
return securityFilter;
}
示例12: getFilters
import com.sun.net.httpserver.Filter; //导入依赖的package包/类
@Nullable
Filter[] getFilters();
示例13: getFilters
import com.sun.net.httpserver.Filter; //导入依赖的package包/类
@Override
public Filter[] getFilters() {
return new Filter[] { new GzipRequestFilter(), new DateResponseFilter() };
}
示例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;
}
示例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;
}