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


Java Predicates类代码示例

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


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

示例1: createErrorContext

import io.undertow.predicate.Predicates; //导入依赖的package包/类
public static HttpHandler createErrorContext(final String slot) throws ModuleLoadException {
    final ClassPathResourceManager cpresource = new ClassPathResourceManager(getClassLoader(Module.getCallerModuleLoader(), ERROR_MODULE, slot), "");
    final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(cpresource)
            .setAllowed(not(path("META-INF")))
            .setDirectoryListingEnabled(false)
            .setCachable(Predicates.<HttpServerExchange>falsePredicate());

    //we also need to setup the default resource redirect
    return new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(ERROR_CONTEXT + DEFAULT_RESOURCE)), handler);
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:11,代码来源:ErrorContextHandler.java

示例2: addTo

import io.undertow.predicate.Predicates; //导入依赖的package包/类
public void addTo(RoutingHandler rh, OptionMap config) {
	List<Predicate> list = new ArrayList<>();
	list.add(this.predicate);
	list.add(this.matches);
	Route route = this.route;
	if (this.type != null && this.type.isEmpty() == false) {
		list.add(MIMEPredicate.accept(type));
		route = (req, res) -> {
			Object result = this.route.handle(req, res);
			res.type(this.type);
			return result;
		};
	}
	this.accepts.stream().filter(s -> s.isEmpty() == false)
			.map(s -> MIMEPredicate.contentType(s)).forEach(list::add);
	rh.add(Predicates.and(list.toArray(new Predicate[list.size()])), route,
			this.renderer);
}
 
开发者ID:taichi,项目名称:siden,代码行数:19,代码来源:RoutingDef.java

示例3: testEspeciallyPkgsAreNotRender

import io.undertow.predicate.Predicates; //导入依赖的package包/类
@Test
public void testEspeciallyPkgsAreNotRender() throws Exception {
	this.exchange.putAttachment(Core.CONFIG, Config.defaults().getMap());
	this.exchange.putAttachment(Core.RESPONSE, new SidenResponse(
			this.exchange));

	RoutingHandler target = new RoutingHandler(Testing.empty());
	target.add(Predicates.truePredicate(),
			(q, s) -> s.cookie("hoge", "fuga"),
			new MockUp<Renderer<Object>>() {
				@Mock(invocations = 0)
				void render(Object model, HttpServerExchange sink)
						throws IOException {
				}
			}.getMockInstance());

	target.handleRequest(this.exchange);
}
 
开发者ID:taichi,项目名称:siden,代码行数:19,代码来源:RoutingHandlerTest.java

示例4: testSimpleCall

import io.undertow.predicate.Predicates; //导入依赖的package包/类
@Test
public void testSimpleCall() throws Exception {
	Filter filter = new MockUp<Filter>() {
		@Mock(invocations = 2)
		public void filter(Request req, Response res, FilterChain chain)
				throws Exception {
			chain.next();
		}
	}.getMockInstance();

	FiltersHandler target = new FiltersHandler(Testing.mustCall());
	target.add(new FilterDef(Predicates.truePredicate(), filter));
	target.add(new FilterDef(Predicates.falsePredicate(),
			(req, res, ch) -> {
				throw new AssertionError();
			}));
	target.add(new FilterDef(Predicates.truePredicate(), filter));

	target.handleRequest(this.exchange);
}
 
开发者ID:taichi,项目名称:siden,代码行数:21,代码来源:FiltersHandlerTest.java

示例5: parse

import io.undertow.predicate.Predicates; //导入依赖的package包/类
public static List<PredicatedHandler> parse(final String contents, final ClassLoader classLoader) {
    String[] lines = contents.split("\\n");
    final List<PredicatedHandler> wrappers = new ArrayList<>();

    for (String line : lines) {
        if (line.trim().length() > 0) {
            Predicate predicate;
            HandlerWrapper handler;
            String[] parts = line.split("->");
            if (parts.length == 2) {
                predicate = PredicateParser.parse(parts[0], classLoader);
                handler = HandlerParser.parse(parts[1], classLoader);
            } else if (parts.length == 1) {
                predicate = Predicates.truePredicate();
                handler = HandlerParser.parse(parts[0], classLoader);
            } else {
                predicate = PredicateParser.parse(parts[0], classLoader);
                HandlerWrapper[] handlers = new HandlerWrapper[parts.length -1];
                for(int i = 0; i < handlers.length; ++i) {
                    handlers[i] = HandlerParser.parse(parts[i + 1], classLoader);
                }
                handler = new ChaninedHandlerWrapper(Arrays.asList(handlers));
            }
            wrappers.add(new PredicatedHandler(predicate, handler));
        }
    }
    return wrappers;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:PredicatedHandlersParser.java

示例6: gzip

import io.undertow.predicate.Predicates; //导入依赖的package包/类
public static HttpHandler gzip(HttpHandler next) {
    return new EncodingHandler(new ContentEncodingRepository()
              .addEncodingHandler("gzip",
                  // This 1000 is a priority, not exactly sure what it does.
                  new GzipEncodingProvider(), 1000,
                  // Anything under a content-length of 20 will not be gzipped
                  Predicates.truePredicate()
                  //Predicates.maxContentSize(20) // https://issues.jboss.org/browse/UNDERTOW-1234
                  ))
              .setNext(next);
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:12,代码来源:CustomHandlers.java

示例7: configurationCompressionIfNecessary

import io.undertow.predicate.Predicates; //导入依赖的package包/类
private HttpHandler configurationCompressionIfNecessary(HttpHandler httpHandler) {
	if (this.compression == null || !this.compression.getEnabled()) {
		return httpHandler;
	}
	ContentEncodingRepository repository = new ContentEncodingRepository();
	repository.addEncodingHandler("gzip", new GzipEncodingProvider(), 50,
			Predicates.and(getCompressionPredicates(this.compression)));
	return new EncodingHandler(repository).setNext(httpHandler);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:UndertowEmbeddedServletContainer.java

示例8: getCompressionPredicates

import io.undertow.predicate.Predicates; //导入依赖的package包/类
private Predicate[] getCompressionPredicates(Compression compression) {
	List<Predicate> predicates = new ArrayList<Predicate>();
	predicates.add(new MaxSizePredicate(compression.getMinResponseSize()));
	predicates.add(new CompressibleMimeTypePredicate(compression.getMimeTypes()));
	if (compression.getExcludedUserAgents() != null) {
		for (String agent : compression.getExcludedUserAgents()) {
			RequestHeaderAttribute agentHeader = new RequestHeaderAttribute(
					new HttpString(HttpHeaders.USER_AGENT));
			predicates.add(Predicates.not(Predicates.regex(agentHeader, agent)));
		}
	}
	return predicates.toArray(new Predicate[predicates.size()]);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:UndertowEmbeddedServletContainer.java

示例9: wrap

import io.undertow.predicate.Predicates; //导入依赖的package包/类
/**
 * Wraps the passed {@link ServletInitialHandler} with a PredicateHandler for serving static content.
 *
 * @param servletInitialHandler the ServletInitialHandler
 * @return PredicateHandler which decides whether to invoke ResourceHandler or pass on the request to
 * next handler in the chain which is ServletInitialHandler.
 * @see ServletInitialHandlerWrapper class header for detailed information.
 */
@Override
public HttpHandler wrap(HttpHandler servletInitialHandler) {
    Config cfg = Configs.DEFAULT.undertow();
    return Handlers.predicate(Predicates.and(Predicates.prefix(cfg.getString(RESOURCE_PREFIX)),
            Predicates.suffixes(cfg.getStringList(RESOURCE_EXTNS).toArray(new String[0]))),
            Handlers.resource(new ClassPathResourceManager(this.getClass().getClassLoader(),
                    cfg.getString(RESOURCE_MGR_PREFIX))),
            servletInitialHandler);
}
 
开发者ID:AdeptJ,项目名称:adeptj-runtime,代码行数:18,代码来源:ServletInitialHandlerWrapper.java

示例10: getCompressionPredicates

import io.undertow.predicate.Predicates; //导入依赖的package包/类
private Predicate[] getCompressionPredicates(Compression compression) {
	List<Predicate> predicates = new ArrayList<Predicate>();
	predicates.add(Predicates.maxContentSize(compression.getMinResponseSize()));
	predicates.add(new CompressibleMimeTypePredicate(compression.getMimeTypes()));
	if (compression.getExcludedUserAgents() != null) {
		for (String agent : compression.getExcludedUserAgents()) {
			RequestHeaderAttribute agentHeader = new RequestHeaderAttribute(
					new HttpString(HttpHeaders.USER_AGENT));
			predicates.add(Predicates.not(Predicates.regex(agentHeader, agent)));
		}
	}
	return predicates.toArray(new Predicate[predicates.size()]);
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:14,代码来源:UndertowEmbeddedServletContainer.java

示例11: addCacheHandler

import io.undertow.predicate.Predicates; //导入依赖的package包/类
private void addCacheHandler(final DeploymentInfo servletBuilder) {
    // this handles mime types and adds a simple cache for static files
    servletBuilder.addInitialHandlerChainWrapper(new HandlerWrapper() {
        @Override
        public HttpHandler wrap(final HttpHandler handler) {
          final ResourceHandler resourceHandler = new ResourceHandler(servletBuilder.getResourceManager());
            io.undertow.util.MimeMappings.Builder mimes = MimeMappings.builder();
            List<String> suffixList = new ArrayList<String>();
            // add font mime types not included by default
            mimes.addMapping("eot", "application/vnd.ms-fontobject");
            mimes.addMapping("otf", "font/opentype");
            mimes.addMapping("ttf", "application/x-font-ttf");
            mimes.addMapping("woff", "application/x-font-woff");
            suffixList.addAll(Arrays.asList(".eot",".otf",".ttf",".woff"));
            // add the default types and any added in web.xml files
            for(MimeMapping mime : servletBuilder.getMimeMappings()) {
                log.debug("Adding mime-type: " + mime.getExtension() + " - " + mime.getMimeType());
                mimes.addMapping(mime.getExtension(), mime.getMimeType());
                suffixList.add("."+mime.getExtension());
            }
            resourceHandler.setMimeMappings(mimes.build());
            String[] suffixes = new String[suffixList.size()];
            suffixes = suffixList.toArray(suffixes);
            // simple cacheHandler, someday maybe make this configurable
            final CacheHandler cacheHandler = new CacheHandler(new DirectBufferCache(1024, 10, 10480), resourceHandler);
            final PredicateHandler predicateHandler = predicate(Predicates.suffixes(suffixes), cacheHandler, handler);
            return predicateHandler;
        }
    });
}
 
开发者ID:cfmlprojects,项目名称:runwar,代码行数:31,代码来源:Server.java

示例12: createConsoleHandler

import io.undertow.predicate.Predicates; //导入依赖的package包/类
static ResourceHandlerDefinition createConsoleHandler(String slot, String resource) throws ModuleLoadException {
    final ClassPathResourceManager cpresource = new ClassPathResourceManager(getClassLoader(Module.getCallerModuleLoader(), ERROR_MODULE, slot), "");
    final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(cpresource)
            .setAllowed(not(path("META-INF")))
            .setResourceManager(cpresource)
            .setDirectoryListingEnabled(false)
            .setCachable(Predicates.<HttpServerExchange>falsePredicate());

    //we also need to setup the default resource redirect
    PredicateHandler predicateHandler = new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(CONTEXT + resource)), handler);
    return new ResourceHandlerDefinition(CONTEXT, resource, predicateHandler);
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:13,代码来源:ConsoleMode.java

示例13: testSimpleMatch

import io.undertow.predicate.Predicates; //导入依赖的package包/类
@Test
public void testSimpleMatch() throws Exception {
	RoutingHandler target = new RoutingHandler(Testing.empty());
	target.add(Predicates.truePredicate(), (q, s) -> "Hello",
			new MockUp<Renderer<Object>>() {
				@Mock(invocations = 1)
				void render(Object model, HttpServerExchange sink)
						throws IOException {
					assertEquals("Hello", model);
				}
			}.getMockInstance());
	target.handleRequest(this.exchange);
}
 
开发者ID:taichi,项目名称:siden,代码行数:14,代码来源:RoutingHandlerTest.java

示例14: testReturnOptinal

import io.undertow.predicate.Predicates; //导入依赖的package包/类
@Test
public void testReturnOptinal() throws Exception {
	RoutingHandler target = new RoutingHandler(Testing.empty());
	target.add(Predicates.truePredicate(), (q, s) -> Optional.of("Hello"),
			new MockUp<Renderer<Object>>() {
				@Mock(invocations = 1)
				void render(Object model, HttpServerExchange sink)
						throws IOException {
					assertEquals("Hello", model);
				}
			}.getMockInstance());
	target.handleRequest(this.exchange);
}
 
开发者ID:taichi,项目名称:siden,代码行数:14,代码来源:RoutingHandlerTest.java

示例15: testResponseCodeSettigIsOnce

import io.undertow.predicate.Predicates; //导入依赖的package包/类
@Test
public void testResponseCodeSettigIsOnce() throws Exception {
	this.exchange = new MockUp<HttpServerExchange>() {
		@Mock
		public boolean isInIoThread() {
			return false;
		}

		@Mock
		public HeaderMap getResponseHeaders() {
			return new HeaderMap();
		}

		@Mock(invocations = 1)
		public HttpServerExchange setResponseCode(final int responseCode) {
			return getMockInstance();
		}

		@Mock(invocations = 1)
		public HttpServerExchange endExchange() {
			return getMockInstance();
		}
	}.getMockInstance();

	this.exchange.putAttachment(Core.CONFIG, Config.defaults().getMap());
	this.exchange.putAttachment(Core.RESPONSE, new SidenResponse(
			this.exchange));

	RoutingHandler target = new RoutingHandler(Testing.empty());
	target.add(Predicates.truePredicate(),
			(q, s) -> s.redirect("/hoge/fuga/moge"), null);

	target.handleRequest(this.exchange);
}
 
开发者ID:taichi,项目名称:siden,代码行数:35,代码来源:RoutingHandlerTest.java


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