time condition in rewrite rule along with other rules

Splash Forums Rewrite Users time condition in rewrite rule along with other rules

This topic contains 9 replies, has 3 voices, and was last updated by  Serkan Durusoy 9 years, 10 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
  • #18220

    Serkan Durusoy

    Hi Everyone,

    I have the following configuration:

    package com.dna.bifincan.root.urlrewrite;

    import com.ocpsoft.rewrite.config.Configuration;

    import com.ocpsoft.rewrite.config.ConfigurationBuilder;

    import com.ocpsoft.rewrite.config.Direction;

    import com.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;

    import com.ocpsoft.rewrite.servlet.config.Path;

    import com.ocpsoft.rewrite.servlet.config.Redirect;

    import javax.servlet.ServletContext;

    public class BifincanConfigurationProvider extends HttpConfigurationProvider {


    public int priority() {

    return 10;



    public Configuration getConfiguration(final ServletContext context) {

    return ConfigurationBuilder.begin()







    reference: http://ocpsoft.org/support/topic/redirect-from-root-app-to-app-with-other-context-in-same-host-in-tomcat

    Now, I also want a time based rule integrated into this, namely:

    If current time is before some date (for example 2012-03-15 00:00:00), then don’t use the above config, but instead redirect (maybe forward) all requests to /somepath/somepage.html

    I’ll use this to deploy the app, but have a countdown page and have the app show the countdown page until the grand opening

    So, does anyone have an idea how I can accomplish this within rewrite?



    Rewrite provides a JodaTime integration module.


    With this you can do something like:

    return ConfigurationBuilder.begin()
    .and(JodaTime.matches(new TimeCondition() {
    public boolean matches(DateTime date) {
    return date.isAfter(new DateMidnight(2013, 1, 1));

    You can do EVERYTHING with Rewrite! ;)


    Serkan Durusoy

    Wow, that was great, thanks !!

    And if I don’t want to bloat my libraries with jodatime, how can use builtin date/calendar packages?

    Can I use basic date operators within .and(JodaTime.matches(new TimeCondition() instead of using JodaTime?


    Serkan Durusoy

    Hmm, I think instead of complicating the configuration,

    can I write more than one configuration provider

    use one for time

    and the other for general purpose redirect

    and set priority for time config 10

    and set priority for general config 20

    would that work?


    Yes, you could create different configuration with different priorities to separate the rules. This totally makes sense if you have completely independent configurations.

    If you don’t want to use JodaTime for this, you could implement a matching condition yourself. Something like:

    return ConfigurationBuilder.begin()
    .and(new Condition() {
    public boolean evaluate(Rewrite rewrite, EvaluationContext ctx)
    // do whatever you want

    Just return true if you want the condition to match and false otherwise.


    Serkan Durusoy

    This was really helpful.

    By the way, are you planning a documentation for rewrite?

    I mean yes, there are good examples (although they are confusing since most are embedded in the socialpm project) but a document like the one for prettyfaces would be very good.

    Not only for developers, but for you guys as well, documentation is key to getting good traction, promoting rewrite, getting people like me to use it without being afraid and all :)


    You are totally right. We will definitively write some documentation soon.

    The only problem is that currently Rewrite has only some Alpha release. So we are currently not sure whether there will be major API changes until 1.0 get’s released. So it makes sense for us to do the documentation a bit later.

    BTW: We are really looking for feedback on the Rewrite API. If you have any ideas or problems please let us know! :)


    Serkan Durusoy

    We are going to use rewrite on a hopefully high traffic web site, although for basic purposes (to pass root paths to app paths), but I’ll share our experience once we get some stats.

    keep up the good work!


    Awesome! I’d love to know how your app performs, if and where there are any performance bottlenecks! Is the API suitable to your needs?

    Looking forward to your feedback!

    Also, if you’d like to get involved in the source-code, feel free to hack on GitHub! https://github.com/ocpsoft/rewrite

    Everyone is welcome to contribute!

    My biggest questions right now are:

    * Where and how do you think we should organize the built-in Conditions/Rules?

    * What package structure makes the most sense?

    * Are the static Condition builders (e.g. Redirect.to(“blah”)) convenient or confusing?


    Serkan Durusoy

    Hi Lincoln,

    It is too early for me to reply your questions since we are in our first few days into using rewrite, and also ours is a very basic use-case, but I’ll sure share our experience.


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

The forum ‘Rewrite Users’ is closed to new topics and replies.

Comments are closed.