Jerome,

Here is an implementation which extends SpringBeanRouter, it could easily be
integrated into the super class.

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=1597991

Reply via email to