Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

GWT and REST

I've posted two message to the GWT Google Group in the last couple of days. However, new member messages are moderated and neither has shown up yet. I'm reposting my questions here in hopes of getting some answers.

Is there a way to easily use a REST backend with GWT? I tried GWT-REST. It works, but it seems to be centered towards Rails (I'm using Grails) and it suffers from the SOP issue.

JSONRequest looks promising for cross-domain support, but I can't get it to work either. The provided examples work, but not my simple hello world that returns:

{"response":"Hello World!"}

Also, the example implementation only has GET support, not PUT, DELETE or POST. I can post my REST backend on the public internet if anyone is interested in seeing the issues I'm having.

Thanks in advance for any advice.

Posted in Java at Jul 21 2008, 10:31:58 AM MDT 14 Comments
Comments:

The code you posted looks like it's for JSONP. You probably want XmlHttpRequest, so check out RequestBuilder.

Posted by Bob Lee on July 21, 2008 at 10:55 AM MDT #

I'm always amazed how things claim to be RESTful, but implement only GET and POST. The "rails way" to me is not restful at all, but RPC based. Which is fine; it just makes it confusing when people use terminology incorrectly.

Posted by Dave Copeland on July 21, 2008 at 10:58 AM MDT #

Hi there,

you could try out our (still sandboxed) "thin" REST client for GWT from here: http://svn.sonatype.org/nexus/trunk/sandbox/nexus-gwt-ui/sonatype-gwt-rest/

It is already used in the "next gen" GXT based UI for Nexus. The feature list is not huge, but it works for REST services based on JSON or XML. I started with GWT-REST too, but it's focus on Rails prevented me to implement proper requests against restlet.org powered Nexus (ie. not supporting every HTTP method).

Posted by Tamas Cservenak on July 21, 2008 at 11:00 AM MDT #

> The code you posted looks like it's for JSONP. You probably want XmlHttpRequest, so check out RequestBuilder.

I'm using Grails' JSON Builder to produce this JSON, but it's certainly possible it sucks.

As far as RequestBuilder, its javadoc indicates it only supports GET and POST. Also, I believe it suffers from the SOP issue as well, doesn't it?

Posted by Matt Raible on July 21, 2008 at 11:10 AM MDT #

Assuming you mean SPO (single point of origin), you didn't specify that you wanted cross-site requests. If that's the case, you want JSONP, and due to the way to works, GET is your only option. As for RequestBuilder, like you said, it only works with a single point of origin because it uses XmlHttpRequest underneath and that's all it supports. It only supports GET and POST because that's all Safari supports.

Posted by Bob Lee on July 21, 2008 at 11:24 AM MDT #

Oh, and your simple hello world example doesn't work because it's missing the callback.

Posted by Bob Lee on July 21, 2008 at 11:29 AM MDT #

Hi Matt, FYI, we are currently working on a port of the Restlet API (client-side only) to GWT. http://www.restlet.org We want to ensure that all methods work, using a POST tunnel if necessary (already supported by Restlet servers or by Rails). Stay tuned! Best regards, Jerome

Posted by Jerome Louvel on July 23, 2008 at 04:34 AM MDT #

@Tamas: I checked out sonatype-gwt-rest and when I ran "mvn package", I got the following error:

Cannot find parent: org.sonatype.nexus.gwt:nexus-gwt-ui for project: null:sonatype-gwt-rest:jar:null for project null:sonatype-gwt-rest:jar:null

Do I need to checkout the source for Nexus and mvn install it to get sontatype-gwt-rest to compile?

Also, it looks like SOA Faces might be something similar. Have you looked at it? It sounds like a JSF library, but it appears to be geared towards GWT.

Posted by Matt Raible on July 23, 2008 at 06:18 AM MDT #

@Matt: yes, the parent POM is not deployed anywhere, so you need to checkout and run "mvn install" from top level. Also, you will need to add Google repo to your settings: http://gwt-maven.googlecode.com/svn/trunk/mavenrepo/ Thanks for the tip about SOAFaces, will look at it...

Posted by Tamas Cservenak on July 23, 2008 at 06:26 AM MDT #

Matt, we have just released our Restlet-GWT module: http://blog.noelios.com/2008/07/25/restlet-ported-to-gwt/ It supports all HTTP methods. For the SOP issue, you can easily leverage the org.restlet.Redirector classes that will act like a light HTTP reverse proxy on the server-side. See the wiki page for more details: http://wiki.restlet.org/docs_1.1/g1/43-restlet/144-restlet.html Let me know if this works for you...

Posted by Jerome Louvel on July 25, 2008 at 06:33 AM MDT #

Sorry, here are the clickable links:
Restlet-GWT module announce
Usage documentation

Posted by Jerome Louvel on July 25, 2008 at 06:35 AM MDT #

Just curious if anyone was able to put together an example of Restlet + GWT + cross domain which gets around SOP. Thanks, jmus

Posted by jmus on December 14, 2008 at 04:43 PM MST #

Hi jmus,

It is easily feasible using a Restlet Redirector on the server-side (like a reverse proxy) as illustrated in figure 4 of this page:

http://wiki.restlet.org/docs_1.1/13-restlet/144-restlet/185-restlet.html

But maybe you are looking at removing the SOP on the browser itself? I'm not sure it is feasible in a cross-browser compatible way...

http://en.wikipedia.org/wiki/Same_origin_policy

Best regards,
Jerome

Posted by Jerome Louvel on December 18, 2008 at 05:04 PM MST #

RestyGWT properly supports all the restful verbs including GET, PUT, DELETE and POST. It will even set the "X-HTTP-Method-Override" http header in case your browser does not allow issuing the requested verb (like safari).

Posted by Hiram Chirino on November 16, 2009 at 08:59 AM MST #

Post a Comment:
  • HTML Syntax: Allowed