jump to navigation

Restlet ported to GWT ! July 25, 2008

Posted by Jerome Louvel in GWT, Restlet General, User interface.
trackback

Google Web Toolkit is a very successful technology that brings Java right inside Web browsers. It could be compared to traditional Applets but without requiring any extra plugin and with a more natural integration with the browser artifacts.

How is it possible? Well, they built a smart Java compiler that produces highly optimized JavaScript ‘bytecode’. What is great is that you can leverage your Java experience and the strong typing of the language. What is even better is that in GWT version 1.5, they added support for the generic types, the famous feature introduced in Java SE 5.

Now, how can you leverage REST in GWT? By default, they propose an opaque GWT-RPC mechanism that is closer to SOAP than to REST. It gives a feeling of transparent distribution but actually introduces tight coupling between client and server code and prevents you from leveraging existing RESTful back-ends. There is an HTTP request builder class that you can use, but it requires knowledge of lower HTTP levels like the exact headers syntax.

Wouldn’t it be nice to use the Restlet API instead, which provides a higher level mapping of HTTP semantics to a clean Java API ? Thanks to the support for generics added in GWT 1.5, we were able to achieve this port with reduced efforts and limited troubles. We had to get rid of the server-side features that don’t make sense in a browser, and of the APIs like NIO and logging that aren’t emulated by GWT. The major impact was the adaptation of the API to the asynchronous communication imposed by AJAX and GWT.

Restlet

The port, named “Restlet edition for GWT”, is available since Restlet 1.1 and its usage is documented in our Wiki. There is a discussion comparing the GWT-RPC and Restlet edition for GWT architectures and much more! The testing, most of the documentation as well as the back-end integration (see the server-side GWT extension) was contributed by Rob Heittman. I would like to thank him as well for the numerous design discussions while working on this port.

Rob Heittman is Chief Technology Officer at Solertium.  Using prototypes of the Restlet edition for GWT, Solertium has been building large enterprise applications with Restlet and GWT for the past year, for worldwide customers like IUCN and Conservation International.  “I love GWT, but I prefer RESTful web services to RPC,” says Rob.  “GWT backed by Restlet has been great for us. Now, GWT 1.5 and the new Restlet edition for GWT will make our client-side code as simple and elegant as our server code.”

Finally, if you want to follow the latest news about GWT, I recommend the onGWT blog. It is maintained by Didier Girard, a good friend who introduced me to the joys of GWT!

Updates:

Comments»

1. Pathfinder Development » Restlet Ported to GWT - August 1, 2008

[...] the folks at the Restlet project have ported the Restlet API to GWT. Thanks to the support for generics in GWT 1.5 RC1, we were able to achieve this port with reduced [...]

2. Weekly GWT Links For 8/2/08 | GWT Site - August 2, 2008

[...] Restlet ported to GWT! With the introduction of generics in GWT 1.5 RC1, the Restlet API has now been ported over to GWT. [...]

3. qnaguru - August 4, 2008

Wish they had focussed on Flex instead for desktop!

4. Jerome Louvel - August 4, 2008

For better REST support in Flex, you can check out this library:
http://lab.arc90.com/2008/03/restservice.php

The port for GWT was just easier for us because it is mostly the same Java syntax. A port to Flex would be valuable as well we would require much more time to develop and maintain.

5. Eduard Escrihuela - August 5, 2008

Please,
can you show examples ?

It is impossible for me to do anything without examples!

Thanks

6. Jerome Louvel - August 5, 2008

Eduard, we don’t have more documentation than our wiki page for now:
http://wiki.restlet.org/docs_1.1/g1/13-restlet/28-restlet/144-restlet.html

In term of Restlet API usage, you could check the general tutorial to see how to make Restlet HTTP requests:
http://www.restlet.org/documentation/1.1/tutorial#part02

We’ll try to improve the documentation for the final Restlet 1.1 release.

7. Eduard Escrihuela - August 6, 2008

Thanks Jerome,
I am hoping anxiously your documentation!

Thanks

8. Restlet 1.1 M5 released « Noelios Technologies - August 7, 2008

[...] a Restlet-GWT module which is a port of the Restlet API to the Google Web Toolkit 1.5 RC2 AJAX [...]

9. Nitin Gupta - August 8, 2008

Hi,
I just tried the GWT-Restlet API with the GWT 1.5 RC1. It worked wonderfully in the hosted mode. I then attempted web mode. However, When I compiled the code using the default GWT project compiler, i got the errors. Error snippet:
[ERROR] : Class.createForEnum(“org.restlet.gwt.data.”,”Dimension”>

Am I missing on something. Please help me as I am in the middle of a migration project and need the REST client for GWT badly.

10. Jerome Louvel - August 8, 2008

Hi Nitin,

We have also noticed this issue and fixed it in the latest Restlet 1.1 M5 release which is compatible with GWT 1.5 RC2 (it might work with 1.5 RC1 as well, but we didn’t test it).

Best regards,
Jerome

11. Nitin Gupta - August 8, 2008

Hi Jerome,

Thanks for replying back. I tried with RC-2 the Restlet code which I downloaded from the link on your website. I am still getting error, though now it is different. Here is a brief snippet. I just want to check with you that I am not missing anything.
[ERROR] at Client.java(45): final class Client extends Connector

Can I ask you about the tentative release date of Restlet v 1.1?

Best Regards,
Nitin Gupta

12. Jerome Louvel - August 8, 2008

Hi Nitin,

Thanks for testing the latest release. I’ve entered a bug report for the new issue that you encounter:
http://restlet.tigris.org/issues/show_bug.cgi?id=545

Would you mind attaching a sample source code that reproduces the issue or adding it in a comment to the issue?

Regarding Restlet 1.1 release, the roadmap is here:
http://www.restlet.org/about/roadmap

Thanks,
Jerome

13. Nitin Gupta - August 8, 2008

Hi Jerome,

Here is the basic code which I wrote and called it on click of a button;

CallbackExtension callback = new CallbackExtension();
Client client = new Client(Protocol.HTTP);
Reference ref = new Reference(Protocol.HTTP, “localhost”, 8080);
ref.addSegment(“PATS/atom”);
client.get(ref, callback);

CallbackExtension is a simple extension to the CallBack class.

It works fine in the hosted mode, however compiler complains when attempt is made for the hosted mode.

Let me know if you would like me to post the error message as well.
Best Regards,
Nitin Gupta

14. Jerome Louvel - August 9, 2008

Hi Nitin,

Thanks for the report. It was due to some volatile modifiers rejected by the GWT compiler. There were all removed from source code. This has been fixed in SVN trunk. You’ll be able to test again from the next 1.1 snapshot.

Best,
Jerome

15. Gabor Dolla - August 11, 2008

Hi
I can also see this problem with GWT compile when I tried GWT and restlet. My other question is: in restlet examples (http://www.restlet.org/documentation/1.0/tutorial) HTTP authentication is handled with
ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
ChallengeResponse authentication = new ChallengeResponse(scheme,
“scott”, “tiger”);
request.setChallengeResponse(authentication);

Is it not available with restlet-gwt ??

thanks
Gabor

16. Jerome Louvel - August 11, 2008

Hi Gabor,

Right this isn’t available yet, mainly due to the apparent lack of a base64 implementation in GWT.

The is definitely an enhancement that we’d like to add in the future, see note at the end of:
http://restlet.tigris.org/issues/show_bug.cgi?id=127

We have already found a public domain base64 implementation that we could leverage to support HTTP Basic authentication more quickly.

Best regards,
Jerome

17. Nitin - August 16, 2008

Hi Jerome,

Thanks for the update. I shall check an do some more testing.

If there can be a quick work around for the Basic HTTP authentication, then please let me know.

Warm Regards,
Nitin

18. radioAe6rt » GWT-Restlet snippet - September 10, 2008

[...] You’d use this in conjunction with a server process that can handle RESTful requests. A bit more detail can be found here. [...]

19. Jerome Louvel - September 19, 2008

Hi Nitin,

I have just added support for preemptive authentication to our Restlet-GWT module. It will make it into the next Restlet 1.1 release.

Here is how you should use it:

final Client client = new Client(Protocol.HTTP);
Request request = new Request(Method.GET,
“http://localhost:8888/ping”);
request.setChallengeResponse(new ChallengeResponse(
ChallengeScheme.HTTP_BASIC, “scott”, “tiger”
.toCharArray()));

client.handle(request, new Callback() {
@Override
public void onEvent(Request request, Response response) {
button.setText(response.getEntity().getText());
}
});

Best regards,
Jerome

20. Le blog de Fabien DUMINY » Paris JUG – conférence sur GWT - November 16, 2008

[...] : c’est une implémentation open source de REST en java. La version 1.1.0, appelée Restlet-GWT, est la première version stable du portage vers [...]

21. Cartoon presents Restlet « Noelios Technologies - November 25, 2008

[...] Restlet General. trackback On the 4th of November, I presented a session on REST, Restlet and our port to GWT at the local JUG (Paris Java User Group). More than 200 juggers attended, with a first part on GWT [...]

22. jmusgrove - December 2, 2008

Newbie here… When I try to download the Restlet GWT — Simple Example it doesn’t download correctly, anythoughts? or references to other good examples?

Thanks!

http://wiki.restlet.org/docs_1.1/162-restlet/version/default/part/AttachmentData/data/RestletGWTSimpleExample.zip

23. Jerome Louvel - December 2, 2008

Hi,

We have had stability issues with our wiki recently. We have just restarted it and the link works again.

Best regards,
Jerome

24. Scott - December 21, 2008

It seems the link (http://wiki.restlet.org/docs_1.1/162-restlet/version/default/part/AttachmentData/data/RestletGWTSimpleExample.zip) is broken again. It allows about 42k of the file to download and then closes the connection.

Thanks,
Scott

25. Jerome Louvel - December 26, 2008

Hi Scott,

We still have a stability issue with the wiki server. We are planning to upgrade it in the near future.

Anyway, we have restarted it again. The link should work again.

Best regards,
Jerome

26. The LinkedIn Blog » Blog Archive OSCON 2008 and Web Frameworks of the Future « - February 10, 2009

[...] folks that share this same sentiment and quite a few solutions are being developed (for example, Restlet-GWT). While Flex allows for cross-domain communication, I was disappointed to find it doesn’t [...]

27. Restlet in the cloud with Google App Engine ! « Noelios Technologies - April 11, 2009

[...] addition, support for GWT is available in both GAE and Restlet (see this post on our port of Restlet on GWT). The usage instructions are available in our online User [...]

28. Thomas - April 14, 2009

Hi all,
Is a gwt 1.6 support is planned ?
Thanks
Thomas

29. Jerome Louvel - April 14, 2009

Hi Thomas,

Yes, we will update our Restlet/GWT edition for GWT 1.6 before releasing Restlet 1.2 RC1 based on our main code branch at that time.

Best regards,
Jerome

30. Rogério Liesenfeld - April 30, 2009

You claim that in GWT “the back-end has to be built using a Servlet container in order to work properly and to invoke your custom classes and methods”… but in reality it would only be a matter of porting the GWT server side classes in order to make it work with another platform, such as C#/ASP.NET. Although the official GWT documentation only talks about a Java back-end, there really should be no major technical difficulties involved in supporting other platforms (I have achieved some tricky things with GWT RPC on the server side, such as getting GWT 1.3 and 1.5 to work at the same time, and having a unique central servlet for any number of RemoteService interfaces, so I should know if there were any – unless I am missing something).

31. Jerome Louvel - April 30, 2009

Hi Rogério,

I agree that the server-side could be re-implemented in other languages. There is an example of that for PHP:
http://code.google.com/p/gwtphp/

It seems to me that reimplementing the GWT-RPC object encoding protocol isn’t trivial at all, especially if you consider having it work both ways. You have to take care of serialization policies for example which isn’t trivial.

Anyway, REST provides a much reusable back-end, not tighted to GWT or any specific language.

BTW, we are working in Restlet 1.2 on the support of the GWT-RPC encoding for our resource representations, as an alternative to more interoperable format like pure JSON or XML.

The idea is to leverage HTTP content negotiation to provide the best of both worlds with the exact same server code, returning serializable Java beans as representations.

Best regards,
Jerome

32. Restlet available on Android phones « Noelios Technologies - May 6, 2009

[...] framework, is already available on regular computers based on Java SE/EE, in Web browers with our GWT edition and even in the cloud with a new Google AppEngine edition. But, we are still missing the Mobile [...]

33. Restlet 2.0 M3 released « Noelios Technologies - May 27, 2009

[...] API), on extension packages and with the growing number of special Restlet editions (Java SE/EE, Google Web Toolkit, Google App Engine and Android), it seemed appropriate to rename the Restlet 1.2 branch into [...]

34. Wish - May 28, 2009

I am using gwt-restlet to access a JAX-RS hosted webservice on the localhost. In hosted mode for GWT, I get this on error console with eclipse:
Starting the HTTP client
Error while handling an HTTP client call

I am using Eclipse 3.4 and GWT 1.6. Downloaded the restlet 2.0m3 zip to get access to gwt-restlet. I have an http monitor running on the glassfish server, I does not even get the request from the GWT application. Here is the client access code:

[...]

If I use curl to access the webservice it works fine:
curl -v -H “Accept: application/json” http://localhost/entApp-war/resources/Items/id/70
I see request with the http event monitor in glassfish.

Any help is appreciated..

-Wish

Jerome Louvel - June 1, 2009

Hi Wish,

Do you mind posting again in our mailing list instead?
http://www.restlet.org/community/lists

Cheers,
Jerome

35. Restlet 2.0 M4 released « Noelios Technologies - August 6, 2009

[...] separate distributions for each edition that we support: Java SE, Java EE (with Servlet support), Google Web Toolkit, Google App Engine and Android. In addition, the porting of the main source code base to each [...]

36. Restlet, a RESTful middleware for GWT, GAE and Android « Noelios Technologies - December 17, 2009

[...] Google Web Toolkit (GWT) for AJAX applications deployed in desktop browsers, without any plugin required [...]

37. Fast Web UI design by Google Web Toolkit « When IE meets SE… - January 24, 2010

[...] 1. Restlet ported to GWT ! [...]

38. GWT-Restlet snippet « radioAe6rt - January 22, 2011

[...] You’d use this in conjunction with a server process that can handle RESTful requests. A bit more detail can be found here. [...]

39. vasu - June 12, 2012

r.get() getting null how to solve this problem

my code is
ClientResource r = new ClientResource(“http://192.168.1.13:8888/auth/ramu/ram@123″);

r.setOnResponse(new Uniform() {

@Override

public void handle(Request request, Response response) {

// TODO Auto-generated method stub
try {

System.out.print(response.getEntity().getText());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});

System.out.println(“testtt”+r.get());


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 62 other followers

%d bloggers like this: