rewrite dynamic rule

Splash Forums Rewrite Users rewrite dynamic rule

This topic contains 8 replies, has 3 voices, and was last updated by  Lincoln Baxter III 1 year, 6 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #26765

    arcturus
    Participant

    hi guys,
    I need to add some dynamic rules depends on user connected.
    let’s say that i have 2 user type : AgentX, AgentY.
    AgentX is public agent, on the other hand agentY is a private agent

    So, i need to define a rule that basically set private or public in the url depends the user connected
    i define some rule like this code below :
    `.addRule(Join.path(“public/url”).to(“/url.xhtml”)).when(new HttpCondition() {

    @Override
    public boolean evaluateHttp(HttpServletRewrite arg0, EvaluationContext arg1) {
    UserSessionMbean userSessionMBean = null;
    boolean condition;
    try{
    userSessionMBean = JSFUtils.getSessionScoped(“userSession”); // get session method
    }catch(Exception e){
    e.printStackTrace();
    }
    if(userSessionMBean.isAgentX())
    condition = true;
    else if (userSessionMBean.isagentY()) {
    condition = false;
    }
    return condition;
    }
    });
    }
    return builder;
    `

    but its seems doesnt work, for some session NPE issue.
    rewrite runs in boot in server run so there’s no session created yet
    can i achieve this work ? please help me

    • This topic was modified 1 year, 6 months ago by  arcturus.
    • This topic was modified 1 year, 6 months ago by  arcturus.
    #26771

    arcturus
    Participant

    here’s my code.
    my use case already works fine with prettyfaces using
    <rewrite inbound=”false” match=”/public/hab/hab_login” processor=”rewrite.PrettyFacesProcessor”/>
    can i do something similar to this ? using rewrite

    Attachments:
    1. rewriteRule.txt
    #26773

    According to the stacktrace the error is caused by an NPE in your JSFUtils class. 😉

    But I guess that you are trying to access FacesContext there, correct? This won’t work, because the HttpCondition will be executed before the JSF lifecycle starts.

    I’m not completely sure how JSF handles session scoped managed beans, but I guess you could try something like that instead to obtain the bean:

    event.getRequest().getSession().getAttribute("userSession");
    

    Where event is the HttpServletRewrite passed to the condition.

    #26774

    Well, JSF Session Scoped Beans should be available in any Request. Only ConversationScoped beans have issues with filters (because they are implemented with a filter, but if FacesContext is null, that could be an issue…

    If you are CDI, I would recommend injecting the SessionScoped bean directly into your rewrite configuration. To do this, you will likely need to include rewrite-integration-cdi:

    http://www.ocpsoft.org/rewrite/docs/integration/cdi

    Or for spring:
    http://www.ocpsoft.org/rewrite/docs/integration/spring

    #26777

    arcturus
    Participant

    thak you both guys for giving interrest this issue :
    @Christian Kaltepoth :
    i tried to get session attribute using : event.getRequest().getSession().getAttribute("userSession");
    but i get NPE Exception (Check updated file attachement)
    i put all details

    @lincoln Baxter III :
    I’m not CDI, but please can i inject JSF beans by including rewrite-integration-faces ?
    i tried to include this jar file but its doesnt work

    Attachments:
    1. rewrite-issue.txt
    #26779

    That’s another NPE in YOUR code. I don’t see what is in “RewriteUrl.java:46” in your text file. Please tell us what is null in your sample code.

    #26780

    arcturus
    Participant

    check my class look like :
    i debug the RewriteUrl class but it’s seems like the rule is not builded !! any suggestion ?

    • This reply was modified 1 year, 6 months ago by  arcturus.
    • This reply was modified 1 year, 6 months ago by  arcturus.
    Attachments:
    1. RewriteUrl.java
    #26784

    arcturus
    Participant

    big thnx both of u guys it’s fixed
    i was trying to get session attribut from FacesContext.
    as @Christian Kaltepoth mentioned :

    But I guess that you are trying to access FacesContext there, correct? This won’t work, because the HttpCondition will be executed before the JSF lifecycle starts.

    so i get the session attribut using : event.getRequest().getSession().getAttribute(“userSession”);

    #26847

    Great! Glad you got it fixed!

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

You must be logged in to reply to this topic.

Comments are closed.