Join replaced by isInbound isOutbound not working

Splash Forums Rewrite Users Join replaced by isInbound isOutbound not working

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

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

    cilf
    Participant

    Hey. I must be doing something terribly wrong but it’s been bugging me for a while.

    I have this link in my jsf file:

    
    <h:link outcome="/artist-albums.xhtml">
        <f:param name="artistUrl" value="#{artist.url}"/>
        #{artist.name}
    </h:link>
    

    and a rule in my config

    
    .addRule(Join.path("/{artistUrl}").to("/artist-albums.xhtml"))
    .where("artistUrl").matches("[a-z0-9-]+")
    

    which is working fine. But when I try to replace the rule with (the same)

    
    .addRule()
    .when(Direction.isInbound().and(Path.matches("/{artistUrl}")))
    .perform(Forward.to("/artist-albums.xhtml"))
    .where("artistUrl").matches("[a-z0-9-]+")
    
    .addRule()
    .when(Direction.isOutbound().and(Path.matches("/artist-albums.xhtml")))
    .perform(Substitute.with("/{artistUrl}"))
    .where("artistUrl").matches("[a-z0-9-]+")
    

    I suddenly get

    
    javax.servlet.ServletException: The value of required parameter [artistUrl] was null.
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
    io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
    io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)
    org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:226)
    io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
    io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
    io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
    io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
    io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)
    io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
    io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
    io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)
    io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
    io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
    io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
    io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
    io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)
    io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
    io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)
    io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)
    io.undertow.server.Connectors.executeRootHandler(Connectors.java:177)
    io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    java.lang.Thread.run(Thread.java:745)
    

    Any ideas?

    #26459

    The reason this is occurring is because you have not bound the value of {artistUrl} to anything. You need to bind it to something like this:

    .addRule()
    .when(Direction.isInbound().and(Path.matches("/{artistUrl}")))
    .perform(Forward.to("/artist-albums.xhtml"))
    .where("artistUrl").matches("[a-z0-9-]+").bindsTo(RequestBinding.parameter())
    
    .addRule()
    .when(Direction.isOutbound().and(Path.matches("/artist-albums.xhtml")))
    .perform(Substitute.with("/{artistUrl}"))
    .where("artistUrl").matches("[a-z0-9-]+").bindsTo(RequestBinding.parameter())
    

    Other kinds of bindings include:

    El.property()
    El.method()

    And a few others (search for implementations of Binding.

    I hope this helps!
    ~Lincoln

    #26466

    cilf
    Participant

    It’s outbound rule which is not working. I put there

    
    RequestBinding.parameter("artistUrl")
    

    but still the same exception :-/

    #26467

    You need to bind {artistUrl} to something that exists.

    #26468

    Also, you probably want to fire the rule only when that parameter exists…

    .addRule()
    .when(Direction.isOutbound().and(Path.matches("/artist-albums.xhtml")).and(RequestParameter.exists("artistUrl")))
    .perform(Substitute.with("/{artistUrl}"))
    .where("artistUrl").matches("[a-z0-9-]+").bindsTo(RequestBinding.parameter())

    Etc..

    #26470

    cilf
    Participant

    You need to bind {artistUrl} to something that exists.

    I don’t get it.

    If you have inbound you can inject the {artistUrl} into a bean by using .bindsTo which is great since you can then work with the injected value within that bean.

    What I don’t understand is into what should I inject (bind) the outbounding {artistUrl}? I just need it to create the URL by the combination of filename and parameter like the Join. does..

    #26472
    .addRule()
    .when(Direction.isOutbound().and(Path.matches("/artist-albums.xhtml")).and(Query.parameterExists("artistUrl")))
    .perform(Substitute.with("/{artistUrl}"))
    .where("artistUrl").matches("[a-z0-9-]+"))

    Try the above. The point is that {artistUrl} needs a value, and if that value does not come from a previously matched {variable} binding in a condition in the .when() or .perform() clauses, then rewrite won’t know what to put there. It can’t automatically figure out where you want that value to come from if you haven’t already defined a parameter with that name. Now that I know what you want to do, I think the above should work, but note, this assumes you are attempting to rewrite an outbound URL of the following form:

    /artist-albums.xhtml?artistUrl=URL

    Sorry for not picking up on what you wanted to do sooner. Let me know if I misunderstood.

    #26474

    cilf
    Participant

    Yup. This one works! Thanks.

    #26476

    Awesome! Sorry it took so long to figure out what you wanted 🙂 It’s hard to go from a lot of code to a little code sometimes. Join does many many things “for you”.

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

You must be logged in to reply to this topic.

Comments are closed.