Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doubled rewrite rules #217

Open
Yavin opened this issue Oct 2, 2015 · 4 comments
Open

Doubled rewrite rules #217

Yavin opened this issue Oct 2, 2015 · 4 comments

Comments

@Yavin
Copy link

Yavin commented Oct 2, 2015

Hi, i'm learning javaee7 and i have a problem with rewrite library. Rules defined by @RewriteConfiguration class are loaded twice in the chain of rules. To demonstrate i create a demo-minimal project:

my ConfigurationProvider class:

@RewriteConfiguration
public class RewriteConfigurationProvider extends HttpConfigurationProvider {

    @Override
    public Configuration getConfiguration(ServletContext context) {
        return ConfigurationBuilder.begin()
            .addRule()
                .when(Direction.isOutbound().and(Path.matches("/faces/{file}.xhtml")))
                .perform(Substitute.with("/faces/{file}-rewrite.xhtml"));
    }

    @Override
    public int priority() {
        return 10;
    }
}

And link in jsf:

<h:link outcome="/index.xhtml" value="index link"/>

The output link is then /faces/index-rewrite-rewrite.xhtml and expected result should be /faces/index-rewrite.xhtml

pom.xml:

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.ocpsoft.rewrite</groupId>
            <artifactId>rewrite-servlet</artifactId>
            <version>2.0.12.Final</version>
        </dependency>
        <dependency>
            <groupId>org.ocpsoft.rewrite</groupId>
            <artifactId>rewrite-config-prettyfaces</artifactId>
            <version>2.0.12.Final</version>
        </dependency>
    </dependencies>

Maybe i doing some wrong with configuration. Please help :)

@chkal
Copy link
Member

chkal commented Oct 3, 2015

There are multiple possible causes for this.

  • Rewrite could for some reason find the ConfigurationProvider twice
  • The JSF implementation could call HttpServletResponse.encodeURL() twice

Could you post the full log output please? And which container are you deploying to?

If you are using the new ConfigurationProvider API, you won't need to add rewrite-config-prettyfaces to your dependencies. But you should add rewrite-integration-faces to get the full JSF integration.

@Yavin
Copy link
Author

Yavin commented Oct 4, 2015

thanks @chkal,

(possibly only end of this post is important)

I'm using glassfish 4.1, here is whole log, and filtered output to phrase "ocp":

[2015-10-04T22:53:16.163+0200] [glassfish 4.1] [FINER] [] [] [tid: _ThreadID=47 _ThreadName=admin-listener(2)] [timeMillis: 1443991996163] [levelValue: 400] [CLASSNAME: org.ocpsoft.rewrite.annotation.scan.ByteCodeFilter] [[
  Found interesting annotation reference in constant pool: Lorg/ocpsoft/rewrite/annotation/RewriteConfiguration;]]
[2015-10-04T22:53:16.178+0200] [glassfish 4.1] [FINER] [] [] [tid: _ThreadID=47 _ThreadName=admin-listener(2)] [timeMillis: 1443991996178] [levelValue: 400] [CLASSNAME: org.ocpsoft.rewrite.annotation.ClassVisitorImpl] [[
  Executing handler chain on class com.example.RewriteConfigurationProvider: [org.ocpsoft.rewrite.annotation.handler.RewriteConfigurationHandler@74d16440]]]
  Loaded [1] org.ocpsoft.rewrite.spi.GlobalParameterProvider [org.ocpsoft.rewrite.instance.WildcardParameterProvider<0>]]]
[2015-10-04T22:53:16.464+0200] [glassfish 4.1] [FINER] [] [] [tid: _ThreadID=47 _ThreadName=admin-listener(2)] [timeMillis: 1443991996464] [levelValue: 400] [CLASSNAME: org.ocpsoft.rewrite.annotation.scan.ByteCodeFilter] [[
  Found interesting annotation reference in constant pool: Lorg/ocpsoft/rewrite/annotation/RewriteConfiguration;]]
[2015-10-04T22:53:16.468+0200] [glassfish 4.1] [FINER] [] [] [tid: _ThreadID=47 _ThreadName=admin-listener(2)] [timeMillis: 1443991996468] [levelValue: 400] [CLASSNAME: org.ocpsoft.rewrite.annotation.ClassVisitorImpl] [[
  Executing handler chain on class com.example.RewriteConfigurationProvider: [org.ocpsoft.rewrite.annotation.handler.RewriteConfigurationHandler@3be6f983]]]
...
 [2015-10-04T22:54:01.004+0200] [glassfish 4.1] [FINE] [] [] [tid: _ThreadID=35 _ThreadName=http-listener-1(4)] [timeMillis: 1443992041004] [levelValue: 500] [CLASSNAME: org.ocpsoft.rewrite.servlet.impl.DefaultHttpRewriteProvider] [[
  Rule [RuleBuilder [priority=null, id=, condition=And [[True, RuleBuilder [priority=10, id=, condition=And [[True, RuleBuilder [priority=null, id=, condition=And [[True, org.ocpsoft.rewrite.config.Direction$Outbound@2f95a5a1, /faces/{file}.xhtml]], operation=DefaultCompositeOperation [left=NoOp, right=Substitute [location=/faces/{file}-rewrite.xhtml]]]]], operation=DefaultCompositeOperation [left=NoOp, right=RuleBuilder [priority=null, id=, condition=And [[True, org.ocpsoft.rewrite.config.Direction$Outbound@2f95a5a1, /faces/{file}.xhtml]], operation=DefaultCompositeOperation [left=NoOp, right=Substitute [location=/faces/{file}-rewrite.xhtml]]]]]]], operation=DefaultCompositeOperation [left=NoOp, right=RuleBuilder [priority=10, id=, condition=And [[True, RuleBuilder [priority=null, id=, condition=And [[True, org.ocpsoft.rewrite.config.Direction$Outbound@2f95a5a1, /faces/{file}.xhtml]], operation=DefaultCompositeOperation [left=NoOp, right=Substitute [location=/faces/{file}-rewrite.xhtml]]]]], operation=DefaultCompositeOperation [left=NoOp, right=RuleBuilder [priority=null, id=, condition=And [[True, org.ocpsoft.rewrite.config.Direction$Outbound@2f95a5a1, /faces/{file}.xhtml]], operation=DefaultCompositeOperation [left=NoOp, right=Substitute [location=/faces/{file}-rewrite.xhtml]]]]]]]] matched and will be performed.]]
[2015-10-04T22:54:01.105+0200] [glassfish 4.1] [FINE] [] [] [tid: _ThreadID=35 _ThreadName=http-listener-1(4)] [timeMillis: 1443992041105] [levelValue: 500] [CLASSNAME: org.ocpsoft.rewrite.servlet.impl.DefaultHttpRewriteProvider] [[
  Rule [RuleBuilder [priority=null, id=, condition=And [[True, RuleBuilder [priority=10, id=, condition=And [[True, RuleBuilder [priority=null, id=, condition=And [[True, org.ocpsoft.rewrite.config.Direction$Outbound@184860c1, /faces/{file}.xhtml]], operation=DefaultCompositeOperation [left=NoOp, right=Substitute [location=/faces/{file}-rewrite.xhtml]]]]], operation=DefaultCompositeOperation [left=NoOp, right=RuleBuilder [priority=null, id=, condition=And [[True, org.ocpsoft.rewrite.config.Direction$Outbound@184860c1, /faces/{file}.xhtml]], operation=DefaultCompositeOperation [left=NoOp, right=Substitute [location=/faces/{file}-rewrite.xhtml]]]]]]], operation=DefaultCompositeOperation [left=NoOp, right=RuleBuilder [priority=10, id=, condition=And [[True, RuleBuilder [priority=null, id=, condition=And [[True, org.ocpsoft.rewrite.config.Direction$Outbound@184860c1, /faces/{file}.xhtml]], operation=DefaultCompositeOperation [left=NoOp, right=Substitute [location=/faces/{file}-rewrite.xhtml]]]]], operation=DefaultCompositeOperation [left=NoOp, right=RuleBuilder [priority=null, id=, condition=And [[True, org.ocpsoft.rewrite.config.Direction$Outbound@184860c1, /faces/{file}.xhtml]], operation=DefaultCompositeOperation [left=NoOp, right=Substitute [location=/faces/{file}-rewrite.xhtml]]]]]]]] matched and will be performed.]]

After some debugging i found there a 2 registered AnnotationConfigProvider's, digging deeper ServiceLoader:loadServiceFiles is finding 3 files:

jar:file:/home/.../target/pretty-faces-test/WEB-INF/lib/rewrite-annotations-impl-2.0.12.Final.jar!/META-INF/services/org.ocpsoft.rewrite.config.ConfigurationProvider
jar:file:/home/.../target/pretty-faces-test/WEB-INF/lib/rewrite-servlet-2.0.12.Final.jar!/META-INF/services/org.ocpsoft.rewrite.config.ConfigurationProvider
jar:file:/home/.../target/pretty-faces-test/WEB-INF/lib/rewrite-config-prettyfaces-2.0.12.Final.jar!/META-INF/services/org.ocpsoft.rewrite.config.ConfigurationProvider

I follow your advice to replace dependency to rewrite-integration-faces and now it work fine.

When i build application i was using WEB-INF/pretty-config.xml file (as described http://www.ocpsoft.org/prettyfaces/), but when i reached the point when i need some custom rewriting i declared @RewriteConfiguration class. I thought pretty-config.xml will store all "simple" rules, and @RewriteConfiguration will define some more advanced ones.

After some googling i found that prettyfaces is build on top of the rewrite project. But later on github i see that prettyfaces was merged into rewrite. It is confusing to me how should i use it. Could you explain if i can still use pretty-config.xml or there is other proper way of using rewrite?

@chkal
Copy link
Member

chkal commented Oct 5, 2015

The Rewrite PrettyFaces module basically provides a way to use the old PrettyFaces configuration style with Rewrite. So if you prefer to use XML for rule configuration, you can use this module. However, the new Rewrite configuration API is much more flexible.

Your original problem seems to be caused by the fact that there is rewrite-annotations-impl on your classpath. I'll leave this issue open so we can have a deeper look at what is causing this later.

@chkal
Copy link
Member

chkal commented Oct 5, 2015

Note to myself: Looks like the prettyfaces module declares a compile time dependency on rewrite-annotations-impl. Do we really need this? Shouldn't this be provided instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants