Bean serialization between Restlet/GWT and Restlet/Server

6 messages Options
Embed this post
Permalink
jlouvel

Bean serialization between Restlet/GWT and Restlet/Server

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

Hi all,

 

After upgrading our GWT library to 1.6.4 (it works just fine by the way), I was finally been able to make transparent bean serialization work between Restlet/GWT and server-side Restlet!

 

There was a serialization policy issue that was easy to fix but then I hit issues on the client-side to obtain a valid serializer instance. Here is the trick: this serializer is generated by GWT at compilation time using the deferred binding mechanism but only for RPC RemoteService instances and the related object classes.

 

So, it works with one constraint: you need to have a RemoteService defined that uses all the objects you intend to serialize/deserialize RESTfully. I’ve tested both serialization and deserialization and they all work.

 

See my test server:

 

public class TestServer extends ServerResource {

 

    private static volatile Customer myCustomer = Customer.createSample();

 

    public static void main(String[] args) throws Exception {

        new Server(Protocol.HTTP, 8182, TestServer.class).start();

    }

 

    @Get

    public Customer retrieve() {

        return myCustomer;

    }

 

    @Put

    public Customer store(Customer customer) {

        return myCustomer = customer;

    }

 

}

 

The GWT code looks like this:

 

                        […]

                Customer customer = Customer.createSample();

                customer.setFirstName(firstName);

                customer.setLastName(lastName);

 

                ObjectRepresentation<Customer> or = new ObjectRepresentation<Customer>(

                        customer, GreetingService.class);

 

                final Client client = new Client(Protocol.HTTP);

                client.put("http://localhost:8182", or, new Callback() {

 

                    public void onEvent(Request request, Response response) {

                        String entity = response.getEntity().getText();

 

                        ObjectRepresentation<Customer> or = new ObjectRepresentation<Customer>(

                                entity, GreetingService.class);

                        Customer customer = or.getObject();

                        […]

 

See the full project attached.

 

 

Now, this is only the first step, I want to make annotated interfaces work on GWT as well (porting the new ClientResource class) and to remove the constraint of declaring a special RemoteService interface by providing our own serializer.

 

I have started a dedicated specification here:

 

“GWT serialization”

http://wiki.restlet.org/developers/282-restlet.html

 

Feed-back welcome !

 

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~
http://www.noelios.com

 



TestGwt2.zip (1M) Download Attachment
Tim Peierls

Re: Bean serialization between Restlet/GWT and Restlet/Server

Reply Threaded More More options
Print post
Permalink
On Sat, May 16, 2009 at 1:06 PM, Jerome Louvel <[hidden email]> wrote:

There was a serialization policy issue that was easy to fix but then I hit issues on the client-side to obtain a valid serializer instance. Here is the trick: this serializer is generated by GWT at compilation time using the deferred binding mechanism but only for RPC RemoteService instances and the related object classes.

So, it works with one constraint: you need to have a RemoteService defined that uses all the objects you intend to serialize/deserialize RESTfully. I’ve tested both serialization and deserialization and they all work.


But you don't actually have to use the RemoteService, right? It's just there to get the GWT compiler to generate stuff?

Very cool.

--tim
jlouvel

RE: Bean serialization between Restlet/GWT and Restlet/Server

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

Yes Tim, there is no need to actually use the RPC service, nor to run it on the server-side.

 

BTW, I found an issue when compiling the GWT test application, the GWT#create() method requires a class literal. After a bit of refactoring, the code now looks like:

 

                // Prepare our customer

                Customer customer = Customer.createSample();

                customer.setFirstName(firstName);

                customer.setLastName(lastName);

 

                // Wrap it in an object representation

                final GreetingService rs = GWT.create(GreetingService.class);

                ObjectRepresentation<Customer> or = new ObjectRepresentation<Customer>(

                        customer, rs);

 

                final Client client = new Client(Protocol.HTTP);

                client.put("http://localhost:8182/rest/test", or,

                        new Callback() {

 

                            public void onEvent(Request request,

                                    Response response) {

                                String entity = response.getEntity().getText();

 

                                ObjectRepresentation<Customer> or = new ObjectRepresentation<Customer>(

                                        entity, rs);

                                Customer customer = or.getObject();

 

Again, the goal is to make this even more transparent using the ClientResource paradigm and our custom deferred binding. Stay tuned :)

 

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~
http://www.noelios.com

 

 

 

 

De : [hidden email] [mailto:[hidden email]] De la part de Tim Peierls
Envoyé : samedi 16 mai 2009 21:22
À : [hidden email]
Objet : Re: Bean serialization between Restlet/GWT and Restlet/Server

 

On Sat, May 16, 2009 at 1:06 PM, Jerome Louvel <[hidden email]> wrote:

There was a serialization policy issue that was easy to fix but then I hit issues on the client-side to obtain a valid serializer instance. Here is the trick: this serializer is generated by GWT at compilation time using the deferred binding mechanism but only for RPC RemoteService instances and the related object classes.

So, it works with one constraint: you need to have a RemoteService defined that uses all the objects you intend to serialize/deserialize RESTfully. Ive tested both serialization and deserialization and they all work.

 

But you don't actually have to use the RemoteService, right? It's just there to get the GWT compiler to generate stuff?

 

Very cool.

 

--tim

webpost

RE: Bean serialization between Restlet/GWT and Restlet/Server

Reply Threaded More More options
Print post
Permalink
Thanks for the tutorial on how to serialize requests to and from the servlet, but I can't get it to work. The

GreetingService service =  GWT.Create(GreetingService.class) breaks for me. I was wondering if there is a new/better way to do this now?

Thanks,
Jeff

> Yes Tim, there is no need to actually use the RPC service, nor to run it on the server-side.
>
>  
>
> BTW, I found an issue when compiling the GWT test application, the GWT#create() method requires a class literal. After a bit of refactoring, the code now looks like:
>
>  
>
>                 // Prepare our customer
>
>                 Customer customer = Customer.createSample();
>
>                 customer.setFirstName(firstName);
>
>                 customer.setLastName(lastName);
>
>  
>
>                 // Wrap it in an object representation
>
>                 final GreetingService rs = GWT.create(GreetingService.class);
>
>                 ObjectRepresentation<Customer> or = new ObjectRepresentation<Customer>(
>
>                         customer, rs);
>
>  
>
>                 final Client client = new Client(Protocol.HTTP);
>
>                 client.put("http://localhost:8182/rest/test", or,
>
>                         new Callback() {
>
>  
>
>                             public void onEvent(Request request,
>
>                                     Response response) {
>
>                                 String entity = response.getEntity().getText();
>
>  
>
>                                 ObjectRepresentation<Customer> or = new ObjectRepresentation<Customer>(
>
>                                         entity, rs);
>
>                                 Customer customer = or.getObject();
>
>  
>
> Again, the goal is to make this even more transparent using the ClientResource paradigm and our custom deferred binding. Stay tuned :)
>
>  
>
> Best regards,
> Jerome Louvel
> --
> Restlet ~ Founder and Lead developer ~  <http://www.restlet.org/> http://www.restlet.org
> Noelios Technologies ~ Co-founder ~  <http://www.noelios.com/> http://www.noelios.com
>
>  
>
>  
>
>  
>
>  
>
> De : [hidden email] [mailto:[hidden email]] De la part de Tim Peierls
> Envoyé : samedi 16 mai 2009 21:22
> À : [hidden email]
> Objet : Re: Bean serialization between Restlet/GWT and Restlet/Server
>
>  
>
> On Sat, May 16, 2009 at 1:06 PM, Jerome Louvel <[hidden email]> wrote:
>
> There was a serialization policy issue that was easy to fix but then I hit issues on the client-side to obtain a valid serializer instance. Here is the trick: this serializer is generated by GWT at compilation time using the deferred binding mechanism but only for RPC RemoteService instances and the related object classes.
>
> So, it works with one constraint: you need to have a RemoteService defined that uses all the objects you intend to serialize/deserialize RESTfully. Ive tested both serialization and deserialization and they all work.
>
>  
>
> But you don't actually have to use the RemoteService, right? It's just there to get the GWT compiler to generate stuff?
>
>  
>
> Very cool.
>
>  
>
> --tim

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2403422
jlouvel

RE: Bean serialization between Restlet/GWT and Restlet/Server

Reply Threaded More More options
Print post
Permalink
Hi Jeff,

I've added a note to the related RFE to make sure we take a look:

"Transparent serialization to JSE, GWT, GAE and Android"
http://restlet.tigris.org/issues/show_bug.cgi?id=831

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com


-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]]
Envoyé : lundi 5 octobre 2009 05:22
À : [hidden email]; Jerome Louvel
Objet : RE: Bean serialization between Restlet/GWT and Restlet/Server

Thanks for the tutorial on how to serialize requests to and from the servlet, but I can't get it to work. The

GreetingService service =  GWT.Create(GreetingService.class) breaks for me. I was wondering if there is a new/better way to do this now?

Thanks,
Jeff

> Yes Tim, there is no need to actually use the RPC service, nor to run it on the server-side.
>
>  
>
> BTW, I found an issue when compiling the GWT test application, the GWT#create() method requires a class literal. After a bit of refactoring, the code now looks like:
>
>  
>
>                 // Prepare our customer
>
>                 Customer customer = Customer.createSample();
>
>                 customer.setFirstName(firstName);
>
>                 customer.setLastName(lastName);
>
>  
>
>                 // Wrap it in an object representation
>
>                 final GreetingService rs = GWT.create(GreetingService.class);
>
>                 ObjectRepresentation<Customer> or = new ObjectRepresentation<Customer>(
>
>                         customer, rs);
>
>  
>
>                 final Client client = new Client(Protocol.HTTP);
>
>                 client.put("http://localhost:8182/rest/test", or,
>
>                         new Callback() {
>
>  
>
>                             public void onEvent(Request request,
>
>                                     Response response) {
>
>                                 String entity = response.getEntity().getText();
>
>  
>
>                                 ObjectRepresentation<Customer> or = new ObjectRepresentation<Customer>(
>
>                                         entity, rs);
>
>                                 Customer customer = or.getObject();
>
>  
>
> Again, the goal is to make this even more transparent using the ClientResource paradigm and our custom deferred binding. Stay tuned :)
>
>  
>
> Best regards,
> Jerome Louvel
> --
> Restlet ~ Founder and Lead developer ~  <http://www.restlet.org/> http://www.restlet.org
> Noelios Technologies ~ Co-founder ~  <http://www.noelios.com/> http://www.noelios.com
>
>  
>
>  
>
>  
>
>  
>
> De : [hidden email] [mailto:[hidden email]] De la part de Tim Peierls
> Envoyé : samedi 16 mai 2009 21:22
> À : [hidden email]
> Objet : Re: Bean serialization between Restlet/GWT and Restlet/Server
>
>  
>
> On Sat, May 16, 2009 at 1:06 PM, Jerome Louvel <[hidden email]> wrote:
>
> There was a serialization policy issue that was easy to fix but then I hit issues on the client-side to obtain a valid serializer instance. Here is the trick: this serializer is generated by GWT at compilation time using the deferred binding mechanism but only for RPC RemoteService instances and the related object classes.
>
> So, it works with one constraint: you need to have a RemoteService defined that uses all the objects you intend to serialize/deserialize RESTfully. Ive tested both serialization and deserialization and they all work.
>
>  
>
> But you don't actually have to use the RemoteService, right? It's just there to get the GWT compiler to generate stuff?
>
>  
>
> Very cool.
>
>  
>
> --tim

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

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2413836
webpost

RE: Bean serialization between Restlet/GWT and Restlet/Server

Reply Threaded More More options
Print post
Permalink
Hi Jerome,
You can find attached your code compiled for Restlets 2.0 M5 with Eclipse galileo and GWT2.0m2.
The code is dispatched into three eclipse project in ordezr to be able to compile the application.
regards
Xavier
ps : could be put on the wiki in the gwt section

exampleGWTObjectSerialization.zip (2M) Download Attachment