javalite / activeweb

ActiveWeb moved, see below

Home Page:http://javalite.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reuse getRequestString() in filter and controller?

jacktang opened this issue · comments

Now getRequestString can't be invoked twice since the underlying is InputStream.

In my case, I called getRequestString in before filter and want to re-call it in the controller. And it returns null in controller. I solved the issue by storing the value into values() by assign("requestString", getRequestString), and retrieving the value in controller. The shortcoming is the controller depends on the filter. If I removed the filter, I had to modify the controller code.

How about to make getRequestString reusable?

@jacktang this is not a bug. The request string is simply content read from ServletRequest InputStream. This content can only be read once, as from any other InputStream. Making it available to be re-read multiple times in the framework is fraught with danger - imagine someone sends a 50mb file? The current behavior is in line with general logic of web apps. You can also use thread local to pass data from filter to controller. However, in any case, you need to think how much heap you will be allocating under a load (multiple concurrent requests).