use of org.tuckey.web.filters.urlrewrite.Conf in project runwar by cfmlprojects.
the class UrlRewriteFilterTest method simpleApacheHConf.
@Test
public void simpleApacheHConf() throws IOException, ServletException, InvocationTargetException {
Conf conf = new Conf(servletContext, new FileInputStream(new File("src/test/resources/urlrewrite.htaccess")), "urlrewrite.htaccess", null, true);
assertTrue(conf.isEngineEnabled());
assertTrue(conf.isOk());
assertTrue(conf.getRules().size() > 0);
NormalRewrittenUrl rewrittenRequest;
MockRequest request;
UrlRewriter urlRewriter = new UrlRewriter(conf);
request = new MockRequest("/notthere");
rewrittenRequest = (NormalRewrittenUrl) urlRewriter.processRequest(request, response);
assertNotNull(rewrittenRequest);
assertEquals("index.cfm/notthere", rewrittenRequest.getTarget());
}
use of org.tuckey.web.filters.urlrewrite.Conf in project engine by craftercms.
the class SiteContextFactory method getUrlRewriter.
protected UrlRewriter getUrlRewriter(SiteContext siteContext, String[] urlRewriteConfPaths, ResourceLoader resourceLoader) {
String siteName = siteContext.getSiteName();
String confPath = null;
Resource confResource = null;
Conf conf = null;
UrlRewriter urlRewriter = null;
logger.info("--------------------------------------------------");
logger.info("<Loading URL rewrite engine for site: " + siteName + ">");
logger.info("--------------------------------------------------");
try {
for (int i = urlRewriteConfPaths.length - 1; i >= 0; i--) {
Resource resource = resourceLoader.getResource(urlRewriteConfPaths[i]);
if (resource.exists()) {
confPath = urlRewriteConfPaths[i];
confResource = resource;
break;
}
}
if (confResource != null) {
// By convention, if it ends in .xml, it's an XML-style url rewrite config, else it's a mod_rewrite-style
// url rewrite config
boolean modRewriteStyleConf = !confPath.endsWith(".xml");
try (InputStream is = confResource.getInputStream()) {
conf = new Conf(servletContext, is, confPath, "", modRewriteStyleConf);
logger.info("URL rewrite configuration loaded @ " + confResource);
}
}
if (conf != null) {
if (conf.isOk() && conf.isEngineEnabled()) {
urlRewriter = new UrlRewriter(conf);
logger.info("URL rewrite engine loaded for site " + siteName + " (conf ok)");
} else {
logger.error("URL rewrite engine not loaded, there might have been conf errors");
}
}
return urlRewriter;
} catch (Exception e) {
throw new SiteContextCreationException("Unable to load URL rewrite conf for site '" + siteName + "'", e);
} finally {
logger.info("--------------------------------------------------");
logger.info("</Loading URL rewrite engine for site: " + siteName + ">");
logger.info("--------------------------------------------------");
}
}
use of org.tuckey.web.filters.urlrewrite.Conf in project load-balancer by RestComm.
the class BalancerUrlRewriteFilter method init.
public void init(BalancerRunner balancerRunner) throws ServletException {
log.info("filter init called");
Conf conf = new BalancerConf(balancerRunner.getConfiguration().getHttpConfiguration().getUrlrewriteRule());
checkConfLocal(conf);
}
use of org.tuckey.web.filters.urlrewrite.Conf 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.Conf 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