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


Java RedirectHandler类代码示例

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


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

示例1: handleRequest

import io.undertow.server.handlers.RedirectHandler; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    User user = exchange.getAttachment(AuthReader.USER);

    Role role = Role.GUEST;
    if (user != null) {
        role = user.getRole();
    }

    if (role.lessThan(this.requiredRole)) {
        // or, you know, an error page
        List<String> errors = Arrays.asList("https://www.youtube.com/watch?v=vTIIMJ9tUc8", "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
        new RedirectHandler(errors.get((int) (Math.random() * errors.size()))).handleRequest(exchange);
    } else {
        next.handleRequest(exchange);
    }
}
 
开发者ID:xSke,项目名称:Pxls,代码行数:18,代码来源:RoleGate.java

示例2: createErrorContext

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

示例3: createStaticContentHandler

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

import io.undertow.server.handlers.RedirectHandler; //导入依赖的package包/类
/**
 * Returns a new redirect handler
 *
 * @param location The redirect location
 * @return A new redirect handler
 */
public static RedirectHandler redirect(final String location) {
    return new RedirectHandler(location);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:Handlers.java


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