use of org.tuckey.web.filters.urlrewrite.UrlRewriter in project camel by apache.
the class UrlRewriteFilter method doStart.
@Override
protected void doStart() throws Exception {
ObjectHelper.notNull(camelContext, "camelContext");
if (conf == null) {
if (modRewriteConfFile != null) {
LOG.debug("Using mod rewrite config file: {} as config for urlRewrite", modRewriteConfFile);
InputStream is = camelContext.getClassResolver().loadResourceAsStream(modRewriteConfFile);
if (is == null) {
throw new IOException("Cannot load mod rewrite config file: " + modRewriteConfFile);
}
try {
String text = camelContext.getTypeConverter().mandatoryConvertTo(String.class, is);
ModRewriteConfLoader loader = new ModRewriteConfLoader();
conf = new Conf();
loader.process(text, conf);
} finally {
IOHelper.close(is);
}
} else if (modRewriteConfText != null) {
LOG.debug("Using modRewriteConfText: {} as config for urlRewrite", modRewriteConfText);
ModRewriteConfLoader loader = new ModRewriteConfLoader();
conf = new Conf();
loader.process(modRewriteConfText, conf);
} else if (configFile != null) {
LOG.debug("Using config file: {} as config for urlRewrite", configFile);
InputStream is = camelContext.getClassResolver().loadResourceAsStream(configFile);
if (is == null) {
throw new IOException("Cannot load config file: " + configFile);
}
try {
conf = new Conf(is, configFile);
} finally {
IOHelper.close(is);
}
}
if (conf != null) {
// set options before initializing
conf.setUseQueryString(isUseQueryString());
conf.setUseContext(isUseContext());
if (getDefaultMatchType() != null) {
conf.setDefaultMatchType(getDefaultMatchType());
}
if (getDecodeUsing() != null) {
conf.setDecodeUsing(getDecodeUsing());
}
conf.initialise();
}
if (conf == null || !conf.isOk()) {
throw new IllegalStateException("Error configuring config file: " + configFile);
}
}
if (urlRewriter == null) {
urlRewriter = new UrlRewriter(conf);
}
}
use of org.tuckey.web.filters.urlrewrite.UrlRewriter in project sling by apache.
the class SlingUrlRewriteFilter method configure.
private void configure(final ComponentContext context) {
logger.info("configuring URL rewriter");
final Dictionary properties = context.getProperties();
final String rules = PropertiesUtil.toString(properties.get(REWRITE_RULES_PARAMETER), DEFAULT_REWRITE_RULES);
final Document document = createDocument(rules);
if (document == null) {
logger.error("creating rules document failed");
return;
}
final Conf conf = new DocumentConf(document);
conf.initialise();
clearRewriter();
if (conf.isOk()) {
logger.info("rewrite configuration is ok");
} else {
logger.error("rewrite configuration is NOT ok");
return;
}
rewriter = new UrlRewriter(conf);
logger.info("rewrite engine is enabled: {}", conf.isEngineEnabled());
if (conf.getRules() != null) {
logger.info("number of rewrite rules: {}", conf.getRules().size());
} else {
logger.info("no rewrite rules");
}
}
Aggregations