URL encoding the entity ID in Velocity

Brent Putman putmanb at georgetown.edu
Wed Feb 3 15:56:44 EST 2016



On 2/3/16 3:29 PM, Wessel, Keith wrote:
> I've tried, and I'm closer, but I think I still need a hint for bean creation. I've got a bean with an id element of custom.urlEncoder and a class of java.net.URLEncoder.
>
> <bean id="custom.urlEncoder" class="java.net.URLEncoder" />

I don't know where you're putting that, but that doesn't look correct
for the Map-based bean we have commented in global.xml.  The general
pattern would be like this:

    <util:map id="shibboleth.CustomViewContext">
        <entry key="urlEncoder">
             ....
        </entry>
    </util:map>


And then you access in the template like $custom.get("urlEncoder") OR
$custom["urlEncoder"].

However...

In thinking about your actual use case... This is java.net.URLEncoder. 
You don't instantiate it, you're just calling a static method.

I've never personally done that in Velocity.  In searching, I think
what you need to do is inject a bean that is a java.lang.Class
instance.  They apparently added support for that in Velocity 1.6 [1].

Given the Spring wiring requirement here (i.e. not modifying Java
code), I think you'd want something like this [2]:

    <util:map id="shibboleth.CustomViewContext">
        <entry key="urlEncoder">
            <value type="java.lang.Class">java.net.URLEncoder</value>
        </entry>
    </util:map>


I don't have an immediate way to test.  Please give it a try and let us
know how it works out.


[1]
http://stackoverflow.com/questions/2329191/calling-class-methods-static-from-inside-a-velocity-view-page
[2]
http://stackoverflow.com/questions/1601015/spring-syntax-for-setting-a-class-object
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shibboleth.net/pipermail/users/attachments/20160203/6f3cbcd2/attachment.html>


More information about the users mailing list