Ignore JSF resources

Splash Forums Rewrite Users Ignore JSF resources

This topic contains 4 replies, has 3 voices, and was last updated by  fabricciois 2 years, 2 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #26254

    fabricciois
    Participant

    Hello:

    I am migrating my system of PrettyFaces to Rewrite and I have a problem, when I try to create a rule that ignores JSF resources, for example, if I put this in my browser
    http://localhost:8080/rewrite/testing/sat the system shows me that the resource is not available (Error 404)

    This is my rule:

        	.addRule(Join.path("/{param1}/{app}").to("/page/app.xhtml"))
           		 .perform(PhaseOperation.enqueue(new IgnorePostbackOperation(Invoke.binding(El.retrievalMethod("systemAction.app")))
           		 ).after(PhaseId.RESTORE_VIEW))
           		.where("param1").matches("^((?!javax).)*$")

    how can i make JSF resources are ignored?, my param1 can take almost any value, I have 15 values ​​for param1 reserved
    Thank you very much for your help

    #26255

    Hey! The best way I’ve found to do this is to make sure you use the Resource.exists() condition, you can also use the ServletMapping.includes(). For instance:

    /*
                    * Block direct file access.
                    */
                   .addRule()
                   .when(DispatchType.isRequest().and(Direction.isInbound())
                            .and(Path.matches("/{p}.xhtml"))
                            .and(Resource.exists("/{p}.xhtml"))
                            .andNot(ServletMapping.includes("/{p}")))
                   .perform(SendStatus.error(404))
                   .where("p").matches(".*")
    
                   /*
                    * Application Routes
                    */
                   .addRule(Join.path("/{p}/").to("/faces/{p}/index.xhtml").withChaining())
                   .when(Resource.exists("/{p}/index.xhtml"))
                   .where("p").matches(".*")
    
                   .addRule(Join.path("/{p}").to("/faces/{p}.xhtml").withChaining())
                   .when(Resource.exists("/{p}.xhtml"))
                   .where("p").matches(".*")
    
    #26275

    fabricciois
    Participant

    Hi Lincoln:

    Thank you very much for your answer, in my case, I think I could not use Resource.exists() because the parameters(param1, app) can take almost any value, I am implementing something like the profiles of social networks. My problem is when I access http://localhost:8080/rewrite/testing/sat. the method app() of my ManagedBean (SystemAction) runs multiple times, because JSF resources also filter such as: http://localhost:8087/rewrite/javax.faces.resource/jsf.js.xhtml?ln=javax.faces

    thanks for your help, again.

    #26280

    You could also try to create a custom contraint for the parameter. This way you can write some custom code that checks whether the parameter has the “correct” format. Something like:

    .where( "param1" ).constrainedBy( new Constraint<String>() {
      @Override
      public boolean isSatisfiedBy( Rewrite event, EvaluationContext context, String value ) {
        return !value.contains( "javax.faces" );
      }
    } )
    
    #26287

    fabricciois
    Participant

    Thank you very much, that solved my problem.

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

You must be logged in to reply to this topic.

Comments are closed.