S2 String Trim Interceptor?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

S2 String Trim Interceptor?

Burton Rhodes
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!
Reply | Threaded
Open this post in threaded view
|

Re: S2 String Trim Interceptor?

Lukasz Lenart
2017-04-21 15:53 GMT+02:00 Burton Rhodes <[hidden email]>:

> 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: [hidden email]
For additional commands, e-mail: [hidden email]