Hi Thierry, thanks for your quick reply, Thierry Boileau a écrit : > Hello Laurent, > > the router class which is in charge to dispatch a call between the > declared routes relies on a parameter called "routingMode". It can take > on of these values: best, first, last, custom, next and random. > By default, its routing mode is "best". Each declared route is defined a > score, according to the path of the incoming request, and the length of > the recognized characters. > In your case, both "/users/{id}" and "/users/identification-keys" give > the same score because they catch the same number of cracters, thus the > first declared route giving the best score is chosen. > So I'm enclined to say that the declaration order is not neutral using > the default routing mode, and thus it is preferable to declared the > routes without pattern before the ones using patterns (such as /users/{id}). Ok, all clear, it is what I was guessing. > > We may enhance the "best" algorithm by promoting the routes having the > best score but without a pattern. This question is open. > > Regarding the 405 response, I suppose the "UserResource.class " does not > "implement the GET method" ie does not use the @Get annotation nor > implement the ServerResource#get(Variant) method, nor the > ServerResource#get() method . Could you tell us more about this point? I am trying to POST to the resource '/users/identification-keys', and the associated class have method with annotations to handle post : @Post public Representation createIdentificationKey(Representation entity) throws ResourceException {...} But It is true that it does not have any method for GET, with annotations or not.
Regards, Laurent. > > >> Another question, should I attach route using a trailing slash in URI, or >> not, or should I declare two routes ? > I think that attaching "/users" works for both cases (requesting "/users" and > "/users/"), so to my taste, it is useless to declare the "/users/" route. > Some purists can consider that "/users/" expresses that this resource is a > kind of directory, a container of other resources. > > best regards, > Thierry Boileau > >> Hello, >> I have a question about route and router. >> I have the following router >> final Router router = new Router(getContext()); >> router.attach("/users", UsersResource.class); >> router.attach("/users/{id}", UserResource.class); >> router.attach("/users/identification-keys", >> IdentificationKeysResource.class); >> >> return router; >> >> If I go to http://localhost/users/identification-keys I got a 405 error >> in return >> If I declare the last line first, like this >> >> final Router router = new Router(getContext()); >> router.attach("/users/identification-keys", >> IdentificationKeysResource.class); >> router.attach("/users", UsersResource.class); >> router.attach("/users/{id}", UserResource.class); >> return router; >> >> then it works. >> I tried to change behavior of router using >> router.setDefaultMatchingMode(Template.MODE_EQUALS); >> but nothing seems to changed. >> Is it possibly something not correct in my resource class ? >> Right now, it's ok for me to declare in the second way my resource, but >> I think it should work also in the first way, >> as shown by the tutorial >> http://www.restlet.org/documentation/2.0/tutorial#part12 >> >> Another question, should I attach route using a trailing slash in URI, >> or not, or should I declare two routes ? >> router.attach("/users", UsersResource.class); >> router.attach("/users/", UsersResource.class); >> Regards, >> Laurent. >> >> P.S: using restlet 2.0 M4 >> > > ------------------------------------------------------ > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2382106 > > > ------------------------------------------------------------------------------------------------------------------- > CONFIDENTIALITY NOTICE: This e-mail and any files attached may contain > confidential and proprietary information of Alcatel-Lucent and/or its > affiliated entities. Access by the intended recipient only is authorized. Any > liability arising from any party acting, or refraining from acting, on any > information contained in this e-mail is hereby excluded. If you are not the > intended recipient, please notify the sender immediately, destroy the > original transmission and its attachments and do not disclose the contents to > any other person, use it for any purpose, or store or copy the information in > any medium. Copyright in this e-mail and any attachments belongs to > Alcatel-Lucent and/or its affiliated entities. > > -- Laurent Rustuel, Alten contractor for Alcatel-Lucent, Brest ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2382340