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


Java PredicateHandler类代码示例

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


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

示例1: createErrorContext

import io.undertow.server.handlers.PredicateHandler; //导入依赖的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: addCacheHandler

import io.undertow.server.handlers.PredicateHandler; //导入依赖的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

示例3: createStaticContentHandler

import io.undertow.server.handlers.PredicateHandler; //导入依赖的package包/类
static ResourceHandlerDefinition createStaticContentHandler(ResourceManager resource, String context) {
    final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(resource)
            .setCacheTime(60 * 60 * 24 * 31)
            .setAllowed(not(path("META-INF")))
            .setResourceManager(resource)
            .setDirectoryListingEnabled(false)
            .setCachable(not(suffixes(NOCACHE_JS, APP_HTML, INDEX_HTML)));

    // avoid clickjacking attacks: console must not be included in (i)frames
    SetHeaderHandler frameHandler = new SetHeaderHandler(handler, "X-Frame-Options", "SAMEORIGIN");
    // we also need to setup the default resource redirect
    PredicateHandler predicateHandler = new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(context + DEFAULT_RESOURCE)), frameHandler);
    return new ResourceHandlerDefinition(context, DEFAULT_RESOURCE, predicateHandler);
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:15,代码来源:DomainUtil.java

示例4: createConsoleHandler

import io.undertow.server.handlers.PredicateHandler; //导入依赖的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

示例5: wrapWithStaticHandler

import io.undertow.server.handlers.PredicateHandler; //导入依赖的package包/类
protected HttpHandler wrapWithStaticHandler(HttpHandler baseHandler, String path) {
    // static path is given relative to application root
    if (!new File(path).isAbsolute()) {
        path = WunderBoss.options().get("root", "").toString() + File.separator + path;
    }
    if (!new File(path).exists()) {
        log.debug("Not adding static handler for nonexistent directory {}", path);
        return baseHandler;
    }
    log.debug("Adding static handler for {}", path);
    final ResourceManager resourceManager =
            new CachingResourceManager(1000, 1L, null,
                                       new FileResourceManager(new File(path), 1 * 1024 * 1024), 250);
    String[] welcomeFiles = new String[] { "index.html", "index.html", "default.html", "default.htm" };
    final List<String> welcomeFileList = new CopyOnWriteArrayList<>(welcomeFiles);
    final ResourceHandler resourceHandler = new ResourceHandler()
            .setResourceManager(resourceManager)
            .setWelcomeFiles(welcomeFiles)
            .setDirectoryListingEnabled(false);

    return new PredicateHandler(new Predicate() {
            @Override
            public boolean resolve(HttpServerExchange value) {
                try {
                    Resource resource = resourceManager.getResource(value.getRelativePath());
                    if (resource == null) {
                        return false;
                    }
                    if (resource.isDirectory()) {
                        Resource indexResource = getIndexFiles(resourceManager, resource.getPath(), welcomeFileList);
                        return indexResource != null;
                    }
                    return true;
                } catch (IOException ex) {
                    return false;
                }
            }
    }, resourceHandler, baseHandler);
}
 
开发者ID:projectodd,项目名称:wunderboss,代码行数:40,代码来源:UndertowWeb.java

示例6: predicateHandler

import io.undertow.server.handlers.PredicateHandler; //导入依赖的package包/类
private static PredicateHandler predicateHandler(HttpHandler headersHandler) {
    return Handlers.predicate(exchange -> CONTEXT_PATH.equals(exchange.getRequestURI()),
            Handlers.redirect(TOOLS_DASHBOARD_URI), headersHandler);
}
 
开发者ID:AdeptJ,项目名称:adeptj-runtime,代码行数:5,代码来源:Server.java


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