jeudi 2 avril 2015

UriTemplate matching with optional trailing slash

I'm using the Spring Web UriTemplate class for some URL matching. The following trivial example fails because of the mismatched slash at the end of the URL:



String uriString = "/services/myservice/v1/stuff/"; // With slash
String uriTemplateString = "/services/myservice/{version}/stuff"; // Without slash

UriTemplate uriTemplate = new UriTemplate(uriTemplateString);
assertTrue(uriTemplate.matches(uriString));


I'm aware that the two cases (with slash and without) resolve to two separate REST resources. However, in common use, these URLs are generally considered equivalent. Is there a way to configure the UriTemplate to match both cases of input URL?


I'm using Spring Web 4.0.8.RELEASE.


Aucun commentaire:

Enregistrer un commentaire