Multiple rewrite url value from database

Splash Forums Rewrite Users Multiple rewrite url value from database

This topic contains 10 replies, has 4 voices, and was last updated by  MFCN 1 year, 4 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #26865

    muhkah
    Participant

    Hi all,

    I’m new in “rewrite”. I have project with Spring and Primefaces. I’ve successfully configured rewrite and it works great!. My case now, I stored my url value in database (ex: all *.faces), and want all of them rewritten by ConfigurationProvider. Is it possible to multiple .addrule, let’s say something like this:

    
    ConfigurationBuilder.begin()
    for (){
       .addRule(Join.path(rewrite_url_from_db_1).to(string_url_from_db_1)) ...
    }
    ;

    Is there any way to solve it?.

    Thanks for kind response.

    #26866

    Sure, just don’t chain the calls to ‘addRule()’ and instead do something like:

    ConfigurationBuilder builder = ConfigurationBuilder.begin();
    for( ... ) {
       builder.addRule(Join.path(rewrite_url_from_db_1).to(string_url_from_db_1));
    }
    

    😉

    #26867

    muhkah
    Participant

    Thanks a lot Christian! :), indeed helpful ^^.

    #27012

    MFCN
    Participant

    Hi all.

    In my application there is a form for maintenance of the system url. I need to update the Configuration when I make a chage in this register. I’ve done an implementation of HttpConfigurationCacheProvider with an observer method that is called when an event is triggered, this one set a boolean to reload the Configuration, but the getConfiguration is not called again.

    How can I do this?

    #27015

    The configuration is created only once at application startup. So instead you should create a custom condition which detects the mode you are in. In this case you won’t need to change the configuration at runtime.

    #27016

    MFCN
    Participant

    Can you show me an example, please? Remembering that my rules are persisted in a database.

    #27019

    I was thinking about something like this:

    
    ConfigurationBuilder builder = ConfigurationBuilder.begin();
    for( ... ) {
       builder.addRule(Join.path(rewrite_url_from_db_1).to(string_url_from_db_1))
          .when(new HttpCondition() {
               @Override
               public boolean evaluateHttp(HttpServletRewrite event, EvaluationContext context)
               {
                  // check for maintenance mode
               }
          });
    }
    
    
    #27026

    MFCN
    Participant

    I think I was not clear in my explanation. The form is designed to map the .xhtml files to url‘s, for example:

    I have a ../pages/admin/index.xhtml file, in the form we register the url /admin to that file.

    The question is when I update the url of that page to /administration, at that time I would like to update the cache or ConfigurationProvider.

    #27027

    Not sure what that best way to handle this requirement is. There is a ConfigurationCacheProvider SPI that (by default) caches the configuration forever.

    API:
    https://github.com/ocpsoft/rewrite/blob/master/api/src/main/java/org/ocpsoft/rewrite/spi/ConfigurationCacheProvider.java

    Default implementation:
    https://github.com/ocpsoft/rewrite/blob/master/impl-servlet/src/main/java/org/ocpsoft/rewrite/servlet/impl/ServletContextConfigurationCacheProvider.java

    You could register your own implementation that basically disables caching or forces configuration reloading at certain events. I guess you will have a look at the source. 🙂

    #27028

    Christian is right, you probably want to either trigger a purge of the the ServletContext configuration cache:

    context.put(ServletContextConfigurationCacheProvider.class.getName() + "_cachedConfig", null)

    Or… you can implement your own HttpConfigurationCacheProvider and register it as documented here:

    https://github.com/ocpsoft/rewrite/blob/master/api/src/main/java/org/ocpsoft/rewrite/spi/ConfigurationCacheProvider.java#L25

    (Just make sure the priority is set to a lower number than the existing ServletContext cache provider’s priority (to override it.)

    However, in order for this to work, you will also need to disable the ServletContext cache entirely:

     <context-param>
        <param-name>org.ocpsoft.rewrite.config.CONFIG_RELOADING</param-name>
        <param-value>true</param-value>
      </context-param>

    ~Lincoln

    #27029

    MFCN
    Participant

    Thanks a lot Christian and Lincoln, all works perfectly.

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

Comments are closed.