URL encoding the entity ID in Velocity

Cantor, Scott cantor.2 at osu.edu
Wed Feb 3 15:51:42 EST 2016


On 2/3/16, 3:29 PM, "users on behalf of Wessel, Keith" <users-bounces at shibboleth.net on behalf of kwessel at illinois.edu> 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.

It only has static methods, I'm not sure what you get from calling a static method on a class instance like that. If that works, then your problem might just be the Velocity part and how you named it.

><bean id="custom.urlEncoder" class="java.net.URLEncoder" />

Is that inside a map? You wouldn't need an "id" attribute in that case. The bean you declare MUST be called custom. What you define it to be is arbitrary. It can't be called anything else.

I'm not really sure how you declare a bean that's a class type. There's the brute force way of calling Class.forName(), in which case the class here would be java.lang.Class and you have to use factory-method="forName" to call the static method that returns the class object you want.

<bean class="java.lang.Class" factory-method="forName" c:_0="classname" />

That may not be 100% accurate, but the gist is.

There's a Spring expression syntax of T(classname), but I don't know how to marry that to a bean declaration. I know how to inject that into a property or argument with #{T(classname)} but that's not the same thing.

>I'm assuming it needs some properties associated with it. Because, if I try to use it in my login template as:
>
>$custom(urlEncoder).encode("$entityID","utf-8")

Brent mentioned you can use brackets if the bean called "custom" is defined to be a map, but I don't think you can use parentheses to access a named element in a map.

>Am I missing something from the bean definition? Or from the way I'm calling it? Or both?

Both I think.

>My apologies for the elementary questions; this is a part of Java that I _should_ know more about.

It's not really Java, it's Java and Spring and Velocity, and they're all slightly offset from each other.

-- Scott



More information about the users mailing list