I'm building some kind of proxy server with Restlet, however I am having a problem that there's no automatic way to determine the MediaType
based on the client request.
Here's my code:
Representation entity = null;
entity.setMediaType(processMediaType(path));
To process the media type:
private MediaType processMediaType(String path){
MediaType type = MediaType.ALL;
if(path.endsWith("html")){
type = MediaType.TEXT_HTML;
} else if (path.endsWith("css")) {
type = MediaType.TEXT_CSS;
} else if (path.endsWith("js")) {
type = MediaType.TEXT_JAVASCRIPT;
} else if (path.endsWith("txt")) {
type = MediaType.TEXT_PLAIN;
} else if (path.endsWith("jpg")){
type = MediaType.IMAGE_JPEG;
} else if (path.endsWith("png")){
type = MediaType.IMAGE_PNG;
}
return type;
}
I was wondering if the MediaType can be constructed automatically by the framework (or by getting the MediaType from the request, which didn't worked for me) from the request such that I will not need to do these if-else statements which is very much limited in catching various media types.
getPreferredMediaType(null);
? – Internationalist