The following ServerResource fails handling content negotiation with Restlet
2.0.0:
public class FooResource extends ServerResource {
@Get("txt")
public String plain(Variant v) {
System.out.println("### PLAIN: " + v);
return "bar";
}
@Get("xhtml")
public String browse(Variant v) {
System.out.println("### BROWSE: " + v);
return "<html>Browse</html>";
}
@Get("xml")
public String retrieve(Variant v) {
System.out.println("### RETRIEVE: " + v);
return "<foo>bar</foo>";
}
}
Executing requests with curl:
$ curl -v -H 'Accept: text/plain' ...
...
< HTTP/1.1 200 OK
< Content-Type: text/plain; charset=UTF-8
This was the correct response.
$ curl -v -H 'Accept: application/xthml+xml' ...
...
< HTTP/1.1 200 OK
< Content-Type: application/xml; charset=UTF-8
This is not the right response, the retrieve() method is called!
$ curl -v -H 'Accept: text/xml' ...
...
< HTTP/1.1 200 OK
< Content-Type: text/xml; charset=UTF-8
This is the correct response, the retrieve() method is called.
Also, as has been mentioned by other users before, the annotations are not
well designed. The annotations should either accept plain MIME type strings
as in JAX-RS and/or the type-safe constants as defined by MediaType. Adding
another layer of indirection here does not simplify anything, what happens
is that now a developer will have to learn another mapping and that strings
are always a source of typing errors.
--
View this message in context:
http://restlet-discuss.1400322.n2.nabble.com/Content-negotiation-and-annotations-broken-tp5334789p5334789.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2637889