You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Burton Rhodes <bu...@gmail.com> on 2017/04/21 13:53:06 UTC

S2 String Trim Interceptor?

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();
}

Thanks!

Re: S2 String Trim Interceptor?

Posted by Lukasz Lenart <lu...@apache.org>.
2017-04-21 15:53 GMT+02:00 Burton Rhodes <bu...@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