MVC or Rest or Both - java

I in the process of designing the server side of a web-based user interface that will be very JavaScript intensive.
I originally thought of going with an MVC solution, but now I am thinking I want to use a REST-based solution such as Jersey or Restlets.
Is this often an one or the other type decision or can they be a combined solution?
Thanks,
Mike

MVC is about how the inner side of your app works.
REST is about how your app "talks" with other apps.
You can combine them.
A lot of modern frameworks actually are MVC based and make implementing REST web services easy: Ruby on Rails, Java Spring Framework with SpringMVC , Django, Backbone.js

One of the best Java frameworks I've seen for building MVC webapps with the ability to support REST is SpringMVC. This blog post outlines the REST capabilities in SpringMVC since version 3.0. I've developed REST services using SpringMVC and Jersey, and they are fairly comparable.

They are patterns / solutions to solve different problems.
REST sanitises & simplifies addressing access to features of a web application, for users, client software, etc.
MVC provides a means to organise your application code, making it easier to maintain.

MVC is an architectural design pattern for the layers of your application.
The folder structure:
Models/YourClassModel.php
Views/Home/HomeView.php
Controllers/Controller.php
index.php
The application style REST is the Representational State Transfer of the application.

Related

Pros and Cons of JAX-RS, Playframework scala (REST backend), Web Api

First am not sure if this question fits here well. However couldn't think of a better place to get help. I've been tasked to list the Pros and Cons of each of these {JAX-RS, Playframework scala, MS Web Api}. I've done some research but couldn't conclude as I've not used all three to great extent. Have used playframework to create simple REST app. Have read the Web Api tutorials but have not implemented anything. Did research on JAX-RS but haven't implemented anything either. Also most of our developers are familiar with C# and introductory Java. I am more inclined towards playframework due to Scala,Akka,no server restart and scalability etc but not clear about the cons. One thing am sure is JAX-RS is standard Java EE and Web Api is standard MS stuff. Below are some of the app requirements:
Purely REST backend.
Proper authentication and authorization.
Online secure payment {Paypal etc}
Single front-end for both mobile and desktop
{angular/backbone/knockout..}
Allow users to subscribe as companies or part of companies.
Be able to connect to different databases without App restart.
Code maintenance and readability. Other members should be able to pickup without hassle.
Scalability
This is a partial answer because I worked only with playframwork 2.0 and JAX-RS.
Playframework is a MVC framework, you can use it to create some REST services but it's not focused on this kind of applications, so at least in version 2.0 it wasn't easy to add complex behavior like interceptors, etc. and you should manage authentication by yourself, I don't know if this has been improved in most recent versions of play framework.
JAX-RS is a specification to create REST services, there are several implementations like
Jersey, RESTeasy, Restlet between others. So JAX-RS implementations are built specifically to provide REST services in java. Most implementations have support to several authentications mechanism like OAuth, etc.
In my experience, JAX-RS is better to provide RESTful web services, and the code generated is in general more maintainable than the code generated in playframework, also playframework has a lot of things that maybe you don't need to use, but it will be loaded in memory when you start the server anyway. Akka it's a cool technology, but you can use it if you want it in any JAX-RS implementation.
If you want to build REST services using Scala, you could try Scalatra http://www.scalatra.org/
If you prefer java, take a look at http://dropwizard.io/, it's an embedded server that has Jersey (An implementation of JAX-RS) and a lot of cool things to provide RESTful web services, like metrics, etc, also it's easy to learn. If your team doesn't have an advanced java knowledge, this is a good option.
Playframework is great if you want an easy to learn MVC, specially for non java programmers but definitively it's not the right tool to build RESTful webservices based applications in my experience.

Can Spring MVC be used to implement MVC pattern in Swing applications?

I was wondering if Spring MVC can be used to implement MVC pattern in Java Swing Applications. I've done some study and found Spring MVC to be used for web development.
Is there any way Spring MVC to be used with Swing Applications?
Not really. As you say, Spring MVC (or Spring Web MVC) is primary targeted for web server development and thus have little to do with client side or standalone GUI applications.
That said, nothing prevents you from using ordinary Spring technologies for dependency injection, as a backend in your model, etc. Spring provides abstractions for persistence, remote network communication, transactions, security and so on that might come in handy in many projects.
Additionally, there is the Spring Rich Client Project that was released some years ago, but I do not know its current status.
No, but you may want to take a look at Griffon, which offers a Swing MVC framework base on Spring libraries and the Groovy language, which should be really easy for any Java programmer to pick up.
I've used it quite successfully to build rather large desktop applications for corporate clients.

What is the best approach to use Vaadin for web application development?

I am just about to create a new Web application (kind of CRM system) with lot of tables, statistics, graphs, etc... and I've decided to do the web interface with Vaadin. Most of the data will come from external Web Services (almost 100 %). My Question is, what would be the best approach to go with? Just to implement pure Vaadin application and some classes to handle the SOAP calls and fill the Vaadin components with the data, or to go with some additional framework e.g. Spring, Struts, etc... and integrate vaading for the UI? Any additional hints would be great.
Thanks
Filip
Using spring is good for dependency injection, security (depending on the sections you are using) but struts and vaadin are web frameworks so mixing them does no sense. You either use struts or vaadin or spring-mvc or any other web framework.
Your question is not really clear but I would say you can use spring rest api to pull data from other web services if they are restful services.

Is it possible to use JAX-RS as a web framework?

I've been looking into JAX-RS lately because I really like the Java platform and a RESTful style of web development. I've read a lot about using JAX-RS for creating RESTful Web Services, but is it possible to use JAX-RS to create RESTful web sites? I guess more specifically, is it possible to use JAX-RS as a controller (to retrieve required data from the server) and then forward control to a view engine to render the appropriate HTML?
I've been googling around but haven't found any resources that show you how to do this.
Thanks for any insight/help.
I think you are having difficulty with your google searches because not many people are doing this. JAX-RS was designed for web services, so developers don't think of using it as a controller for web applications. However, there is no reason it wouldn't work.
Check out this blog post: JAX-RS as the one Java web framework to rule them all?
I think it's exactly the kind of thing you are looking for.
If you truly want to rely just only JAX-RS for your web framework, Jersey might be your best bet. Keep in mind the features you get from it are going to be bare minimum and you are obviously not going to get all the bells and whistles like what's provided by JSF, Wicket, etc.
If you know your web application is going to rely on Spring, perhaps you should consider using Spring MVC 3.0. It provides restful web services-alike and it gives you better features so that you don't need to implement most of them yourself. Granted, Spring MVC 3.0 is not an implementation of JAX-RS and based on what the Spring developer said, it seems like they will never make Spring MVC as an implementation of JAX-RS since they are already quite a few stable implementations out there. However, the syntax is pretty similar in my opinion, or at least I was able to understand them rather quickly even though I have been using Jersey for quite awhile.
dbyrne is right that almost no one is doing this. It's more conventional to use JAX-RS to dump information to JSON or XML. Then you fancy up the web browser with an RIA framework (e.g. Ext JS), which handles manipulating the DOM and injecting data as its fetched in JSON/XML form. This approach is powerful. You can write multiple, possibly non-browser clients for the service, all parsing the same JSON/XML. You can write "one-page" webapps, where all information exchange happens through AJAX after the initial pageload. I urge you to investigate and consider its strengths and weaknesses in the context of your particular problem.
Returning to your question: the answer is "sort of". This functionality is not directly provided by the JAX-RS spec (as of 1.1). However, it is in the JAX-RS reference implementation, Jersey, through the Viewable response object. See this blog post if you want to investigate further: http://blogs.oracle.com/sandoz/entry/mvcj. I want to point out that I have no experience with this side of Jersey. It has been pleasant to write XML/JSON-returning web services with Jersey, but I can't speak to this server-side HTML templating business.
Edit: dbyrne's edited his answer to include a blog post which points to the one mentioned above. I think we've both converged on approximately the same answer.

Lightweight REST library for Java

I'm looking for a light version of REST for a Java web application I'm developing.
I've looked at RESTlet (www.restlet.org) and the REST plugin for Struts 2, but I haven't made up my mind. I'm leaning towards RESTlet, as it seems to be lighter.
Has anyone implemented a RESTful layer without any of the the frameworks or with the frameworks?
Any performance issues that you've seen because of the new web layer?
Did the introduction of REST added unmanageable or unreasonable complexity to your project? (Some complexity is understandable, but what I mean is just plain overkilling your design just to add REST)
I'm a huge fan of JAX-RS - I think they've done a great job with that specification. I use it on a number of projects and its been a joy to work with.
JAX-RS lets you create REST resources using POJOs with simple annotations dealing with the URI mappings, HTTP methods and content negotiation all integrated nicely with dependency injection. There's no complex APIs to learn; just the core REST concepts (URIs, headers/response codes and content negotiation) are required. FWIW JAX-RS is quite Rails-ish from the controller point of view
There are a number of JAX-RS implementations out there - see this thread for a discussion.
My personal recommendation is to use Jersey as its got the biggest, most active community behind it, has the best features at the time of writing (WADL support, implicit views, spring integration, nice REST client API); though if you are using JBoss/SEAM you might find RESTeasy integrates a little better.
I'm a big fan of Restlet, but I usually use it to implement apps whose primary role is to be a RESTful web service. It sounds like you're looking to add a RESTful API to an existing application. If that's the case, JAX-RS's (or Enunciate's) annotation-based approach might be a better fit for your project.
As for Restlet, I can tell you that I've been very impressed with the developers and the community; they're very active, engaged, responsive, and committed to a stable, efficient, reliable, and effective framework. My single favorite aspect of the framework is that it is a ground-up implementation of the REST paradigm; therefore there is no impedance-mismatch between a Restlet app's external API and internal implementation. I also really like how flexible it is - it can run inside a Java application container/server such as JBoss, Tomcat, Jetty, etc, or standalone, with an embedded HTTP server library.
Well, I've used Enunciate quite a bit. It uses simple annotations to provide either REST and/or SOAP endpoints.
http://enunciate.codehaus.org
Plus, Ryan Heaton has always provided top-notch support for things, too.
You know there is a new JCP API for Accessing RESTful Services, also:
JAX-RS JCP311
https://jsr311.dev.java.net/
The open source version is called Project Jersey
I am working on a REST API for gliffy.com and we ended up rolling our own. We didn't want to have to bring in Struts 2, Spring, or any other framework. I looked at RESTLet and found it incredibly confusing and over complicated.
Apache has an implementation of the JAX-RS spec, but it is not finalized and also has some oddities to it. We're tentatively planning to open source our solution, but that's not for a few months.
Rolling your own is easy, though. The Servlet Specification gives you everything you need, and you can easily connect to a database via Hibernate (see http://www.naildrivin5.com/daveblog5000/?p=39 for how to set up JPA without using EJB3).
I found restlet to be a really elegant architecture. I'm working in the .net world so it was not an option for me, but I was able to build my own framework following the same basic principles of restlet.
I have found the conversion of our WCF contract-based SOA application to REST based one has significantly simplified the application,

Categories

Resources