1

I am trying to fix a bug in sitebricks where it consumes the input stream in of the data of all servlets even those not using site bricks.

HiddenMethodFilter.java line:66

String methodName = httpRequest.getParameter(this.hiddenFieldName);

See http://code.google.com/p/google-sitebricks/issues/detail?id=45

Oleg Mikheev
  • 17,186
  • 14
  • 73
  • 95
Usman Ismail
  • 17,999
  • 14
  • 83
  • 165

2 Answers2

3

Yes you can provide your own request, see Modify request parameter with servlet filter.

Furthermore may be extending the wrong sitebricks filter might be easier than chaining.

Community
  • 1
  • 1
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • the new request would need to encapsulate duplicate contents of POST in form of some byte array InputStream, right? – Oleg Mikheev Dec 16 '11 at 15:16
  • That seems a bit scary because we could be copying unbounded array into memory – Usman Ismail Dec 16 '11 at 15:22
  • No, `HttpServletRequestWrapper` wraps the original request. – Joop Eggen Dec 16 '11 at 15:48
  • https://github.com/dhanji/sitebricks/pull/14 Here is the fix I came up with. Thanks for your help. – Usman Ismail Dec 16 '11 at 16:10
  • It's still not really obvious to me how HttpServletRequestWrapper prevents the input stream to be read to get the parameters in a POST request. The question you are linking to describes a completely different problem. – jarnbjo Dec 16 '11 at 16:12
  • @Usman: The fix you committed does not change anything. Without subclassing HttpServletRequestWrapper and adding your own behaviour, all methods will simply delegate to the original request, which was passed to the constructor. – jarnbjo Dec 16 '11 at 16:20
  • @jambjo you are basically right, but suppressing parameters and such would be feasible. Also since no deep copying is involved, it is feasible for this use-case. True, I am glad a better solution was found. – Joop Eggen Dec 16 '11 at 16:29
-2

Obivously not, since the servlet container is required to read and consume the data in the InputStream before it is able to give you the request parameters. The other way around if you consume the InputStream first, the container won't have access to the request parameters later.

Why can't you fix the bug using the suggestion in the linked issue suggesting to configure the HiddenMethodFilter only for the URLs related to Site Bricks?

jarnbjo
  • 33,923
  • 7
  • 70
  • 94
  • Sitebricks uses annotations to determine which urls it serves so that information is hard to get in the filter. – Usman Ismail Dec 16 '11 at 15:23
  • Why can't you check the URL in the filter before invoking getParameter, so that the HttpServletRequest is left untouched for requests to URLs not handled by SiteBricks? – jarnbjo Dec 16 '11 at 16:10
  • Although it may be possible to inject the list of URL handled by sitebricks into the filter I haven't found a way to do it yet. ps I did not down vote your answer, this is the ideal solution. – Usman Ismail Dec 16 '11 at 16:17