Hi Dustin,

Yes, it is intentional in the sense that the HTTP server connector
converts the request entity into an InputRepresentation and does not
infer the "right" representation (but who decides which is the right
representation?) according to the media-type of the entity.
However, it should be easy to create a new ObjectRepresentation (or
DOMRepresentation, SAXRepresentation for XML-based representations,
etc) since there is a constructor which accepts a Representation
instance.
You can also develop your own filter that will map media-types and
correct representation.

I hope this will help you.
best regards,
Thierry Boileau

On Sat, Mar 15, 2008 at 12:07 AM, Dustin N. Jenkins
<[EMAIL PROTECTED]> wrote:
> Excellent thank you both for your replies.  I missed the rule that every
>  Representation is a Resource to be honest, and that's good to know now.
>
>  Here is my code:
>
>  Client client = new Client(Protocol.HTTP);
>  Request request = new Request(Method.GET,
>  "http://www.mysite.com/users?media=application/x-java-serialized-object";);
>  request.setChallengeResponse(....);
>
>  Response response = client.handle(request);
>  Representation representation = response.getEntity();
>
>  Why is representation always an InputRepresentation and not the one that
>  was asked for?  The correct ObjectRepresentation is now being returned
>  from my Resource (thanks!), but the Response in this case never returns
>  the right one.  Is this intentional?
>
>  Thanks!
>  Dustin
>
>
>
>
>  Thierry Boileau wrote:
>  > Hello,
>  >
>  > Just a few words to complete Jonathan's responce.
>  >
>  > The next question is "how can I request this specific representation?".
>  >
>  > Let's say that you define the URI of your User resource like this =>
>  > http://my.company.org/users/<id>.
>  > On the client side, if you have a full control of the HTTP request,
>  > you can set the requested URI with http://my.company.org/users/<id>
>  > and set the ACCEPT header with the right media-type.
>  > If not, for example with your favorite browser, there is one solution
>  > based on the Tunnel service [1]. If the Tunnel service is running on
>  > server side (e.g. in an Aplication), you can rely on the
>  > "mediaTypeParameter".
>  > It just says that if your browser requests for
>  > 
> "http://my.company.org/users/<id>?media=application/x-java-serialized-object"
>  > then the Tunnel Filter updates the request on fly by replacing the
>  > media-types preferences sent by the browser with the single preference
>  > "application/x-java-serialized-object". Then the Resource will return
>  > the right representation.
>  >
>  > This solution has another effect : it complies with the rule saying
>  > that every Representation is a Resource, and thus is identified by its
>  > own URI(s).
>  >
>  > best regards,
>  > Thierry Boileau
>  > [1] 
> http://www.restlet.org/documentation/1.0/api/org/restlet/service/TunnelService.html
>  >
>  >
>  > On Fri, Mar 14, 2008 at 10:43 PM, Jonathan Hall <[EMAIL PROTECTED]> wrote:
>  >
>  >> Hi Justin,
>  >>
>  >>  If I understand you, you want to return html,text and an object for a
>  >>  resource?
>  >>  Simplest form
>  >>
>  >>  public class MyResource extends Resource {
>  >>     public MyResource(Context context, Request request, Response 
> response) {
>  >>         super(context, request, response);
>  >>         getVariants().add(new Variant(MediaType.APPLICATION_JAVA_OBJECT));
>  >>         getVariants().add(new Variant(MediaType.TEXT_PLAIN));
>  >>         getVariants().add(new Variant(MediaType.TEXT_HTML));
>  >>
>  >>     }
>  >>
>  >>     @Override
>  >>     public Representation getRepresentation(Variant variant) {
>  >>         Representation rep = null;
>  >>         if (MediaType.TEXT_PLAIN.equals(variant.getMediaType())) {
>  >>                 rep = StringRep...
>  >>         }
>  >>         else if (MediaType.TEXT_HTML.equals(variant.getMediaType())) {
>  >>                 rep = Freemarker...
>  >>         }
>  >>         else if 
> (MediaType.APPLICATION_JAVA_OBJECT.equals(variant.getMediaType())) {
>  >>                 rep = ObjectRepresenation( YOUR_SERIALIZED_OBJECT );
>  >>         }
>  >>
>  >>       return rep;
>  >>     }
>  >>  }
>  >>
>  >>  Your client sending:
>  >>  Accept: application/x-java-serialized-object
>  >>
>  >>  works fine on 1.1 snapshot, sorry I dont have a test setup for 1.0.8.
>  >>
>  >>
>  >>  jon
>  >>
>  >>
>  >>
>  >>  Dustin N. Jenkins wrote:
>  >>  > Hi all,
>  >>  >
>  >>  > This could be a REST understanding problem in general.  I'm using JDK
>  >>  > 1.5.10 with Restlet 1.0.8.
>  >>  >
>  >>  > I have a resource that accepts GET requests for a User.  The HTML
>  >>  > representation will return a FreeMarker page, and the Text version
>  >>  > will just return a String representation of the User.  Simple and 
> lovely.
>  >>  >
>  >>  > I also want to be able to ask for the User object too, and I think
>  >>  > that the ObjectRepresentation class is used for that.  How do I
>  >>  > specify that from the Resource though?  I thought of narrowing down
>  >>  > the ClientInfo's accepted MediaTypes to just
>  >>  > 'x-java-serialized-object' and checking for that in the
>  >>  > getRepresentation() method of the Resource, but it won't accept
>  >>  > requests with just that MediaType to choose from.
>  >>  >
>  >>  > Any ideas of how to just return the Object?  It seems like just
>  >>  > another representation, but I don't think I should have to create
>  >>  > another Resource as it's essentially doing the same thing as the HTML
>  >>  > and Textual representations are doing.
>  >>  >
>  >>  > Thanks,
>  >>  > Dustin
>  >>  >
>  >>  >
>  >>  >
>  >>
>  >>
>  >>
>
>
>
> --
>
>
>  Dustin N. Jenkins | Tel/Tél: 250.363.3101 | [EMAIL PROTECTED]
>
>  facsimile/télécopieur: (250) 363-0045
>
>  National Research Council Canada | 5071 West Saanich Rd, Victoria BC.
>  V9E 2E7
>
>  Conseil national de recherches Canada | 5071, ch. West Saanich, Victoria
>  (C.-B) V9E 2E7
>
>  Government of Canada | Gouvernement du Canada
>
>

Reply via email to