struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lukasz Lenart <lukaszlen...@apache.org>
Subject Re: S2 String Trim Interceptor?
Date Mon, 24 Apr 2017 06:42:23 GMT
2017-04-21 15:53 GMT+02:00 Burton Rhodes <burtonrhodes@gmail.com>:
> Since the invocation.getInvocationContext().getParameters().toMap() method
> is now deprecated, how would I refactor my String Trim interceptor to trim
> incoming parameters?  The HttpParameters parameter objects are designed to
> be "immutable".  Some posts online have suggested type converters, but
> seems like this is the perfect use for an interceptor.
>
> My trim interceptor code is below...
>
> protected String doIntercept(ActionInvocation invocation) throws Exception {
>     Map<String, String[]> parameters =
> invocation.getInvocationContext().getParameters().toMap();
>     for (String param : parameters.keySet()) {
>         if (isIncluded(param)) {
>             String[] values = parameters.get(param);
>             for (int i = 0; i < values.length; i++) {
>                 values[i] = values[i].trim();
>             }
>         }
>     }
>
>     return invocation.invoke();
> }

HttpParameters httpParameters = HttpParameters.create(parameters).build();
invocation.getInvocationContext().setParameters(htttpParameters);

this should work.


Regards
-- 
Ɓukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message