Search in sources :

Example 1 with UrlRewriter

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);
    }
}
Also used : Conf(org.tuckey.web.filters.urlrewrite.Conf) ModRewriteConfLoader(org.tuckey.web.filters.urlrewrite.utils.ModRewriteConfLoader) UrlRewriter(org.tuckey.web.filters.urlrewrite.UrlRewriter) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 2 with UrlRewriter

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");
    }
}
Also used : Dictionary(java.util.Dictionary) Conf(org.tuckey.web.filters.urlrewrite.Conf) UrlRewriter(org.tuckey.web.filters.urlrewrite.UrlRewriter) Document(org.w3c.dom.Document)

Aggregations

Conf (org.tuckey.web.filters.urlrewrite.Conf)2 UrlRewriter (org.tuckey.web.filters.urlrewrite.UrlRewriter)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Dictionary (java.util.Dictionary)1 ModRewriteConfLoader (org.tuckey.web.filters.urlrewrite.utils.ModRewriteConfLoader)1 Document (org.w3c.dom.Document)1