本文整理汇总了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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}