Advantage of Spring Rest Web Services over Servlet - spring

What are the advantages of using Spring Rest Web Services over Core Servlet ?
As we know Spring Rest Web Services also use Servlet internally.

REST is a special kind of web service. Whether this is the right thing for your application varies. If it is you should use a framework/library that is designed for REST to make coding simpler. You might also want to have a look at JAX-RS.
If you need a non-REST web service Servlet may be an option, but there are other options, too.

REST is not a type of Web Service - it is an Architecture and specification - JAX-RS. Spring has its own REST implementation libraries primarily based on its MVC controller. I would recommend you not to go for Spring Rest Web Services until you have any Spring specific requirement (Though I cant think of any such requirement which cant be solved by other light wait JAX-RS implementations). Jersey is the most light weight JAX-RS reference implementation by Sun/Oracle which, has support for Spring as well which, can be plugged in on requirement basis.

Related

Plain Servlet vs Spring MVC

I have to create a web application, I need to use my back-end code for mobile apps also.
I know Servlet, I thought of doing this application with "REST API" + HIBERNATE for server side and Javascript(Angular JS ) in UI.
Some of my colleagues suggest to do this with Spring. I don't know anything about Spring. While reading about Spring I came to know that back-end logic and UI code can be in same place. It seems it is tightly coupled with back-end and front-end.
Some times back Jquery is more preferable JS framework but now everyone suggests Angular JS. This will be changed after some times. But logic I am going to write in back-end will be the same.
How can I choose the correct one?
I suggest to use:
Spring web MVC for backend https://spring.io/guides/gs/serving-web-content/, maybe with Spring Boot, and Hibernate for DAO layer. Here you can find a helpful example (without Spring Boot): http://websystique.com/springmvc/spring-mvc-4-and-spring-security-4-integration-example/
and for frontend certainly Angular 2, with TypeScript, instead of Angular js, and here reach the REST service exposed by backend.
These days it is easy to build a REST based back end with no libraries at all if you deploy to a Java EE 6/7 server such as WildFly, TomEE or Payara (amongst others).
You get JAX-RS and JSON-P (for rest), JPA for persistence, web sockets, asynchronous processing, transaction management and the rest of the Java EE stack for free.
Try a google search for Java EE thin war - there's lots of examples about

Can you use (any) Spring's functionality outside of Spring (Boot)?

I have just built a RESTful web service with Spring Boot.
I now want to utilise the RESTful web service and start making calls to it by building a java console application (eventually adding GUI and security).
I was wondering if I can use any of the Spring functionality outside of the Spring (Boot) environment and use it in my java console application? For example, can I use Spring's RestTemplate in my non-Spring java application to make the REST api calls? I am new to Spring and I want to stick as close to Spring as possible. I think you can't, but I just want to make sure.
If not possible, I know you can create non-web application with Spring. Is it possible to integrate a GUI? Might not be best practice, just exploring what is possible and conventional.
Spring Boot is not coupled, in any way, to an application type. You can run command-line only apps, batch apps, web apps or any other kind of apps with it. You can even benefit from Spring Boot's auto-configuration.
In the case of the RestTemplate you may want to import spring-web directly rather than spring-boot-starter-web. Or you could add the starter and exclude the embedded container (spring-boot-starter-tomcat). Spring Boot will auto-adapt and not start an embedded web server in that case.

Spring REST API for web- and mobile-clients

This is my first question on StackOverflow and I hope someone can help me. :-)
I am planning to build a web-application (backend) with spring roo. For the backend I will use Spring and Hibernate/JPA. In the future I will implement a web client (JSF/Primefaces), a mobile client (Android) and a Windows App.
With spring roo it is easy to create a layered architecture with domain classes, repositories and services. This part is fun.
But now I am thinking about remoting and how to connect all the clients (web, mobile, windows) with my backend.
1.) What do you prefer for the remoting between client and backend? SOAP-Web Services or a REST-API (e.g. with JSON).
2.) If REST-API: How should the API look like for authentication/login functionality? REST is resource-oriented but how do you implement authentication with REST API?
At the moment I think a REST-API is a good idea. Because I am using spring it is easy to create a Spring MVC controller with REST support. But is this the correct way to implement a REST API for all the three devices? The web client e.g. should be implemented with JSF and Primefaces and I donĀ“t use spring MVC for the web layer.
3.)Can I nevertheless use Spring MVC controllers to build the REST API (together with JSF in the web layer)? Or is there a better way?
1.) What do you prefer for the remoting between client and backend? SOAP-Web Services or a REST-API (e.g. with JSON).
I don't have too much experience with SOAP-WS, but I have a ton of experience with REST-APIs using JSON. There are many implementations for mobile, web and server side clients that are fairly simple to implement.
2.) If REST-API: How should the API look like for authentication/login functionality? REST is resource oriented but how to implement authentication with REST API?
If you are already using spring, I recommend securing your API with Spring Security. You can use spring security even if you don't end up going with Spring MVC for your API implementation. There are many ways to secure a rest API with spring security, but I the simplest is to send the basic auth header with every request to a secure URI
3.)Can I nevertheless use Spring MVC controllers to build the REST API (together with JSF in the web layer)? Or is there a better way?
Spring MVC Controllers will work fine, but I would recommend going with RestEasy or Jersey. I find them to be more flexable.
I agree with #mad_fox. Additionally, i want to add another option regarding your question#2. If you dont want to use Spring security, you can write your own token based authentication mechanism using spring and basic java interceptors.
You can store the token in your browser local storage.

why we use jersey with spring? What are the benefits?

I want to know that why we use jersey with spring and what are the benefits of using it.
I have searched on google but not getting proper answer so i am asking this question here.Sorry because i know my question is old but i am very confused now.
Please suggest me the example of jersey with spring and hibernate.
Thanx in advance.
I use Jersey2 with Spring in one of my projects and in the other Spring MVC4. The advantage of Jersey is its simplicity. If you are creating only RESTful Web services - use Jersey, if you have to generate also some web pages for users, consider to use Spring MVC.
Additionally, I develop my applications on Google Cloud, so the warm up time is very important (if there is a traffic spike, many instances have to wake up in the background to be ready for incoming requests) - according to my tests Jersey is a bit faster than MVC.
Here you have an example of complete configuration:
Integrating Jersey 2 and Spring with Java Based Configuration

Invoking soap services and rest apis using Dropwizard framework

I have a requirement to expose my business logic in RESTFul API. One of my colleague mentioned Dropwizard seems to be quite good. However i would like to know if it suits my requirements. My requirement is to invoke multiple SOAP services and REST APIs to build the application logic.
Does dropwizard have anything native support for consuming soap services / rest apis ?
or
i should integrate with other frameworks like Spring, CXF ? If i use CXF or Spring, i am aware that i will need to generate the JAXB annotated classes, Service endpoint interfaces etc, provide cxf beans and inject the dependencies into my code and implement business logic.
Pls let me know if the requirements can be met with just dropwizard without any other frameworks like spring, cxf etc ?
Thanks a lot for your help.
Yes, you can invoke external REST Services using this library
dropwizard-client
Demo example is given in this manual.

Resources