Recieve custom Representations

2 messages Options
Embed this post
Permalink
webpost

Recieve custom Representations

Reply Threaded More More options
Print post
Permalink
Hi everyone,

I have an app that use Restlet 2m2. To have a better live, I have wriited my own "DomListRepresentation" that extends "DomRepresentation" and use reflexion to respond an XML list.
I have alos writed a "JAXBRepresentation" that use JAXB to marsahll an object and respond the resulting XML. And now I'm an happy developper who like Restlet.

But some of my services receive XML (result of JAXB marshalling on the client side). And in each of these services I will do the JAXB unmarshalling from the received representation :
"context.createUnmarshaller().unmarshal(representation.getStream());"

But I wonder if it is a way to receive a custom Representation ?
I will be a more happy developper if I can receive a custom "JAXBRepresentation" insted of an "InputRepresentation".
Is it a way to use custom representations in POST methods ?

Maybe something like that :
# public class MyResource extends ServerResource {
#   protected void int() {
#     getRepresentations().put(Method.POST, new MyJAXBRepresentation(My.class));
#   }
#
#   protected Representation post(Representation rep, Varinat v) {
#     My obj = ((MyJAXBRepresentation) rep).getObject()
#   }
# }

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

Re: Recieve custom Representations

Reply Threaded More More options
Print post
Permalink
Hello,

either you add a constructor to the MyJAXBRepresentation with a
Representation as a parameter that allows to read/parse the given
representation or you can have a look here
(http://wiki.restlet.org/docs_2.0/285-restlet.html). This solution is
based on annotated ServerResources and ConverterHelper (in this case the
one provided by the xtream extension).

best regards,
Thierry Boileau

> Hi everyone,
>
> I have an app that use Restlet 2m2. To have a better live, I have wriited my own "DomListRepresentation" that extends "DomRepresentation" and use reflexion to respond an XML list.
> I have alos writed a "JAXBRepresentation" that use JAXB to marsahll an object and respond the resulting XML. And now I'm an happy developper who like Restlet.
>
> But some of my services receive XML (result of JAXB marshalling on the client side). And in each of these services I will do the JAXB unmarshalling from the received representation :
> "context.createUnmarshaller().unmarshal(representation.getStream());"
>
> But I wonder if it is a way to receive a custom Representation ?
> I will be a more happy developper if I can receive a custom "JAXBRepresentation" insted of an "InputRepresentation".
> Is it a way to use custom representations in POST methods ?
>
> Maybe something like that :
> # public class MyResource extends ServerResource {
> #   protected void int() {
> #     getRepresentations().put(Method.POST, new MyJAXBRepresentation(My.class));
> #   }
> #
> #   protected Representation post(Representation rep, Variant v) {
> #     My obj = ((MyJAXBRepresentation) rep).getObject()
> #   }
> # }
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2415088
>
>

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