xiaodududu / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Guice's include() and forward() should conform to servlet standards #647

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Currently Guice mangles include() and forward() request attributes

Two suggested solutions.

1) Hand off to the servlet engine itself to do the forwarding properly, as 
suggested with example code and a patch for v2.0 by tmikov in bug 522. Sadly 
this fix somehow didn't make it into 3.0, and of course the patch doesn't work 
against 3.0.

2) Fix Guice so that it's forwarding logic conforms to the servlet 
specification helpfully described in summary at... 
http://www.caucho.com/resin-3.0/webapp/faq.xtp#include
...and here...
http://www.caucho.com/resin-3.0/webapp/faq.xtp#forward
...and detailed in pages 91 and 92 Sections 9.3.1 and 9.4.2 of the formal 
servlet standard JSR315 available at http://www.jcp.org/en/jsr/detail?id=315

Libraries which depend on forwarding or inclusion and expect Guice to specify 
the path info correctly in return values and request attributes are currently 
totally broken in Guice. 

For example, a ForwardResolution is a standard technique for handling a form 
submission and then serving a result jsp in Stripes, which cannot be made to 
work at all in Guice, because the path information is messed up so bad that the 
corresponding resources can't be found after the forward.

http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/acti
on/ForwardResolution.html

Without this change, I and many others will be forced to resort to web.xml 
after much shouting and debugging to workaround this issue in Guice-servlet. 
This means sadly that it's easier to do without it rather than have two 
different places to specify servlet routing, one of which works sometimes.

Original issue reported on code.google.com by c...@cefn.com on 13 Aug 2011 at 9:25

GoogleCodeExporter commented 9 years ago
Is there any interest in fixing this bug?

I believe it's fairly major when mainstream Java servlet libraries like Stripes 
are broken and unfixable within a servlet engine because of something which is 
surely only a few minutes work; adding 5 request attributes inside the logic of 
both Guice forward(...) and guice include(...) respectively to conform to 
servlet standards.

The bug has been open for a very long time too.

I gave up trying to make sense of the Guice stubs and test framework after a 
fair amount of struggling to recreate this as a test case. What I need to do is 
NOT write stubs, and have the Guice framework actually execute the invalid 
forward or include (hence demonstrating its failure to update the mandatory 
request attributes). I cannot figure out how to execute this within the Guice 
svn source, sorry, though I tried.

Original comment by c...@cefn.com on 12 Nov 2011 at 6:42