本文整理汇总了Java中org.eclipse.jetty.rewrite.handler.RewriteHandler.setOriginalPathAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java RewriteHandler.setOriginalPathAttribute方法的具体用法?Java RewriteHandler.setOriginalPathAttribute怎么用?Java RewriteHandler.setOriginalPathAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.rewrite.handler.RewriteHandler
的用法示例。
在下文中一共展示了RewriteHandler.setOriginalPathAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRewriteHandler
import org.eclipse.jetty.rewrite.handler.RewriteHandler; //导入方法依赖的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.RewriteHandler; //导入方法依赖的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: getRewriteHandler
import org.eclipse.jetty.rewrite.handler.RewriteHandler; //导入方法依赖的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();
}
示例4: startWebserver
import org.eclipse.jetty.rewrite.handler.RewriteHandler; //导入方法依赖的package包/类
private void startWebserver() {
JSONObject config = getConfig();
webport = Integer.parseInt((String)config.get("port"));
org.eclipse.jetty.util.log.Log.setLog(new NullLogger());
webserver = new Server(webport);
webserver.setSessionIdManager(new HashSessionIdManager());
RewriteHandler rewriteHandler = new RewriteHandler();
rewriteHandler.setRewriteRequestURI(true);
rewriteHandler.setRewritePathInfo(true);
rewriteHandler.setOriginalPathAttribute("requestedPath");
RedirectRegexRule rule = new RedirectRegexRule();
rule.setRegex("/");
rule.setReplacement("/index");
rewriteHandler.addRule(rule);
WebAppContext dynamicHandler = new WebAppContext();
String webDir = this.getClass().getClassLoader().getResource("web").toExternalForm();
dynamicHandler.setResourceBase(webDir);
dynamicHandler.addServlet(new ServletHolder(new IndexServlet(this)),"/index");
dynamicHandler.addServlet(new ServletHolder(new LTIServlet(this)),"/lti");
dynamicHandler.addServlet(new ServletHolder(new TokenServlet(this)),"/token");
dynamicHandler.addServlet(new ServletHolder(new AssignmentServlet(this)),"/assignment");
dynamicHandler.addServlet(new ServletHolder(new ConsumerServlet(this)),"/consumer");
dynamicHandler.addServlet(new ServletHolder(new LTIConfigServlet()),"/config.xml");
ResourceHandler staticHandler = new ResourceHandler();
String staticDir = this.getClass().getClassLoader().getResource("static").toExternalForm();
staticHandler.setResourceBase(staticDir);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { rewriteHandler, staticHandler, dynamicHandler, new DefaultHandler() });
webserver.setHandler(handlers);
try {
webserver.start();
} catch (Exception e) {
getLogger().severe("Failed to start server.");
}
}
示例5: start
import org.eclipse.jetty.rewrite.handler.RewriteHandler; //导入方法依赖的package包/类
public void start() throws Exception {
((ServerConnector) server.getConnectors()[0]).setReuseAddress(true);
// Root context
context.setContextPath("/abnormal");
// Setup static content
context.setResourceBase("src/main/webapp/");
context.addServlet(DefaultServlet.class, "/");
// Enable Jersey debug output
context.setInitParameter("com.sun.jersey.config.statistic.Trace", "true");
// Enable CORS - cross origin resource sharing
FilterHolder cors = new FilterHolder();
cors.setInitParameter("allowedOrigins", "https?://localhost:*, https?://*.e-navigation.net:*");
cors.setInitParameter("allowedHeaders", "*");
cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD");
cors.setFilter(new CrossOriginFilter());
context.addFilter(cors, "*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC, DispatcherType.INCLUDE));
// Little hack to satisfy OpenLayers URLs in DMA context
RewritePatternRule openlayersRewriteRule = new RewritePatternRule();
openlayersRewriteRule.setPattern("/abnormal/theme/*");
openlayersRewriteRule.setReplacement("/abnormal/js/theme/");
RewriteHandler rewrite = new RewriteHandler();
rewrite.setRewriteRequestURI(true);
rewrite.setRewritePathInfo(false);
rewrite.setOriginalPathAttribute("requestedPath");
rewrite.addRule(openlayersRewriteRule);
rewrite.setHandler(context);
server.setHandler(rewrite);
// Setup Guice-Jersey integration
context.addEventListener(new GuiceServletContextListener() {
@Override
protected Injector getInjector() {
return Guice.createInjector(new RestModule(
repositoryName,
pathToEventDatabase,
eventRepositoryType,
eventDataDbHost,
eventDataDbPort,
eventDataDbName,
eventDataDbUsername,
eventDataDbPassword
));
}
});
context.addFilter(com.google.inject.servlet.GuiceFilter.class, "/rest/*", EnumSet.allOf(DispatcherType.class));
// Start the server
server.start();
}