Backend for RESTful (JSON) - java

I have a question regarding RESTful client implementation.
At this moment I have developed the server using RESTeasy and EJB. Method return JSON in much case. And now we are starting backend development(WEB). And can't select a framework for this, that supports authorization, authentication...
Could you suggest a pattern, framework, approach etc..

If you looking for a Java web framework that fits your existing technology (EJB) you should take a look at JSF and WebBeans (note though that JSF does not expose RESTful URLs for its actions/controllers).
However since you also mentioned REST I guess you just want a backend framework for your services that can handle user security and auth. In this case you should take a look at spring (in particular spring-security and spring-web). Most JAX-RS implementations have good support for spring, although I should mention that spring itself has a splendid REST framework that of cause works very well with their other offerings.
If on the other hand you want a framework that can handle security in the context of a EJB application that exposes a RESTful service, then you are in a tough spot. RESTful applications are meant to keep most of the state at the client, in contrast to most EJB apps that frequently uses state-full session beans. You can integrate JAX-RS with stateless or singleton EJBs and then either use spring-security to handle the security/auth or use the <security-constraint> in the web.xml as described here

Related

Designing and implementing mobile web application

I would like to design and implement a mobile web application using JQuery mobile and Java EE technology.
The application will consists of sales persons using the mobile device to take an order when they visit the customers. So the application will contain complex business logic.
I am confused as to with what frameworks I should pick/select to design and implement the server side of the application. So my question is should I use Spring, Spring MVC and Hibernate together or some other suggestion?
But I want to stick to Java technology as I am comfortable with it.
My next question is how will the JQuery mobile and the server side integrate with each other. I mean what are the ways/methods to integrate them?
Your best bet would be to avoid Spring in this case.
Use straight Java EE, with JAX-RS, CDI/EJB and JPA.
Your jQuery code will call JAX-RS resources (which are ReSTfull web services). Those resources are injected with Service beans, which are a combination of CDI and EJB. These beans will contain your super complex business logic. If they need to retrieve or store something from/into the DB, they will use JPA for this via an injected entity manager.

Remoting from iOS to Java/Spring backend

In our application we have an Adobe Flex client that communicates to our Java/Spring backend via a facade (using AMF) that is exposed via Spring.
Any recommendations on how I could leverage this facade to make remote calls from iOS? Note that I would prefer backend frameworks that would be reusable from other clients (Android, etc).
I hear about JSON & RESTful web services. Would there be a way to rather easily get existing facade services to be exposed as RESTFul web services that uses JSON for object serialization?
Or would you recommend something different?
Any information and/or pointers will be appreciated!
Update:
So we have one option so far for this: JSON requests and responses via Spring
Anybody want to suggest any other ways?
Spring supports JSON requests and responses (see for instance, this article from the Spring In Practice blog), largely through the use of annotations.
While I don't think that it is likely that you'll be able to go through your existing AMF facade, I think that it should probably be pretty straight-forward to create a JSON-over-HTTP facade using the same underlying Spring controllers (assuming that you're using Spring MVC).
Edit: Whether the JSON-over-HTTP facade that you create is truly RESTful depends largely on your implementation.

For performance, Spring webservices or pure restful jersey even if i use MVC?

im using spring MVC and webflow to create a game server and serve some web pages to the users. Thing is, the javascript game will also make multiple ajax calls to restful services on the same server for some game logic. While the web page serving performance is not critical, the restful service calls need to be as efficient as possible (efficient as in response time).
For performance of the services, would it be better to use pure JAX-RS (jersey) web service calls without the spring ws overhead (since i understand the spring layer could affect performances negatively) or would it be the same if i used the spring webservices framework instead and maintain integration with the rest of the spring family?
thanks!
There aren't many clear benchmarks out there, but take a look here:
http://www.techempower.com/benchmarks/
It clearly shows the overhead of using Spring. Compared to Servlets that serve JSON manually Spring is "slower". Personally, I don't think that Spring cuts development time, unless you are very much familiar with it. Creating a simple servlet that will act as a REST API is very simple. Take a look at the servlet code from the benchmark:
Servlet benchmark
I don't think Spring per se will affect performance negatively. Where did you hear that?
Spring web services are "contract first" SOAP services. If you're saying that you don't want to pay the overhead of SOAP, XML, marshalling and unmarshalling, then you have a valid point. That's true whether you use Spring to implement the services or not.
REST is HTTP, so it's a natural for AJAX calls.
I believe Spring 3.0 supports REST, so it's not a "Spring or not Spring" choice:
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/new-in-3.html#d0e1188

RESTful web services framework comparison with Spring MVC REST support

In one of our projects we are using the spring mvc. The spring mvc has inherent support for REST web services. I am looking forward to some insight/suggestions on how does Springs mvc's REST support fare when compared with the other popular framework like RESTEasy, RESTlet,JAX-RS etc.
The first big differentiator is that Restlet and RESTEasy both provide implementations of JAX-RS. You can write JAX-RS code that either of those frameworks could run and not have to change anything. Spring MVC is a separate API that doesn't implement JAX-RS. It does provide most of the same functionality from what I've seen. Of course, Restlet also provides its own non-JAX-RS based API which is nice too.
I found this seemingly thorough comparison of Spring MVC and JAX-RS at InfoQ that might interest you. I would say, if you are already using Spring MVC and it meets your needs in the REST department, stick with it until you find a need to look for something else.

CDI/JSF and JAX-RS?

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.

Categories