本文整理汇总了Java中org.eclipse.jetty.rewrite.handler.RewriteRegexRule类的典型用法代码示例。如果您正苦于以下问题:Java RewriteRegexRule类的具体用法?Java RewriteRegexRule怎么用?Java RewriteRegexRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RewriteRegexRule类属于org.eclipse.jetty.rewrite.handler包,在下文中一共展示了RewriteRegexRule类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRewriteHandler
import org.eclipse.jetty.rewrite.handler.RewriteRegexRule; //导入依赖的package包/类
private static Handler getRewriteHandler(Handler wrapped) {
RewriteHandler rewrites = new RewriteHandler();
rewrites.setOriginalPathAttribute(ORIGINAL_PATH_ATTRIBUTE_NAME);
rewrites.setRewriteRequestURI(true);
rewrites.setRewritePathInfo(true);
for (Map.Entry<String, String> entry : REGEX_REWRITE_RULES.entrySet()) {
RewriteRegexRule rule = new RewriteRegexRule();
rule.setRegex(entry.getKey());
rule.setReplacement(entry.getValue());
rewrites.addRule(rule);
}
rewrites.setHandler(wrapped);
return rewrites;
}
示例2: configureRedirectionRules
import org.eclipse.jetty.rewrite.handler.RewriteRegexRule; //导入依赖的package包/类
private Handler configureRedirectionRules(Handler appHandler) {
RewriteHandler handler = new RewriteHandler();
handler.setRewriteRequestURI(false);
handler.setRewritePathInfo(false);
handler.setOriginalPathAttribute("requestedPath");
RewriteRegexRule uiRewriteRule = new RewriteRegexRule();
uiRewriteRule.setRegex("^/collector/.*");
uiRewriteRule.setReplacement("/");
handler.addRule(uiRewriteRule);
handler.setHandler(appHandler);
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] {handler, appHandler});
return handlerCollection;
}
示例3: startWithRewrite
import org.eclipse.jetty.rewrite.handler.RewriteRegexRule; //导入依赖的package包/类
public static Server startWithRewrite(int port) throws Exception {
Server server = new Server(port);
ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/api");
contextHandler.addServlet(TestServlet.class, "/epigraph/*");
RewriteHandler rewriteHandler = new RewriteHandler();
rewriteHandler.addRule(new RewriteRegexRule("(.*?)/getUser/(.*)", "$1/epigraph/users/$2:record(firstName,lastName)"));
rewriteHandler.setHandler(contextHandler);
server.setHandler(rewriteHandler);
server.start();
return server;
}
示例4: getRewriteHandler
import org.eclipse.jetty.rewrite.handler.RewriteRegexRule; //导入依赖的package包/类
private Optional<Handler> getRewriteHandler(Handler handler) {
try {
String rewriteFilePath = configuration.getRewriteFilePath();
if (rewriteFilePath != null && !(rewriteFilePath = rewriteFilePath.trim()).isEmpty()) {
RewriteHandler rewriteHandler = new RewriteHandler();
rewriteHandler.setRewritePathInfo(false);
rewriteHandler.setRewriteRequestURI(true);
rewriteHandler.setOriginalPathAttribute("__path");
rewriteHandler.setHandler(handler);
JavaType listRuleType = getMapper().getTypeFactory().constructParametricType(List.class, RewriteRule.class);
List<RewriteRule> rules = getMapper().readValue(new FileInputStream(rewriteFilePath), listRuleType);
boolean isAnyRuleActive = false;
for (RewriteRule rule : rules) {
if (rule.isActive()) {
RewriteRegexRule regexRule = new RewriteRegexRule();
regexRule.setRegex(rule.getFrom());
regexRule.setReplacement(rule.getTo());
rewriteHandler.addRule(regexRule);
isAnyRuleActive = true;
}
}
return isAnyRuleActive ? Optional.of(rewriteHandler) : Optional.empty();
}
} catch (IOException e) {
STARTUP_LOGGER.error("Unable to read Rewrite Rules", e);
}
return Optional.empty();
}