Gwt + Guice tutorial - gwt

I'm a Gwt beginner. My remote service implementation now uses a DAO.
For the sake of example, I'm creating it myself:
StocksDAO myDao = new StocksDAO();
Now I was thinking to add Spring IOC for injecting it.
Then I came across this GUICE framework... it can be interesting but...
How to quick start? Is there a simple tutorial over the web suitable to my simplicity example?

GWT remote service is implemented as a Servlet. To use Guice with Servlets, look at the docs: http://code.google.com/p/google-guice/wiki/Servlets
Also, this has been discussed earlier: GWT Guice/Gin on the server side problem

Have a look at the sample application which will demonstrate use of Guice with GWT specifically with Request Factory.
http://code.google.com/p/guice-gwt/

Related

Guice with JAX-RS

I am using Guice as my dependency injection framework. I'd like something that I can add that will make creating REST services easier.
I've had a look at guice-servlet and it works well for directing paths to HTTP servlets, but that's all it appears to do, I was expecting a JAX-RS like annotation syntax to work but it doesn't.
Having not actually used JAX-RS I've googled around and it appears that Jersey is the reference implementation for this but it looks like it uses its own dependency injection framework and doesn't work well with Guice. In addition it has 5+MB worth of dependencies which seems alot for what I am after.
Is Guice designed in such a way that it doesn't lend itself to JAX-RS, if so what else should I be doing?
I think that maybe the guice-servlet module has misguided you. Guice is a DI framework. Period. The real goal of the guice-servlet module is not providing the servlet's and filter's shortcut declaration but giving support for the special scopes request and session. Those nice shorcut declarations are syntatic sugar.
Chosing a JAX-RS implementation in Java is a bit out of the question. You have several options (Jersey, Resteasy, Spring...). If you are going full JavaEE then you don't have to choose. You just use the annotations (and the DI) out of the box.
If you are not using a JavaEE server (just a web server like Tomcat or any other fancy thing like an Android app) then you must choose your implementation. If you are using DI also (which I recommend) then there is one more decision to make.
So you are not using JavaEE and you want to implement some REST API using JAX-RS and dependency injection. You do some research and end up choosing Jersey and Guice. Good choice, I've chosen those in my last projects too. Yes, the dependency graph of Jersey is a bit bloated. I know, it could be way better.
Now your problem is how to make it work together because Jersey uses it's own DI framework (HK2) which is a bad thing.
You have a lot of references on SO about Jersey-Guice integration. Your best bet is the Guice HK2 bridge.
What? You want a direct reference on SO? No problem, here is a good one. Don't forget to upvote the answer. ;-)
Jersey and Google Guice integration

Is it possible to have a class support both a JAX-RS service and JAX-WS service?

I've created a RESTful web service using jersey and JAX-RS annotations. It's also documented using enunciate and looks great. However, SOAP support has been requested as an option. I noticed in this outdated enunciate example JAX-WS and JAX-RS annotations in the same class. Is this possible? I've tried it myself and enunciate generates documentation correctly, but the services don't actually work.
I'd prefer to have the exact same class support both interfaces rather than two separate classes (one soap one rest) pointing to the business logic class. This would prevent possibly having code in two places.
Here's the example on outdated software versions:
http://docs.codehaus.org/display/ENUNCIATE/A+Rich+Web+service+API+for+Spring
I'm using
Jersey 1.8
Spring 3.0.5
Weblogic 11g
Thanks!
/Chip
I'm not sure what might not be working, but a lot of the Enunciate example modules use both the SOAP and REST annotations on the same class.
Here's one for Jersey/JAX-WS.
Here's one for JBoss WS/RestEasy.
Here's one for CXF.
We ended up making a separate service for SOAP than the REST service. We also found it best to have interfaces for each that enunciate could generate from. This way we could control what documentation it generated. It also started functioning smoother. Still having a problem with the namespaces though as they're all default and ns0 is generated but enunciate links are to ns2/3/4/5/etc. So many links are broken.

GWT + EJB working?

I want to use EJB in my GWT Application, but I coulnd't find a current Tutorial. I am new to the topic of EJB's and with GWt I have worked the last months. At the moment I have got some RPC Calls in my GWT Application and this works. Is it's possible in GWT to use EJB and if yes would it be difficult to install?
GWT is a client-side framework. It can connect with the server-side i.e. using RPC calls, REST web services or SOAP web services. An EJB on the other hand is a server-side technology which can define several entry-points for its clients.
I would consider creating a proper business logic and create a boundary for it - in form of i.e. RESTful Web Services. This functionality can be tested in well-controlled environment or even in real-life application server.
If this is done, than you just need to create a regular GWT application which 'talks' with EJBs through REST-WS.
Sorry, but I'm not aware of any tutorials about GWT + EJB. There is an example of EJB RESTful implementation at Adam Bien's weblog, but if you're really interested in EJB technology and don't know a bit about it, I would recommend to take some decent book first, like Enterprise Java Beans 3.1.

Authentication with AOP, Guice and the new RequestFactories

I would like to use the new RequestFactories and the new approach to do AOP with Guice to do the Authentication.
I would like to have for example a RequestFactory Request method in a JPA Entity for example
findCustomer(int id) which i can anotate for example with #NeedsAuthorization(rights=Rigths.ADMIN)
This is just an example, but i am not so experienced in this field and it would be nice if there is an nice tutorial which shows such a possibility. Maybe HttpSession based.
Want to give myself an answer. After longer research i find a way to use Guice with RequestFactory in this software architecture example: https://github.com/mgenov/injecting-request-factory
In this project i saw an example of Authorizaton wit AOP: http://snippets.dzone.com/posts/show/11587
In the dynatableRF example of GWT i saw how to do the Authorization on Request Factory level (with AuthFilter)

GWT Acegi alternative

I'm starting new project. The client interface is based on GWT (and GXT) I have no say it's predetermined. However I can pick and choose as far as server side so I can have some fun and hopefully learn something new in the process. Some requirements are :
Exchange with server will be through use of JSON, most if not all of UI will be generated by GWT (JS) on the client, so the client/serve exchange will be limited to data exchange as much as possible
No Hibernate (it's not really supported on the proprietary db I will be connecting to). In the past projects people would use JDBC or iBATIS
Some sort of IoC (I'm thinking Guice just to stick with Google)
Some sort of Security framework based on LDAP. In the past we would use Spring security (Acegi) but it wasn't ideal and we had to customize it a lot
So basically should I stick with tried-and-true Spring/Acegi or try something based on Guice? And what that "something" would be and how mature is it?
Have a look at Apache Shiro. It seems to be gaining ground, with no reference to Spring.
If you'd like to do IOC on client and server, go with Guice. You can use Guice on the server, and its brother GIN on the client.
Since nether of the above answers gave me any practical ideas (or almost any) here's formula I ended up with:
Maven + GXT + GWT and Guice + iBaGuice