In my ServerResource are two different "Get-Functions"
public class ApiKeyRestlet extends ServerResource {
@Get("json:json")
public ApiKeyResponse apikeyAsJson() throws RecordDoesNotExist {
...
}
@Get("text:text")
public Representation apikeyAsFile() throws RecordDoesNotExist {
...
Representation representation = new StringRepresentation(data, MediaType.TEXT_PLAIN);
Disposition disposition = new Disposition(Disposition.TYPE_ATTACHMENT);
disposition.setFilename("apikey.properties");
representation.setDisposition(disposition);
return representation;
}
...
The path .../apikey is bound to ApiKeyRestlet. If the client sends Accept: text/plain then apikeyAsFile should be called and if the client sends Accept: application/json apikeyAsJson should come into effect. But I can send what I want as Accept-Header its always apikeyAsJson that's called.
I think it has something todo with compatibility between these two formats but how can I handle this? I don't want to define two different routes for this.
[Update]
I debugged through the code and I found that the return type of Representation adds the default MediaType [*/*]
. Scoring is alway 0.5 and so always the first function defined in ServerResource will be called - seems to be a bug??? If I define a Accept-Header the score for this request should go up...