Created
November 10, 2010 13:37
-
-
Save lucascs/670852 to your computer and use it in GitHub Desktop.
ignore blank request parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class HackedParametersProvider extends OgnlParametersProvider { | |
public HackedParametersProvider(...., HttpServletRequest request, ...) { | |
super(....., new HackedRequest(request), ....); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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