0

I'm trying to use Errai rest capabilities in my GWT app,
I took a look at the following guide:
http://errai-blog.blogspot.it/2011/10/jax-rs-in-gwt-with-errai.html

In particular, it says:

We simply put this interface somewhere in our client packages (e.g. client.shared) where the GWT compiler can find it. To create a request all that needs to be done is to invoke RestClient.create()

I think there's a plot hole here, how is Errai able to know how serialize/deserialize model classes ?

Can you help understanfing this ?

thanks

GionJh
  • 2,742
  • 2
  • 29
  • 68

1 Answers1

1

According to RestClient Class's create() method

 public static <T, R> T create(final Class<T> remoteService, final RemoteCallback<R> callback, Integer... successCodes) {
   return create(remoteService, null, callback, null, successCodes);
}

In example which you've provided; when using create() method Errai gets the CustomerService Class as remoteService, After many operations;

Errai parses and implements this CustomerService Interface with using their errai-codegen library which uses Java Reflection API.

When parsing simply;

  • First it looks for JAX-RS annotated methods and defines them as JaxrsResourceMethod

  • Then it looks into parameters of that method if there is any parameter that annontated with JAX-RS annotations.

  • If it finds annontated parameters in JaxrsResourceMethod, it keeps that parameter with it's annotation type

  • If it finds not annontated parameter in JaxrsResourceMethod it defines as a entityParameter

  • Errai holds these annotated parameter and entityParameters in JaxrsResourceMethodParameters by their method. When building request it uses parameters by their rule.

Let me explain these rules with using an example you've provided.

Customer customer = new Customer("new name", "new last name", "new postal code");
RestClient.create(CustomerService.class, callback).updateCustomer(240193, customer);

Errai will create url like

example.com/cusomers/240193

Because @PathParam("id") annotation rule is adding parameter to the url and according to Errai's entityParameter rule customer will be marshalled when sending data with PUT.

@PUT 
@Path("/{id}") 
@Consumes("application/json")
@Produces("application/json") 
public Customer updateCustomer(@PathParam("id") long id, Customer customer); //- See more at: http://errai-blog.blogspot.com.tr/2011/10/jax-rs-in-gwt-with-errai.html#sthash.2GTQtIg8.dpuf

One more additional note if you check here there is an exception in setEntityParameter method;

Only one non-annotated entity parameter allowed per method:

This means you cant define methods with more than 1 non-annotated parameter in Class which you sent in Errai.

Ömer Erden
  • 7,680
  • 5
  • 36
  • 45