Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ignore blank request parameters
@Component
public class HackedParametersProvider extends OgnlParametersProvider {
public HackedParametersProvider(...., HttpServletRequest request, ...) {
super(....., new HackedRequest(request), ....);
}
}
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.google.common.base.Predicate;
public class HackedRequest extends HttpServletRequestWrapper {
public HackedRequest(HttpServletRequest request) {
super(request);
}
@Override
public Enumeration getParameterNames() { //ignores blank parameters
Set<String> names = new HashSet<String>();
Enumeration<String> superNames = super.getParameterNames();
while (superNames.hasMoreElements()) {
String name = superNames.nextElement();
if (!Strings.isNullOrEmpty(getParameter(name))) {
names.add(name);
}
}
return Collections.enumeration(names);
}
@Override
public Map getParameterMap() {
return Maps.filterKeys(super.getParameterMap(), new Predicate<String>() {
public boolean apply(String name) {
return !Strings.isNullOrEmpty(getParameter(name));
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment