• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

filter chain losing form post parameters

 
Darvesh Niz
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Guys,
A lot of people have mentioned about the request losing post parameters when it is routed through a filter chain.

We have the same issue where we have routed all request to go through a filter since web.xml does not support regex (we do some routing check in the actual filter itself to perform some logic if the request url is of specific pattern) but we have one request which is rest call and it has post parameters and we are losing
those parameters when the rest call is invoked through the filter chain.

is there anyway we can overcome this issue.
i have read some post where people capture request.getparametermap and re-create those form parameters.

Any code, idea or advice.

thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right off hand I would say one of your filters is reading the body of the request, thus consuming the POST parameters.

Bill
 
Darvesh Niz
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thinig we are doing in that filter is

will this result in losing of form parameters
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Does that include the use of getParameter("somename") or a similar call that gets parameter data? If so, be aware that for a POST request, this involves reading the body of the request. See the JavaDocs for the getParameter method where this side effect is discussed.

Bill
 
Darvesh Niz
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks William

the rest call which has the post parameters is coming in the else part and we not doing any thing just passing the control back to filter chain
 
Darvesh Niz
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also to add
i do see servletRequest.getParameterMap() having all my parameters intact in the else part of my code in the filter.

The next break point i have is on the rest call and there the parameter is empty.

is there a way i can reinforce those parameter at the filter side
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this point you are going to have to post some code. We can't guess what's going on.

There is no reason that parameters should disappear.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The getParameterMap method of course consumes the body of the request so subsequent filters can't see it.

is there a way i can reinforce those parameter at the filter side


Sure, but it isn't simple.

Your filter must be able to

1. grab the entire body of the request - presumably as a byte[] - and preserve it for:

2. Custom implementations of the ServletRequest interface methods such as getInputStream, etc. that depend on having a copy of the body of the request.

I suspect this has already been done multiple times but I am not familiar with existing filter toolkits.

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:
Your filter must be able to

1. grab the entire body of the request - presumably as a byte[] - and preserve it for:


Why?

Unless the filter's doing something really hinky with the input stream on its own, there's no reason to worry about the parameters or request body.

The filter should be able to use getParameter() and the servlet should be able to use getParameter().
 
Darvesh Niz
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys for proactive reply

There was one more filter in the filter chain which was actually consuming my post parameters, it did tamper the request, somehow it missed by eye

Anyway thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad you found it.

Tampering with the request behind the back of the container almost always ends up causing problems.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic