I can't remember what 1.1.6's API looks like, but I do something like this with 
the 2.0 API.  Basically, in the Resource's constructor, I use someting like:

getVariants().add(new MyXMLRepresentation(this))
getVariants().add(new MyJSONRepresentation(this))


Each of those My* classes are a subclass of Representation, and the write() 
method is overridden to produce the custom media type.  I pass the Resource 
object to the custom representation so that I have access to the resource 
during the write method.  Also important is that in the constructor, you call 
the super constructor with the MediaType and resource as arguments, ex:

//Constructor
public MyJSONRepresentation(Resource res)
{
  super(MediaType.APPLICATION_JSON, res);
}

I know something like this can be done with the 1.1.6 API because I was using 
it before I ported to 2.0, but now I can't find the 1.1.6 code. It probably 
isn't too different.

On Jan 22, 2010, at 3:50 PM, Jean-Philippe Steinmetz wrote:

> Hello all,
> 
> We're using restlet 1.1.6 and for all our resources we want to support a 
> dynamic set of media types. We do this in our Spring configuration by setting 
> up a list of acceptable media types. My question is if there is a 
> Representation class I can use that will essentially accept any type of data 
> I push into it? For instance we support HTML, XML, JSON and AMF3 therefore 
> most of the time it's a string based representation but in the case of AMF3 
> it is binary (byte array). So far the only way I see it is to make a switch 
> statement in our resource class for each media type but this pretty much 
> defeats the purpose of specifying supported media types in the application 
> configuration.
> 
> Jean-Philippe

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2441312

Reply via email to