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)
Related
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
Why would one like to integrate JAX-RS(Jersey) using Rest API to Struts2? Struts2 is itself a mvc framework, so why would anyone want to integrate these both? If combined, how will the resulting framework be(I wanted to know if REST API just control the controller part of MVC).
There is a RESTful plugin called struts2-rest-plugin that has been included with the framework since version 2.1.1. A fair amount of information on the plugin can be found here.
Essentially, the plugin uses a custom action mapper that examines the request and based upon the HTTP Method used in conjunction with the URI, it dispatches the request to one of several different method names (e.g. GET /movies dispatched to index() method of action).
Just because Struts2 is an action-based framework does not mean a RESTful solution cannot be included as an alternative for developers. Spring MVC offers similar solutions themselves and it is also an action-based framework.
If you consider your JSON response as your view, you'll see that the fact that Struts2 is based on MVC design makes logical sense. Your model is simply the data structure you are returning to the client and your controller is the action.
Consider reading the link above on the plugin and you'll get a better picture of how the two can be integrated. If you want to return JSON but don't necessarily want to offer RESTful URLs in your Struts2 application, you can also consider the JSON plugin, found here.
I am not sure about Struts2, but in the past Struts1 did not have a "Rest" adapter built in. Jersey provides the cool #annotations that will easily serialize your datamodel and will push you in a "Restful" direction. Jersey does not provide an MVC framework as much as it provides convenience methods to work in a Restful/resource based way.
I recently upgraded my project from GWT RPC to GWT RequestFactory, my UI uses alot DTO classes that was pure java classes, but now I upgrade them to entityproxy.
Now gwt designer is complaining that the entity class(JPA Entity) present in locator is illegal.I also use Gucie in locator to inject service implementation.
How could I fix this.
thx.
Like LPD said, provide more details. Some details are important to understand why it doesn't work.
"Java doesn't work, please help" -> you know the feeling.
For a given entity, you could post the entity class itself, the related proxy, parts of the service methods and annotations, as well as your relevant parts of your locator and request context class.
Go through this check list:
Check your annotations (ProxyFor, etc.)
Check your RequestContext and its annotations
Check your services definition.
Ensure that your service, locator definitions are in sync with what is specified in the RequestContext.
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/
In short, how do you transfer semantic data between client and server with GWT and which frameworks do you use? Read on for more details that I've thought about.
For example, using GWT 2.2.0 features like the RequestFactory will bring the constraint to have java beans transferred while the semantic resources are represented as triples and a resource can have a varying set of properties. So the RequestFactory itself cannot be shaped to transfer semantic-driven data easily.
A way to do that would be to use RequestFactory with beans that represent triples. Such bean would have 3 properties: subject, predicate, object. These beans will be transferred to client which will know to query, change their properties and then send them to server. This approach will however need a custom implementation(there are no GWT-based frameworks to represent semantic data on client-side, from what I've searched so far) and that could prove buggy or unoptimized. I've seen this approach in this project: http://code.google.com/p/gwt-odb-ui/ - it used GWT-RPC and implements some classes that represent semantic resources. However, I think it's in an incipient stage so I'm reluctant to copy their model.
Also, I've found that Restlets is a framework that supports the semantic web approach to applications. However, there is no documentation or an example on how to use Restlets with Semantic Web and perhaps with GWT. Also, Restlets is also supporting GWT. Does anyone know if this is a viable solution or not?
Thank you!
Restlet should work quite well for you. It has a GWT edition able to automatically serialize your triple beans. In addition, it also comes with an org.restlet.ext.rdf extension, including a Link class similar to your triple bean idea.
For further documentation, I would suggest the "Restlet in Action" book which covers GWT and the semantic web from a Restlet and REST point of view.