Hi guys,

The SpringBeanRouter.resolveUri() method in 1.1.1 has a potential problem, if 
you specify restlet in Spring configuration file without an id like this way:

<bean name="/product-folders" scope="prototype" class="..."> </bean>

Your BeanFinder will never be attached the URI "/product-folders". The reason 
is that the resolveUri() method tries to get name and other aliases from id, 
see the code below

    protected String resolveUri(String resourceName,
            ConfigurableListableBeanFactory factory) {
        for (final String alias : factory.getAliases(resourceName)) {
            if (alias.startsWith("/")) {
                return alias;
            }
        }

        return null;
    }

if you don't specify and ID in the Spring configuration file 
factory.getAliases(resourceName) will return null when the passed in 
resourceName is actually the bean name. 
To workaround this, you have to specify an ID for each restlet, eg,
<bean id="_product-folders" name="/product-folders" scope="prototype" 
class="..."> </bean>

Note, the id cannot be the same as the name because XML id cannot contain 
characters in URI like "/" or "{id}". Also, it's troublesome to specify id for 
each bean. So, how can I just simply specify name without IDs?

I made it by changing resolveUri as below

    protected String resolveUri(String resourceName,
                ApplicationContext factory) {
        String aliasName = null;
        if (resourceName.startsWith("/")) {
                aliasName = resourceName;
        } else {
            for (final String alias : factory.getAliases(resourceName)) {
                if (alias.startsWith("/")) {
                    aliasName = alias;
                    break;
                }
            }
        }
        logger.debug("resolveUri: alias=" + aliasName);
        return aliasName;
    }

I first check resourceName, if you don't specify an ID, bean name will be 
passed in as resourceName, in this case, just return the  beanName if it starts 
with a slash.
If you specify an ID, bean id will be passed in, then getAliases() will return 
the beanName of that id. it's done.

Tested with 1.1.1

What do you guys think?

Regards,
Daniel

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1169062

Reply via email to