Hi,
Firstly, I'd like to write a ServerResource that uses @Get("xml") and
@Get("html") for content negotiation on GET but not on POST (where it
would return a different content-type depending on what the method does,
or do the negotiation internally).
Secondly, I'd like to be able to post some
"application/x-www-form-urlencoded" content and get another type in return.
public class MyResource extends
ServerResource {
@Override
protected void doInit() throws ResourceException {
super.doInit();
setNegotiated(true);
getVariants().add(new Variant(MediaType.TEXT_HTML));
getVariants().add(new Variant(MediaType.APPLICATION_XHTML));
getVariants().add(new Variant(MediaType.APPLICATION_RDF_XML));
}
@Get("html")
public Representation toHtml() throws ResourceException {
...
}
@Get("xml")
public Representation toXml() throws ResourceException {
...
}
@Post
public Representation accept(Representation entity) throws
ResourceException {
...
}
}
At the moment, if I turn off the content-type negotiation
(setNegotiated(false)), then 'accept' is being called up receiving a
POST request. If content-negotiation is on (setNegotiated(true)), I get
a 405 (method not allowed) error.
It looks like this is due to the logic in doNegotiatedHandle(), which
I'd rather not override.
I'm not entirely sure it's because of the content-type negotiation on
the returned type, but it might be due to the input type too. (Hence the
second part of this problem.)
I've tried this @Post("html"), @Post("xml") and @Post("html|xml"), but
they're never called anyway, so it doesn't seem to have much to do with
the negotiated return type (the browser accepts "*/*" by the way).
What's posted is of type "application/x-www-form-urlencoded". It looks
like the @Post annotation make the negotiation on the input type too.
If I tweak client to send the same content as "text/html", the
@Post("html") is called. This seems a bit wrong (posting
x-www-form-urlencoded forms and getting HTML in return seems quite
common, and that doesn't seem feasible if content-type negotiation is on).
Did I miss something? Any workarounds?
Best wishes,
Bruno.
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2460162