TS-
TS-

Reputation: 4421

Back-end architecture: RESTful web service

I am working on creating a back-end infrastructure for a website. Obviously, the back-end infrastructure needs to be agnostic to the front end, it can be a website, a mobile site, a mobile app, another services, anything.

I am planning to write it up as RESTful web services, and I would also like to have dependency injection, transaction management, and persistence framework. The limitation here is that I will be working with Apache Tomcat web server, thus I can't use EJB (I can't use JBoss or other app server)

My initial thought is to use Spring framework - solid, well supported and easily covered all I need. My slight hesitation is because I simply want REST endpoints without View, whereas if I use Spring, it would be going through the Spring MVC framework. Is it normal to use Spring MVC without the View part?

Does my choice make sense or is there other frameworks that I should consider? I looked into JAX-RS as another alternative for REST framework, but then I don't get dependency injection / transaction management / persistence framework, I would end up having to use other frameworks to get those.

I also noticed there's a project TomcatEE that sounds like could solve my problem too. .

Your thoughts are appreciated. Thanks in advance!

Upvotes: 0

Views: 4162

Answers (4)

Im am using Spring Rest Data, in the same way : The server does only respond with JSON and does not care what a client may do with the data. I was also wondering about using MVC but its ok, no problem !

Lazy Loading : From my point of view there are only two ways for that :

  1. load everything eager from the database and send it to the client
  2. serialize references as links, as its done by Spring Rest Data. Than the client can/must decide which to load.

There is a live demo application using Spring REST Data at demo.appdriver.com You can access the API at http://appdriver.prefabware.cloudbees.net/api/

Upvotes: 0

jabal
jabal

Reputation: 12367

Tomcat does not mean no EJB. Tomcat 7 brings you Jave EE 6 then you can use EJB and CDI technologies. I am currently working on a software that uses the following technology stack:

  • JAX-RS RESTful front-end, that delegates service calls to the
  • service EJB-s, that are injected into the RESTful classes using @Inject CDI annotation

Not using Spring has the following advantages:

  • one less 3pp dependency, one less technology required. Not obviously an advantage.
  • sticking with the standard Java EE technologies makes your app portable (more or less)

On the contrary I think Spring is so widespread and well documented, that it is a charm to work with it. Portability is also fine with Spring, I had more problem with different CDI bugs and misimplementations (?) among different EE vendors than with Spring. I think Spring will not force you to take the MVC way. You can use it partially or mix things as you wish. If you know what is under the hood then you can use Spring in a very flexible way.

Remark: Think about authentication a little bit. RESTful means BASIC authentication but webapps usually require a fancy login page and the BASIC auth popup is hard to suppress. We used SSO to solve this problem, one webapp with FORM auth and fancy login screen and BASIC auth in the RESTful services for the other clients. SSO caused logging in in the first app was valid for the RESTful calls too.

Upvotes: 1

Evgeniy Fitsner
Evgeniy Fitsner

Reputation: 946

Yep, Spring 3 MVC is excellent framework, I'm creating applications on it which also supports RESTful web services. The main benefit - your return value from controller class automatically converting to the JSON object. To use or not View - it's up to you, all will be working fine without views

Upvotes: 1

Gertjan Assies
Gertjan Assies

Reputation: 1900

I'd use Jersey in combination with JAXB to bind to your domain classes a good tutorial can be found here:

http://www.vogella.com/articles/REST/article.html

be aware when using hibernate/jpa as JAXB can't handle the lazy loaded models (you need to write adapter classes then)

Upvotes: 0

Related Questions