Apache Ext-CDI aka CODI and Rewrite integration issue

Splash Forums Rewrite Users Apache Ext-CDI aka CODI and Rewrite integration issue

This topic contains 5 replies, has 3 voices, and was last updated by  RedShadow 5 years ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #18692

    RedShadow
    Participant

    I had a nasty bug today and just finished to write a workaround for it, but you should really take a look at that. Unfortunatelly I have not so much insight into the rewrite code, so I can only contribute a proof of concept ^^

    In the attached maven project, which just contains an index page, codi and rewrite libs, you can reproduce the issue. Clicking on the link of the index page will cause a forever redirect.

    For people that are facing this issue and are looking for a workaround, here you go.

    public class CodiWindowIdFixConfigurationProvider extends

    HttpConfigurationProvider {

    @Override

    public Configuration getConfiguration(ServletContext context) {

    final Condition hasSession = new HttpCondition() {

    @Override

    public boolean evaluateHttp(HttpServletRewrite event, EvaluationContext context) {

    return event.getRequest().getSession(false) != null && !event.getRequest().getSession().isNew();

    }

    };

    return ConfigurationBuilder

    .begin()

    .defineRule()

    .when(Direction.isInbound().andNot(hasSession).and(QueryString.parameterExists("windowId")))

    .perform(new HttpOperation() {

    @Override

    public void performHttp(HttpServletRewrite event, EvaluationContext context) {

    Redirect.temporary(event.getContextPath() + event.getRequestPath()).perform(event, context);

    }

    });

    }

    @Override

    public int priority() {

    return Integer.MAX_VALUE;

    }

    }

    #22927

    Thanks for providing this sample application. I’ll have a look at it. But I’m on a one week vacation tomorrow, so it may take some time.

    #22928

    Hey RedShadow,

    Our file upload system was broken – could you please re-upload your attachment? Thanks! Sorry for the inconvenience.

    ~Lincoln

    #22929

    RedShadow
    Participant

    Of course, here you go.

    #22930

    RedShadow
    Participant

    Here is an updated version of the codi fix. I had some issues regarding the redirect codi does to append the windowId. The following will fix that problem by skipping rewrite handling when no windowId is present.

    public class CodiWindowIdFixConfigurationProvider extends

    HttpConfigurationProvider {

    @Override

    public Configuration getConfiguration(ServletContext context) {

    final Condition hasSession = new HttpCondition() {

    @Override

    public boolean evaluateHttp(HttpServletRewrite event, EvaluationContext context) {

    return event.getRequest().getSession(false) != null && !event.getRequest().getSession().isNew();

    }

    };

    return ConfigurationBuilder

    .begin()

    .defineRule()

    .when(Direction.isInbound().andNot(hasSession).and(QueryString.parameterExists("windowId")))

    .perform(new HttpOperation() {

    @Override

    public void performHttp(HttpServletRewrite event, EvaluationContext context) {

    Redirect.temporary(event.getContextPath() + event.getRequestPath()).and(Lifecycle.handled()).perform(event, context);

    }

    })

    .defineRule()

    .when(Direction.isInbound().andNot(QueryString.parameterExists("windowId")))

    .perform(Lifecycle.handled());

    }

    @Override

    public int priority() {

    return Integer.MAX_VALUE;

    }

    }

    #22931

    RedShadow
    Participant

    I think I managed to workaround all the issues with codi, at least my problems are gone now. Although the code can probably be optimized or put somewhere else to be more performant. If anyone has a better solution please share it!

    public class CodiWindowIdFixConfigurationProvider extends

    HttpConfigurationProvider {

    @Inject

    private WindowContextManager windowContextManager;

    @Override

    public Configuration getConfiguration(ServletContext context) {

    return ConfigurationBuilder

    .begin()

    .defineRule()

    .when(Direction.isInbound().andNot(Path.matches("/javax.faces.resource{0}")

    .where("0").matches(".*")).and(QueryString.parameterExists("windowId")))

    .perform(PhaseOperation.enqueue(new HttpOperation() {

    @Override

    public void performHttp(HttpServletRewrite event, EvaluationContext context) {

    if(!windowContextManager.getCurrentWindowContext().getId().equals(event.getRequest().getParameter("windowId"))){

    Redirect.temporary(event.getContextPath() + event.getRequestPath()).and(Lifecycle.handled()).perform(event, context);

    }

    }

    }).after(PhaseId.RESTORE_VIEW))

    .defineRule()

    .when(Direction.isInbound().andNot(QueryString.parameterExists("windowId"))

    .andNot(Path.matches("/javax.faces.resource{0}")

    .where("0").matches(".*")))

    .perform(Lifecycle.handled());

    }

    @Override

    public int priority() {

    return 0;

    }

    }

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

You must be logged in to reply to this topic.

Comments are closed.