Jersey Producing media type conflict

后端 未结 1 1375
长情又很酷
长情又很酷 2021-02-07 09:35

I\'m trying out Jersey at the moment, followed this link to set up a web service in netbeans. I have my entities classes and my REST classes. It works to add, edit, delete, requ

1条回答
  •  情话喂你
    2021-02-07 10:21

    The problem is, both methods are using path templates that match the same URIs. "{a}/{b}" is equivalent to "{c}/{d}" - in the same way "{username}/{password}" is equivalent to "{from}/{to}". And because both methods also use the same media type, there is an ambiguity. You can fix this by using a regular expression in the path template to make it more specific. I.e. since "{from}/{to}" should always be numbers, you can disambiguate it by changing it like follows: "{from: [0-9]+}/{to: [0-9]+}".

    Anyway, are you sure no user will pick plain numbers from username and password? Looks like in your case it would be much better to use different URI "sub-space" for each of the two resources. E.g.: login/{username}/{password} and ranges/{from}/{to}.

    BUT, few points on the design:

    1. It is a very bad idea to put passwords in the URI. Never ever do it! Look at some existing proven authentication schemes - don't try to reinvent the wheel.
    2. Consider using query params for specifying ranges - e.g. if you have some collection resource (like "myapp.com/calendar/events") you can model ranges using query parameters - e.g. "myapp.com/calendar/events?from=xxx&to=yyy.

    0 讨论(0)
提交回复
热议问题