Search code examples
gwtrestlet

Problem to use GWT client to call a Restlet web service


I am using Restlet framework, and I want to use GWT as the client side. I have already created some ServerResources in Restlet. Here is the codes for the GWT client:

BookResourceProxy.java

public interface BookResourceProxy extends ClientProxy { @Get public void getBooks(Result callback); }

The class that use this Proxy:

BookResourceProxy wrp = GWT.create(BookResourceProxy.class);

wrp.getClientResource().setReference("/Books");

wrp.getClientResource().getClientInfo().getAcceptedMediaTypes().add(new
Preference<MediaType>(MediaType.APPLICATION_JSON));


wrp.getBooks(new Result<String>() 
    {
  public void onFailure(Throwable caught) 
  {
    Window.alert("Fail" + caught.getMessage());
  }

  public void onSuccess(String json) 
  {
    Window.alert(json);
  }
});

When I run the application, I always receive the error:

"No source code is available for type org.restlet.resource.ClientProxy; did you forget to inherit a required module?"

But if I inherit it in the .gwt.xml:

Another error occurs:

Unable to find 'org/restlet/Restlet.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source? [ERROR] Line 13: Unexpected exception while processing element 'inherits'

Does anybody know why?

Thanks in advance!

Ike


Solution

  • Make sure you are using the GWT edition of Restlet and that org.restlet.jar is in the GWT compiler's classpath.