Rhett, I agree on the setAttachment semantics. I'd still like to see something like the setDefaultAttachment method (e.g. setNoPath attachment) without using the setAttachments method as it is a lot simpler to configure. For all other cases the current router works fine.
Another option would be where you could specify a more regular expresssion like pattern. You could then match this case using ^$ as the path (i.e beginning and end of line with no content or to match / and "" it would be ^/?$? Not sure how we'd get the template params in there as java regex doesn't allow you to name groups of matches. Paul On 8-Apr-09, at 4:18 PM, Rhett Sutphin wrote: > Hi Paul, > > On Apr 8, 2009, at 10:18 AM, Paul Austin wrote: > >> Jerome, >> >> Here is an implementation which extends SpringBeanRouter, it could >> easily be integrated into the super class. > > Thanks for the suggestion. I've added something similar in > SpringBeanRouter in trunk r4711, but I only added an attachments > property (a la SpringRouter). > > Reasoning: I don't think that setAttachment makes sense as a bean > property, since it is actually adding another attachment instead of > replacing anything. Restlet's main Router class also has the concept > of a default restlet. The semantics in Router are a bit different > than what you have here (its default is the restlet that receives all > requests that don't map to something else, not the top-level resource > -- depending on the routing mode these might be different things), > so > I left it out. You should still be able to map the top-level route > using the attachments property like so: > > <property name="attachments"> > <map> > <entry key=""><value>topLevelResource</value></entry> > </map> > </property> > > I haven't tried this, though, so if it doesn't work please let me > know. (We can come up with a different property name if necessary.) > > Thanks again, > Rhett > > >> import java.util.Map; >> import java.util.Map.Entry; >> >> import org.restlet.Finder; >> import org.restlet.ext.spring.SpringBeanRouter; >> import org.springframework.beans.BeansException; >> import org.springframework.beans.factory.BeanFactory; >> import org.springframework.beans.factory.BeanFactoryAware; >> >> public class SpringRouter extends SpringBeanRouter implements >> BeanFactoryAware { >> private BeanFactory beanFactory; >> >> public void setAttachment(String uriPattern, String beanName) { >> Finder finder = createFinder(beanFactory, beanName); >> attach(uriPattern, finder); >> } >> >> public void setAttachments(Map<String, String> attachments) { >> for (Entry<String, String> attachment : attachments.entrySet()) { >> String uriPattern = attachment.getKey(); >> String beanName = attachment.getValue(); >> setAttachment(uriPattern, beanName); >> >> } >> } >> >> public void setBeanFactory(BeanFactory beanFactory) throws >> BeansException { >> this.beanFactory = beanFactory; >> } >> >> public void setDefaultAttachment(String beanName) { >> String uriPattern = ""; >> setAttachment(uriPattern, beanName); >> } >> } >> >> Paul >> >> >> On Wed, Apr 8, 2009 at 4:12 AM, Jerome Louvel <jerome.lou...@noelios.com >>> wrote: >> Paul, >> >> The problem is that the URI without the trailing slash isn't >> equivalent to the one with it. It's true that in many cases, people >> assume it is equivalent but it doesn't have to. >> >> Also, relative URIs can be expressed in the same way if the ends >> with a slash or not, leading to further routing issues. The only way >> we found to clean that is to force the client to redirect itself to >> the URI with a slash. However, it isn't something we should do >> automatically. >> >> BTW, there is a related RFE: >> >> "Improve matching of directory URIs" >> http://restlet.tigris.org/issues/show_bug.cgi?id=532 >> >> Best regards, >> Jerome Louvel >> -- >> Restlet ~ Founder and Lead developer ~ http://www.restlet.org >> Noelios Technologies ~ Co-founder ~ http://www.noelios.com >> >> >> >> De : Paul Austin [mailto:mail-li...@revolsys.com] >> Envoyé : mardi 7 avril 2009 21:58 >> À : discuss@restlet.tigris.org >> Objet : Re: [1.1.3] Tomcat + RestletFrameworkServlet mapping >> SpringBeanRouter to / >> >> Here is a class which fixes the issue. Probably a better solution >> would be to change the Route class so that if the remainingPart is >> "" it sets it to "/" before doing the regex matching. On a related >> note is it possible to force exact matching so that say /apps would >> be mapped but not /apps/xyz? >> >> public class RootSpringBeanRouter extends SpringBeanRouter { >> @Override >> public void handle(Request request, Response response) { >> Reference resourceRef = request.getResourceRef(); >> if (resourceRef.getRemainingPart().equals("")) { >> resourceRef.addSegment(""); >> } >> super.handle(request, response); >> } >> } >> >> >> On Tue, Apr 7, 2009 at 12:27 PM, Paul Austin <mail- >> li...@revolsys.com> wrote: >> In my project I am deploying an application as a war file. The root >> of the web application /* is mapped to the RestletFrameworkServlet >> so that all handling is performed by Restlet. >> >> <servlet> >> <servlet-name>bpf</servlet-name> >> <servlet- >> class>com.noelios.restlet.ext.spring.RestletFrameworkServlet</ >> servlet-class> >> </servlet> >> >> <servlet-mapping> >> <servlet-name>bpf</servlet-name> >> <url-pattern>/*</url-pattern> >> </servlet-mapping> >> >> The root restlet is a SpringBeanRouter and I have a mapping for / to >> a resource as shown below. >> >> <bean id="root" class="org.restlet.ext.spring.SpringBeanRouter" /> >> >> <bean >> name="/" >> id="rootResource" >> scope="prototype" >> class="myResourceClass" >> /> >> >> The war is deployed to /ws on my server. >> >> If I access /ws I get an Restlet status page error saying "The >> server has not found anything matching the request URI" but if I >> use /ws/ it works correctly. >> >> I tried mapping to "" to see if that would work and it gives the >> same behaviour. >> >> Is it possible to modify the router so that the root resource does >> not need the trailing slash? >> >> Cheers, >> Paul >> >> > > ------------------------------------------------------ > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1604122 Paul Austin President/CEO Revolution Systems Inc. +1 (604) 288-4304 x201 www.revolsys.com ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1604448