I've started to use GWTP framework. And I've noticed that it has his own implementation of Rest comunication. I've used to use GWT with RestyGWT And Spring server.
Now I wonder- can I use GWTP Rest Dispatch with Spring server?
Or should I stick with RestyGWT (which is not a part from GWTP).
I haven't found a word about it in official documentation of GWTP. And the example given have in shared package rest service interface, which is implemented on server side. Please help.
You can definitely use Rest Dispatch with whatever backend you like. Take a look at this tutorial if you'd like more information on how to setup Rest Dispatch. This tutorial was also tested using the Python webapp2 web framework as backend.
GWTP REST Dispatch just calls REST URLs, so it doesn't care which implementation is behind the URL, as long as it's reachable by it and returns a proper response. So yes, you are totally fine to use Spring MVC, JAX-RS or anything else for your backend.
Related
I need to consume REST API. There are many REST clients for Java. Are there any areas of concerns before proceeding this?
You can use HttpClient for that. However, if you are working on a spring enabled project, I would recommend using RestTemplate.
Rest template provides an abstraction over HTTP client as a result of which you will not have to deal with serialization/deserialition, error handling, SSL configuration in every part of code where you make a REST call. You will just need to configure those with REST template configuration once and not worry about it. This makes your code clean and easily maintainable in case you wish to change the way your application talks to the back-end restful application in future.
I am a newbie to RESTful services.
In my attempt to gain practical exp. with REST in GWT I am trying to create a simple GWT web-app.
The boiler plate code generated by GWT plugin in Eclipse is a nice working example but uses RPC mechanism to interact with backend. I would like to modify this app to use RESTful services.
So, far I have figured that I can use RESTEasy server and restyGWT to get this done. Also a stackoverflow answer says that using Errai JAX-RS, building REST clients is as easy as implementing RPC, but this all seems too abstract to me.
Am I looking at the right tools for the job?
I am looking forward to any suggestion on how to proceed. Any sample code would be great.
Regrds,Mohit
I would recomend restyGWT from experience or the native GWT request factory. RestyGWT is very easy to setup and configure. You simply create an interface that mirrors your server implementation with the same annotations for #GET, #PUT, #PATH etc. The only difference is that you add a final argument to your interface implementation for a MethodCallback with the return. The only downside to this RestyGWT in my opinion is that it uses the GWT RPC for the implementation. This has caused some issues with me in the past when trying to add non white listed classes to the domain objects. You will run into issues where a class that is included is not serializable and cannot be transported to the browser client. It is my opinion to leave your rest services as they are and use requestfactory for the serialization and transport. RequestFactory does not suffer from the same white-listed class problems. It essentially uses a proxy interface on the client side that mirrors your server domain object implementation. RequestFactory can coexist with your back end rest services and use the same code as the Resource classes for retrieving the server side objects.
Here are the link to the gwt requestfactory documentation
http://www.gwtproject.org/doc/latest/DevGuideRequestFactory.html
Here is restygwt's pizza example that is what I used to get started
http://restygwt.fusesource.org/documentation/restygwt-user-guide.html
I develop a CRUD Spring, Servlet/JSP application. I will develop a desktop Swing application with same functionality. My question is that possible to communicate and resuse servlets on swing application (not applet)?
Yes, by making http requests. You can do them with multiple tools. Two of them:
new URL(..).openConnection()
apache http components
since you tagged spring, if you are using it with swing, you can use its RestTemplate. It's used to invoke restful services. You can expose your logic as restful services through the servlets (or spring-mvc), and consume them with RestTemplate
The Rest idea above is pretty good. In fact, by using Spring and it's proxies, you could use any kind of webservices (RESTFul or WSDL), and Spring would make it transparent for you.
Please check some examples in the Spring manual. Take a look at how to create proxies using service interfaces.
Best regards.
since its all via HTTP, and mechanism as suggested above can work.
Or you can even open bytestream to the server and read/write using that stream.
I have a GWT application, with a Native Java backend, and a compiled Javascript front-end (as usual).
My GWT service should also be accessible from other clients, including a java applet. Initially my idea was to double the GWT service as a SOAP service, and use a soap client from the applet to access the GWT service, but I am wondering if it might be possible to use the built-in GWT client infrastructure to call the server from Java.
The problem with this approach is serializing the request and deserialize the response so as to be compatible with the GWT service.
One solution is to use GWT SyncProxy:
http://code.google.com/p/gwt-syncproxy/
which is explained here:
(dead) http://www.gdevelop.com/blog/2010/01/testing-gwt-rpc-services/
(Wayback Archive) http://wayback.archive.org/web/20130107141210/http://www.gdevelop.com/blog/2010/01/testing-gwt-rpc-services/
You can use it directly or, since they provide the source, you take a peek to see how they serialize the request and deserialize the response.
Another approach is to use Restlet to provide the services and then convert your GWT client to make REST calls. The Restlet people provide a GWT library to facilitate this.
http://wiki.restlet.org/docs_2.0/13-restlet/275-restlet/144-restlet.html
They provide an example of calling the REST service via Restlet from different clients, including GWT client, Java SE, and Android:
http://wiki.restlet.org/docs_2.0/13-restlet/21-restlet/318-restlet/303-restlet.html
Edit:
I only know RESTlet from evaluating it last year for my GWT project. I'm no expert and I didn't end up using it, but this is no reflection, good or bad, on RESTlet.
OP asks:
What would be the advantage of using the Restlet framework over JAX-RS ?
Essentially, JAX-RS is an just API (like JDBC) - you still need to pick an implementation or use the reference implementation Jersey. RESTLet has an extension for supporting JAX-RS API.
http://www.restlet.org/about/faq#07
7. What is the link between Restlet and JAX-RS (JSR-311)?
...
To summarize, both APIs have very different designs but are potentially complementary. The good news is that Jérôme Louvel (Restlet's creator) is an active member of the JSR-311 Expert Group and that an implementation of the JAX-RS API was made on top of the Restlet API. This "JAX-RS extension for Restlet" was developed by Stephan Koops in the context of his Master thesis and is one of the most advanced implementations available. For more documentation on this extension, please refer to this page.
OP asks:
Is it possible to use Tomcat / web.xml infrastructure instead of org.reslet.server
http://wiki.restlet.org/docs_2.0/13-restlet/275-restlet/312-restlet.html
This edition is aimed for development and deployment of Restlet applications inside Java EE application server, or more precisely inside Servlet containers such as Apache Tomcat.
I would like to use RESTful services in a CDI/JSF2 application. I am not very familiar with JAX-RS however I have read that its lifecycle does not play well with CDI/JSF2. Is it possible to incorporate JAX-RS with CDI/JSF2 in a JEE6 stack? If not are there alternatives?
thanks
You can use JAX-RS just fine along side a JSF application, however, they don't play well together. For instance, you can't use JAX-RS to have "http://localhost:8080/story/92/" return a JSF page with a Story entity with ID 92.
You can, however, use PrettyFaces to do something very similar to this.
JAX-RS makes sense for non-JSF resources. "http://localhost:8080/story.xml" makes perfect sense for JAX-RS.
You can call your rest services from your JSF templates. For example you can run your rest services from http://localhost:8080/services/ while your JSF page is returned on http://localhost:8080/index.xhtml. You can then write some custom javascript to call your rest services from your JSF page. This is actually the general practice with REST services so they can be consumed by many different UIs. JSF may not be the best for consuming REST services, but it is possible.